Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename JSON property Params to ObserverConfig #49

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions _examples/base/observers.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"TimeSeriesPlots": [
{
"Observer": "obs.WorkerCohorts",
"Params": {
"ObserverConfig": {
"Cumulative": true
},
"DrawInterval": 5,
Expand All @@ -26,7 +26,7 @@
},
{
"Observer": "obs.Stores",
"Params": {
"ObserverConfig": {
"PollenFactor": 20
},
"Columns": ["Honey", "Pollen x20"],
Expand All @@ -39,7 +39,7 @@
"LinePlots": [
{
"Observer": "obs.ForagingStats",
"Params": {"Relative": true},
"ObserverConfig": {"Relative": true},
"X": "Round",
"XLim": [0, 40],
"YLim": [0, 1.05],
Expand Down
6 changes: 3 additions & 3 deletions _examples/patches/observers.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"TimeSeriesPlots": [
{
"Observer": "obs.WorkerCohorts",
"Params": {
"ObserverConfig": {
"Cumulative": true
},
"DrawInterval": 5,
Expand All @@ -18,7 +18,7 @@
},
{
"Observer": "obs.Stores",
"Params": {
"ObserverConfig": {
"PollenFactor": 20
},
"Columns": ["Honey", "Pollen x20"],
Expand All @@ -45,7 +45,7 @@
"LinePlots": [
{
"Observer": "obs.ForagingStats",
"Params": {"Relative": true},
"ObserverConfig": {"Relative": true},
"X": "Round",
"XLim": [0, 40],
"YLim": [0, 1.05],
Expand Down
4 changes: 2 additions & 2 deletions _examples/systems/observers.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"TimeSeriesPlots": [
{
"Observer": "obs.WorkerCohorts",
"Params": {
"ObserverConfig": {
"Cumulative": true
},
"DrawInterval": 5,
Expand All @@ -20,7 +20,7 @@
},
{
"Observer": "obs.Stores",
"Params": {
"ObserverConfig": {
"PollenFactor": 20
},
"Columns": ["Honey", "Pollen x20"],
Expand Down
4 changes: 2 additions & 2 deletions _examples/weather_builtin/observers.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"TimeSeriesPlots": [
{
"Observer": "obs.WorkerCohorts",
"Params": {
"ObserverConfig": {
"Cumulative": true
},
"DrawInterval": 5,
Expand All @@ -12,7 +12,7 @@
},
{
"Observer": "obs.Stores",
"Params": {
"ObserverConfig": {
"PollenFactor": 20
},
"Columns": ["Honey", "Pollen x20"],
Expand Down
4 changes: 2 additions & 2 deletions _examples/weather_file/observers.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"TimeSeriesPlots": [
{
"Observer": "obs.WorkerCohorts",
"Params": {
"ObserverConfig": {
"Cumulative": true
},
"DrawInterval": 5,
Expand All @@ -12,7 +12,7 @@
},
{
"Observer": "obs.Stores",
"Params": {
"ObserverConfig": {
"PollenFactor": 20
},
"Columns": ["Honey", "Pollen x20"],
Expand Down
58 changes: 29 additions & 29 deletions internal/util/observers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,37 +41,37 @@ 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
}

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func init() {
RegisterObserver[obs.NectarVisits]()
RegisterObserver[obs.PollenVisits]()

RegisterObserver[obs.AgeStructure]()
RegisterObserver[obs.ForagingStats]()

RegisterDrawer[plot.Monitor]()
Expand Down
Loading