From 8a8466c98e571b817653310e0eb4cb885076975b Mon Sep 17 00:00:00 2001 From: mlange-42 Date: Sat, 25 May 2024 22:46:10 +0200 Subject: [PATCH 1/2] Rename JSON property `Params` to `ObserverConfig` --- CHANGELOG.md | 1 + _examples/base/observers.json | 6 +-- _examples/patches/observers.json | 6 +-- _examples/systems/observers.json | 4 +- _examples/weather_builtin/observers.json | 4 +- _examples/weather_file/observers.json | 4 +- internal/util/observers.go | 50 ++++++++++++------------ 7 files changed, 38 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d50f0f0..a2c0dd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Show plots only when a single run is performed (#19) - Restructured code for use as a library/module (#26) +- Renames JSON property `Params` to `ObserverConfig` (#49) ## [[v0.1.0]](https://github.com/mlange-42/beecs-cli/tree/v0.1.0) diff --git a/_examples/base/observers.json b/_examples/base/observers.json index b1132aa..3129736 100644 --- a/_examples/base/observers.json +++ b/_examples/base/observers.json @@ -16,7 +16,7 @@ "TimeSeriesPlots": [ { "Observer": "obs.WorkerCohorts", - "Params": { + "ObserverConfig": { "Cumulative": true }, "DrawInterval": 5, @@ -26,7 +26,7 @@ }, { "Observer": "obs.Stores", - "Params": { + "ObserverConfig": { "PollenFactor": 20 }, "Columns": ["Honey", "Pollen x20"], @@ -39,7 +39,7 @@ "LinePlots": [ { "Observer": "obs.ForagingStats", - "Params": {"Relative": true}, + "ObserverConfig": {"Relative": true}, "X": "Round", "XLim": [0, 40], "YLim": [0, 1.05], diff --git a/_examples/patches/observers.json b/_examples/patches/observers.json index 90eedbf..350dbdd 100644 --- a/_examples/patches/observers.json +++ b/_examples/patches/observers.json @@ -8,7 +8,7 @@ "TimeSeriesPlots": [ { "Observer": "obs.WorkerCohorts", - "Params": { + "ObserverConfig": { "Cumulative": true }, "DrawInterval": 5, @@ -18,7 +18,7 @@ }, { "Observer": "obs.Stores", - "Params": { + "ObserverConfig": { "PollenFactor": 20 }, "Columns": ["Honey", "Pollen x20"], @@ -45,7 +45,7 @@ "LinePlots": [ { "Observer": "obs.ForagingStats", - "Params": {"Relative": true}, + "ObserverConfig": {"Relative": true}, "X": "Round", "XLim": [0, 40], "YLim": [0, 1.05], diff --git a/_examples/systems/observers.json b/_examples/systems/observers.json index 002aa59..567e5c1 100644 --- a/_examples/systems/observers.json +++ b/_examples/systems/observers.json @@ -10,7 +10,7 @@ "TimeSeriesPlots": [ { "Observer": "obs.WorkerCohorts", - "Params": { + "ObserverConfig": { "Cumulative": true }, "DrawInterval": 5, @@ -20,7 +20,7 @@ }, { "Observer": "obs.Stores", - "Params": { + "ObserverConfig": { "PollenFactor": 20 }, "Columns": ["Honey", "Pollen x20"], diff --git a/_examples/weather_builtin/observers.json b/_examples/weather_builtin/observers.json index c023071..f904acc 100644 --- a/_examples/weather_builtin/observers.json +++ b/_examples/weather_builtin/observers.json @@ -2,7 +2,7 @@ "TimeSeriesPlots": [ { "Observer": "obs.WorkerCohorts", - "Params": { + "ObserverConfig": { "Cumulative": true }, "DrawInterval": 5, @@ -12,7 +12,7 @@ }, { "Observer": "obs.Stores", - "Params": { + "ObserverConfig": { "PollenFactor": 20 }, "Columns": ["Honey", "Pollen x20"], diff --git a/_examples/weather_file/observers.json b/_examples/weather_file/observers.json index c023071..f904acc 100644 --- a/_examples/weather_file/observers.json +++ b/_examples/weather_file/observers.json @@ -2,7 +2,7 @@ "TimeSeriesPlots": [ { "Observer": "obs.WorkerCohorts", - "Params": { + "ObserverConfig": { "Cumulative": true }, "DrawInterval": 5, @@ -12,7 +12,7 @@ }, { "Observer": "obs.Stores", - "Params": { + "ObserverConfig": { "PollenFactor": 20 }, "Columns": ["Honey", "Pollen x20"], diff --git a/internal/util/observers.go b/internal/util/observers.go index 35a3a84..0de006a 100644 --- a/internal/util/observers.go +++ b/internal/util/observers.go @@ -41,22 +41,22 @@ type TimeSeriesPlotDef struct { } type LinePlotDef struct { - Labels plot.Labels - Title string - Observer string - Params entry - X string - Y []string - Bounds window.Bounds - DrawInterval int - XLim [2]float64 - YLim [2]float64 + Labels plot.Labels + Title string + Observer string + ObserverConfig entry + X string + Y []string + Bounds window.Bounds + DrawInterval int + XLim [2]float64 + YLim [2]float64 } type TableDef struct { File string Observer string - Params entry + ObserverConfig entry UpdateInterval int Final bool } @@ -64,14 +64,14 @@ type TableDef struct { type StepTableDef struct { File string Observer string - Params entry + ObserverConfig entry UpdateInterval int Final bool } type ViewDef struct { Drawer string - Params entry + DrawerConfig entry Title string Bounds window.Bounds DrawInterval int @@ -176,11 +176,11 @@ func createLinePlots(plots []LinePlotDef) ([]*window.Window, error) { return nil, fmt.Errorf("observer type '%s' is not registered", p.Observer) } observerVal := reflect.New(tp).Interface() - if len(p.Params.Bytes) == 0 { - p.Params.Bytes = []byte("{}") + if len(p.ObserverConfig.Bytes) == 0 { + p.ObserverConfig.Bytes = []byte("{}") } - decoder := json.NewDecoder(bytes.NewReader(p.Params.Bytes)) + decoder := json.NewDecoder(bytes.NewReader(p.ObserverConfig.Bytes)) decoder.DisallowUnknownFields() if err := decoder.Decode(&observerVal); err != nil { return nil, err @@ -218,11 +218,11 @@ func createViews(views []ViewDef) ([]*window.Window, error) { return nil, fmt.Errorf("view type '%s' is not registered", p.Drawer) } drawerVal := reflect.New(tp).Interface() - if len(p.Params.Bytes) == 0 { - p.Params.Bytes = []byte("{}") + if len(p.DrawerConfig.Bytes) == 0 { + p.DrawerConfig.Bytes = []byte("{}") } - decoder := json.NewDecoder(bytes.NewReader(p.Params.Bytes)) + decoder := json.NewDecoder(bytes.NewReader(p.DrawerConfig.Bytes)) decoder.DisallowUnknownFields() if err := decoder.Decode(&drawerVal); err != nil { return nil, err @@ -252,10 +252,10 @@ func createTables(tabs []TableDef) ([]*reporter.RowCallback, error) { return nil, fmt.Errorf("observer type '%s' is not registered", t.Observer) } observerVal := reflect.New(tp).Interface() - if len(t.Params.Bytes) == 0 { - t.Params.Bytes = []byte("{}") + if len(t.ObserverConfig.Bytes) == 0 { + t.ObserverConfig.Bytes = []byte("{}") } - decoder := json.NewDecoder(bytes.NewReader(t.Params.Bytes)) + decoder := json.NewDecoder(bytes.NewReader(t.ObserverConfig.Bytes)) decoder.DisallowUnknownFields() if err := decoder.Decode(&observerVal); err != nil { return nil, err @@ -285,10 +285,10 @@ func createStepTables(tabs []StepTableDef) ([]*reporter.TableCallback, error) { return nil, fmt.Errorf("observer type '%s' is not registered", t.Observer) } observerVal := reflect.New(tp).Interface() - if len(t.Params.Bytes) == 0 { - t.Params.Bytes = []byte("{}") + if len(t.ObserverConfig.Bytes) == 0 { + t.ObserverConfig.Bytes = []byte("{}") } - decoder := json.NewDecoder(bytes.NewReader(t.Params.Bytes)) + decoder := json.NewDecoder(bytes.NewReader(t.ObserverConfig.Bytes)) decoder.DisallowUnknownFields() if err := decoder.Decode(&observerVal); err != nil { return nil, err From b33f17885c4d10daacb7e12ef478dbb6ef1ef9f5 Mon Sep 17 00:00:00 2001 From: mlange-42 Date: Sat, 25 May 2024 23:24:57 +0200 Subject: [PATCH 2/2] fix rename, register observer --- internal/util/observers.go | 8 ++++---- registry/registry.go | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/util/observers.go b/internal/util/observers.go index 0de006a..4b60229 100644 --- a/internal/util/observers.go +++ b/internal/util/observers.go @@ -32,7 +32,7 @@ type TimeSeriesPlotDef struct { Labels plot.Labels Title string Observer string - Params entry + ObserverConfig entry Columns []string Bounds window.Bounds DrawInterval int @@ -135,11 +135,11 @@ func createTimeSeriesPlots(plots []TimeSeriesPlotDef) ([]*window.Window, error) return nil, fmt.Errorf("observer type '%s' is not registered", p.Observer) } observerVal := reflect.New(tp).Interface() - if len(p.Params.Bytes) == 0 { - p.Params.Bytes = []byte("{}") + if len(p.ObserverConfig.Bytes) == 0 { + p.ObserverConfig.Bytes = []byte("{}") } - decoder := json.NewDecoder(bytes.NewReader(p.Params.Bytes)) + decoder := json.NewDecoder(bytes.NewReader(p.ObserverConfig.Bytes)) decoder.DisallowUnknownFields() if err := decoder.Decode(&observerVal); err != nil { return nil, err diff --git a/registry/registry.go b/registry/registry.go index dd3e667..928b3c2 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -24,6 +24,7 @@ func init() { RegisterObserver[obs.NectarVisits]() RegisterObserver[obs.PollenVisits]() + RegisterObserver[obs.AgeStructure]() RegisterObserver[obs.ForagingStats]() RegisterDrawer[plot.Monitor]()