Merge pull request #963 from frin1/feature/limit_number_of_optimizer_results

Feature: limit how many metrics is shown by optimizer
This commit is contained in:
Yo-An Lin 2022-09-24 01:53:58 +08:00 committed by GitHub
commit 0ef565ec81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ func init() {
optimizeCmd.Flags().String("output", "output", "backtest report output directory") optimizeCmd.Flags().String("output", "output", "backtest report output directory")
optimizeCmd.Flags().Bool("json", false, "print optimizer metrics in json format") optimizeCmd.Flags().Bool("json", false, "print optimizer metrics in json format")
optimizeCmd.Flags().Bool("tsv", false, "print optimizer metrics in csv format") optimizeCmd.Flags().Bool("tsv", false, "print optimizer metrics in csv format")
optimizeCmd.Flags().Int("limit", 50, "limit how many results to print pr metric")
RootCmd.AddCommand(optimizeCmd) RootCmd.AddCommand(optimizeCmd)
} }
@ -54,6 +55,11 @@ var optimizeCmd = &cobra.Command{
return err return err
} }
resultLimit, err := cmd.Flags().GetInt("limit")
if err != nil {
return err
}
yamlBody, err := ioutil.ReadFile(configFile) yamlBody, err := ioutil.ReadFile(configFile)
if err != nil { if err != nil {
return err return err
@ -124,6 +130,10 @@ var optimizeCmd = &cobra.Command{
continue continue
} }
if len(values) < resultLimit && resultLimit != 0 {
values = values[:resultLimit]
}
fmt.Printf("%v => %s\n", values[0].Labels, n) fmt.Printf("%v => %s\n", values[0].Labels, n)
for _, m := range values { for _, m := range values {
fmt.Printf("%v => %s %v\n", m.Params, n, m.Value) fmt.Printf("%v => %s %v\n", m.Params, n, m.Value)