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

Provide trend data for multiple variables #45

Merged
merged 3 commits into from
Jan 2, 2019
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
21 changes: 13 additions & 8 deletions cse/cse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"cse-server-go/metadata"
"cse-server-go/structs"
"fmt"
"github.com/shirou/gopsutil/mem"
"io/ioutil"
"log"
"math"
Expand Down Expand Up @@ -258,13 +257,17 @@ func findVariableIndex(fmu structs.FMU, signalName string, causality string, val

func TrendLoop(sim *Simulation, status *structs.SimulationStatus) {
for {
status.Mutex.Lock()
if len(status.TrendSignals) > 0 {
var trend = &status.TrendSignals[0]
switch trend.Type {
case "Real":
observerGetRealSamples(sim.Observer, sim.MetaData, trend, status.TrendSpec)
for i, _ := range status.TrendSignals {
var trend = &status.TrendSignals[i]
switch trend.Type {
case "Real":
observerGetRealSamples(sim.Observer, sim.MetaData, trend, status.TrendSpec)
}
}
}
status.Mutex.Unlock()
time.Sleep(500 * time.Millisecond)
}
}
Expand Down Expand Up @@ -325,6 +328,7 @@ func CommandLoop(sim *Simulation, command chan []string, status *structs.Simulat
for {
select {
case cmd := <-command:
status.Mutex.Lock()
switch cmd[0] {
case "load":
initializeSimulation(sim, cmd[1], cmd[2])
Expand Down Expand Up @@ -365,8 +369,9 @@ func CommandLoop(sim *Simulation, command chan []string, status *structs.Simulat
case "set-value":
setVariableValue(sim, cmd[1], cmd[2], cmd[3], cmd[4], cmd[5])
default:
fmt.Println("Empty command, mildt sagt not good: ", cmd)
fmt.Println("Unknown command, this is not good: ", cmd)
}
status.Mutex.Unlock()
}
}
}
Expand Down Expand Up @@ -416,7 +421,8 @@ func GetSignalValue(module string, cardinality string, signal string) int {
}

func SimulationStatus(simulationStatus *structs.SimulationStatus, sim *Simulation) structs.JsonResponse {
virtualMemoryStats, _ := mem.VirtualMemory()
simulationStatus.Mutex.Lock()
defer simulationStatus.Mutex.Unlock()
if simulationStatus.Loaded {
execStatus := getExecutionStatus(sim.Execution)
return structs.JsonResponse{
Expand All @@ -429,7 +435,6 @@ func SimulationStatus(simulationStatus *structs.SimulationStatus, sim *Simulatio
Status: simulationStatus.Status,
ConfigDir: simulationStatus.ConfigDir,
TrendSignals: simulationStatus.TrendSignals,
Memory: virtualMemoryStats,
}
} else {
return structs.JsonResponse{
Expand Down
34 changes: 17 additions & 17 deletions structs/structs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package structs

import (
"github.com/shirou/gopsutil/mem"
"sync"
)

type Signal struct {
Expand All @@ -17,25 +17,24 @@ type Module struct {
}

type JsonResponse struct {
Loaded bool `json:"loaded"`
SimulationTime float64 `json:"time"`
RealTimeFactor float64 `json:"realTimeFactor"`
IsRealTimeSimulation bool `json:"isRealTime"`
ConfigDir string `json:"configDir,omitempty"`
Status string `json:"status,omitempty"`
Modules []string `json:"modules"`
Module Module `json:"module,omitempty"`
Memory *mem.VirtualMemoryStat
TrendSignals []TrendSignal `json:"trendSignals,omitempty"`
Loaded bool `json:"loaded"`
SimulationTime float64 `json:"time"`
RealTimeFactor float64 `json:"realTimeFactor"`
IsRealTimeSimulation bool `json:"isRealTime"`
ConfigDir string `json:"configDir,omitempty"`
Status string `json:"status,omitempty"`
Modules []string `json:"modules"`
Module Module `json:"module,omitempty"`
TrendSignals []TrendSignal `json:"trend-values"`
}

type TrendSignal struct {
Module string
Signal string
Causality string
Type string
TrendValues []float64
TrendTimestamps []float64
Module string `json:"module"`
Signal string `json:"signal"`
Causality string `json:"causality"`
Type string `json:"type"`
TrendValues []float64 `json:"values,omitempty"`
TrendTimestamps []float64 `json:"labels,omitempty"`
}

type TrendSpec struct {
Expand All @@ -46,6 +45,7 @@ type TrendSpec struct {
}

type SimulationStatus struct {
Mutex sync.Mutex
Loaded bool
ConfigDir string
Module Module
Expand Down