Skip to content

Commit

Permalink
fix: the command arctl gen_test_dataset recursively reads files
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy committed Jan 23, 2024
1 parent 83ebf9e commit 8d5f450
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions pkg/arctl/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import (
"context"
"encoding/csv"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"

Check failure on line 24 in pkg/arctl/eval.go

View workflow job for this annotation

GitHub Actions / Lint Go code

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kubeagi/arcadia) -s blank -s dot --custom-order (gci)
"io"
"io/fs"
v1 "k8s.io/api/core/v1"

Check failure on line 27 in pkg/arctl/eval.go

View workflow job for this annotation

GitHub Actions / Lint Go code

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kubeagi/arcadia) -s blank -s dot --custom-order (gci)
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
"log"
"os"
"path/filepath"
"strings"

Check failure on line 35 in pkg/arctl/eval.go

View workflow job for this annotation

GitHub Actions / Lint Go code

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kubeagi/arcadia) -s blank -s dot --custom-order (gci)
basev1alpha1 "github.com/kubeagi/arcadia/api/base/v1alpha1"
evalv1alpha1 "github.com/kubeagi/arcadia/api/evaluation/v1alpha1"
Expand Down Expand Up @@ -142,19 +142,20 @@ func EvalGenTestDataset(home *string, namespace *string, appName *string) *cobra
}

// read files from input directory
files, err := os.ReadDir(inputDir)
if err != nil {
log.Fatal(err)
}
for _, file := range files {
if file.IsDir() || filepath.Ext(file.Name()) != ".csv" || strings.HasPrefix(file.Name(), "ragas-") {
continue
filepath.WalkDir(inputDir, func(path string, d fs.DirEntry, err error) error {

Check failure on line 145 in pkg/arctl/eval.go

View workflow job for this annotation

GitHub Actions / Lint Go code

Error return value of `filepath.WalkDir` is not checked (errcheck)
if err != nil {
log.Fatal(err)
return err
}
if d.IsDir() || filepath.Ext(d.Name()) != ".csv" || strings.HasPrefix(d.Name(), "ragas-") {
return nil
}
var output evaluation.Output
switch outputMethod {
case "csv":
outputCSVFile, err := os.Create(filepath.Join(inputDir, fmt.Sprintf("ragas-%s", file.Name())))
outputCSVFile, err := os.Create(strings.Replace(path, d.Name(), fmt.Sprintf("ragas-%s", d.Name()), 1))
if err != nil {
log.Fatal(err)
return err
}
defer outputCSVFile.Close()
Expand All @@ -168,15 +169,17 @@ func EvalGenTestDataset(home *string, namespace *string, appName *string) *cobra
}
// read file from dataset
err = GenDatasetOnSingleFile(ctx, kubeClient, app,
filepath.Join(inputDir, file.Name()),
path,
evaluation.WithQuestionColumn(questionColumn),
evaluation.WithGroundTruthsColumn(groundTruthsColumn),
evaluation.WithOutput(output),
)
if err != nil {
log.Fatal(err)
return err
}
}
return nil
})

return nil
},
Expand Down

0 comments on commit 8d5f450

Please sign in to comment.