From ac42f8b381b66ee33548292620c694112d273c17 Mon Sep 17 00:00:00 2001 From: Kristoffer Eide <37700866+eidekrist@users.noreply.github.com> Date: Wed, 27 Mar 2019 15:21:46 +0100 Subject: [PATCH] Trend spec for each individual trend (#71) --- cse/cse.go | 10 ++++++---- cse/trending.go | 9 ++++++--- main.go | 3 --- structs/structs.go | 10 +++++----- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cse/cse.go b/cse/cse.go index 9070ab8..64b32c9 100644 --- a/cse/cse.go +++ b/cse/cse.go @@ -371,13 +371,15 @@ func executeCommand(cmd []string, sim *Simulation, status *structs.SimulationSta case "setlabel": success, message = setTrendLabel(status, cmd[1], cmd[2]) case "trend-zoom": - status.TrendSpec = structs.TrendSpec{Auto: false, Begin: parseFloat(cmd[1]), End: parseFloat(cmd[2])} + idx, _ := strconv.Atoi(cmd[1]) + status.Trends[idx].Spec = structs.TrendSpec{Auto: false, Begin: parseFloat(cmd[2]), End: parseFloat(cmd[3])} success = true - message = strCat("Trending values from ", cmd[1], " to ", cmd[2]) + message = strCat("Plotting values from ", cmd[2], " to ", cmd[3]) case "trend-zoom-reset": - status.TrendSpec = structs.TrendSpec{Auto: true, Range: parseFloat(cmd[1])} + idx, _ := strconv.Atoi(cmd[1]) + status.Trends[idx].Spec = structs.TrendSpec{Auto: true, Range: parseFloat(cmd[2])} success = true - message = strCat("Trending last ", cmd[1], " seconds") + message = strCat("Plotting last ", cmd[2], " seconds") case "set-value": success, message = setVariableValue(sim, cmd[1], cmd[2], cmd[3], cmd[4], cmd[5]) case "reset-value": diff --git a/cse/trending.go b/cse/trending.go index d7ebd5e..de1654a 100644 --- a/cse/trending.go +++ b/cse/trending.go @@ -25,7 +25,10 @@ func addNewTrend(status *structs.SimulationStatus, plotType string, label string Id: id, PlotType: plotType, Label: label, - TrendSignals: []structs.TrendSignal{}}) + TrendSignals: []structs.TrendSignal{}, + Spec: structs.TrendSpec{ + Auto: true, + Range: 10.0}}) return true, "Added new trend" } @@ -110,7 +113,7 @@ func TrendLoop(sim *Simulation, status *structs.SimulationStatus) { var signal = &trend.TrendSignals[i] switch signal.Type { case "Real": - observerGetRealSamples(sim.TrendObserver, signal, status.TrendSpec) + observerGetRealSamples(sim.TrendObserver, signal, trend.Spec) } } } @@ -122,7 +125,7 @@ func TrendLoop(sim *Simulation, status *structs.SimulationStatus) { var signal1 = &trend.TrendSignals[j] var signal2 = &trend.TrendSignals[j+1] if (signal1.Type == "Real" && signal2.Type == "Real") { - observerGetRealSynchronizedSamples(sim.TrendObserver, signal1, signal2, status.TrendSpec) + observerGetRealSynchronizedSamples(sim.TrendObserver, signal1, signal2, trend.Spec) } } } diff --git a/main.go b/main.go index df2b7e4..000e625 100644 --- a/main.go +++ b/main.go @@ -17,9 +17,6 @@ func main() { Loaded: false, Status: "stopped", Trends: []structs.Trend{}, - TrendSpec: structs.TrendSpec{ - Auto: true, - Range: 10.0}, } // Passing the channel to the go routine diff --git a/structs/structs.go b/structs/structs.go index 9ee8be0..3694ad8 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -44,13 +44,14 @@ type Trend struct { PlotType string `json:"plot-type"` Label string `json:"label"` TrendSignals []TrendSignal `json:"trend-values"` + Spec TrendSpec `json:"spec"` } type TrendSpec struct { - Begin float64 - End float64 - Range float64 - Auto bool + Begin float64 `json:"begin"` + End float64 `json:"end"` + Range float64 `json:"range"` + Auto bool `json:"auto"` } type ShortLivedData struct { @@ -65,7 +66,6 @@ type SimulationStatus struct { Module string SignalSubscriptions []Variable Trends []Trend - TrendSpec TrendSpec Status string CurrentScenario string }