Skip to content

Commit 5b452e9

Browse files
author
Levi Jamt
committed
Merge remote-tracking branch 'origin/master' into release/v0.7.0
2 parents 864c134 + 653e8c5 commit 5b452e9

File tree

7 files changed

+88
-64
lines changed

7 files changed

+88
-64
lines changed

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Contributor guidelines
2+
======================
3+
4+
This document contains a set of rules and guidelines for everyone who wishes
5+
to contribute to the contents of this repository, hereafter referred to as
6+
"the software".
7+
8+
9+
General
10+
-------
11+
All contributors implicitly agree to license their contribution under the same
12+
terms as the rest of the software, and accept that those terms may change in the
13+
future. See the `LICENCE.txt` file for details.
14+
15+
All contributions to the software, in the form of changes, removals or
16+
additions to source code and other files under source control, shall be made
17+
via pull requests. A pull request must always be reviewed and merged by someone
18+
other than its author.
19+
20+
Before a pull request can be approved and merged into the code base, the author
21+
must sign the "OSP Contributor License Agreement". This agreement is pending, but
22+
will be included in this repository with guidelines once concluded.

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Copyright (c) 2020 DNV GL AS, Kongsberg Maritime CM AS, SINTEF Ocean AS, and NTNU.
2+
13
Mozilla Public License Version 2.0
24
==================================
35

libcosim/libcosim.go

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -646,27 +646,27 @@ func initializeSimulation(sim *Simulation, status *structs.SimulationStatus, con
646646
}
647647

648648
func resetSimulation(sim *Simulation, status *structs.SimulationStatus, configPath string, logDir string) (bool, string, string) {
649-
var success = false
650-
var message = ""
651-
var configDir = ""
652-
653-
success, message = executionStop(sim.Execution)
654-
log.Println(message)
655-
656-
if success{
657-
status.Loaded = false
658-
status.Status = "stopped"
659-
status.ConfigDir = ""
660-
status.Trends = []structs.Trend{}
661-
status.Module = ""
662-
success, message = simulationTeardown(sim)
663-
log.Println(message)
664-
}
665-
666-
success, message, configDir = initializeSimulation(sim, status, configPath, logDir)
667-
log.Println(message)
668-
669-
return success, message, configDir
649+
var success = false
650+
var message = ""
651+
var configDir = ""
652+
653+
success, message = executionStop(sim.Execution)
654+
log.Println(message)
655+
656+
if success {
657+
status.Loaded = false
658+
status.Status = "stopped"
659+
status.ConfigDir = ""
660+
status.Trends = []structs.Trend{}
661+
status.Module = ""
662+
success, message = simulationTeardown(sim)
663+
log.Println(message)
664+
}
665+
666+
success, message, configDir = initializeSimulation(sim, status, configPath, logDir)
667+
log.Println(message)
668+
669+
return success, message, configDir
670670
}
671671

672672
func executeCommand(cmd []string, sim *Simulation, status *structs.SimulationStatus) (shorty structs.ShortLivedData, feedback structs.CommandFeedback) {
@@ -695,18 +695,18 @@ func executeCommand(cmd []string, sim *Simulation, status *structs.SimulationSta
695695
success, message = simulationTeardown(sim)
696696
shorty.ModuleData = sim.MetaData
697697
case "reset":
698-
status.Loading = true
699-
var configDir string
700-
success, message, configDir = resetSimulation(sim, status, cmd[1], cmd[2])
701-
if success {
702-
status.Loaded = true
703-
status.ConfigDir = configDir
704-
status.Status = "pause"
705-
shorty.ModuleData = sim.MetaData
706-
scenarios := findScenarios(status)
707-
shorty.Scenarios = &scenarios
708-
}
709-
status.Loading = false
698+
status.Loading = true
699+
var configDir string
700+
success, message, configDir = resetSimulation(sim, status, cmd[1], cmd[2])
701+
if success {
702+
status.Loaded = true
703+
status.ConfigDir = configDir
704+
status.Status = "pause"
705+
shorty.ModuleData = sim.MetaData
706+
scenarios := findScenarios(status)
707+
shorty.Scenarios = &scenarios
708+
}
709+
status.Loading = false
710710
case "pause":
711711
success, message = executionStop(sim.Execution)
712712
status.Status = "pause"
@@ -885,6 +885,7 @@ func GenerateJsonResponse(status *structs.SimulationStatus, sim *Simulation, fee
885885
response.IsRealTimeSimulation = execStatus.isRealTimeSimulation
886886
response.Module = findModuleData(status, sim.MetaData, sim.Observer)
887887
response.ConfigDir = status.ConfigDir
888+
generatePlotData(sim, status)
888889
response.Trends = status.Trends
889890
response.ManipulatedVariables = fetchManipulatedVariables(sim.Execution)
890891
if sim.ScenarioManager != nil && isScenarioRunning(sim.ScenarioManager) {

libcosim/trending.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"os"
1414
"path/filepath"
1515
"strconv"
16-
"time"
1716
)
1817

1918
func generateNextTrendId(status *structs.SimulationStatus) int {
@@ -131,39 +130,40 @@ func activeTrend(status *structs.SimulationStatus, trendIndex string) (bool, str
131130
return true, "Changed active trend index"
132131
}
133132

134-
func TrendLoop(sim *Simulation, status *structs.SimulationStatus) {
135-
for {
136-
for _, trend := range status.Trends {
137-
if status.ActiveTrend != trend.Id {
138-
continue
133+
func generatePlotData(sim *Simulation, status *structs.SimulationStatus) {
134+
for idx, trend := range status.Trends {
135+
if status.ActiveTrend != idx {
136+
for i, _ := range trend.TrendSignals {
137+
trend.TrendSignals[i].TrendXValues = nil
138+
trend.TrendSignals[i].TrendYValues = nil
139139
}
140-
switch trend.PlotType {
141-
case "trend":
142-
if len(trend.TrendSignals) > 0 {
143-
for i, _ := range trend.TrendSignals {
144-
var signal = &trend.TrendSignals[i]
145-
switch signal.Type {
146-
case "Real":
147-
observerGetRealSamples(sim.TrendObserver, signal, trend.Spec)
148-
}
140+
continue
141+
}
142+
switch trend.PlotType {
143+
case "trend":
144+
if len(trend.TrendSignals) > 0 {
145+
for i, _ := range trend.TrendSignals {
146+
var signal = &trend.TrendSignals[i]
147+
switch signal.Type {
148+
case "Real":
149+
observerGetRealSamples(sim.TrendObserver, signal, trend.Spec)
149150
}
150151
}
151-
break
152-
case "scatter":
153-
signalCount := len(trend.TrendSignals)
154-
if signalCount > 0 {
155-
for j := 0; (j + 1) < signalCount; j += 2 {
156-
var signal1 = &trend.TrendSignals[j]
157-
var signal2 = &trend.TrendSignals[j+1]
158-
if signal1.Type == "Real" && signal2.Type == "Real" {
159-
observerGetRealSynchronizedSamples(sim.TrendObserver, signal1, signal2, trend.Spec)
160-
}
152+
}
153+
break
154+
case "scatter":
155+
signalCount := len(trend.TrendSignals)
156+
if signalCount > 0 {
157+
for j := 0; (j + 1) < signalCount; j += 2 {
158+
var signal1 = &trend.TrendSignals[j]
159+
var signal2 = &trend.TrendSignals[j+1]
160+
if signal1.Type == "Real" && signal2.Type == "Real" {
161+
observerGetRealSynchronizedSamples(sim.TrendObserver, signal1, signal2, trend.Spec)
161162
}
162163
}
163-
break
164164
}
165+
break
165166
}
166-
time.Sleep(1000 * time.Millisecond)
167167
}
168168
}
169169

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func main() {
2828
// Passing the channel to the go routine
2929
go libcosim.StateUpdateLoop(state, &simulationStatus, &sim)
3030
go libcosim.CommandLoop(state, &sim, cmd, &simulationStatus)
31-
go libcosim.TrendLoop(&sim, &simulationStatus)
3231

3332
//Passing the channel to the server
3433
server.Server(cmd, state, &simulationStatus, &sim)

server/websockets.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func stateLoop(state chan structs.JsonResponse, conn *websocket.Conn) {
6565
if err != nil {
6666
log.Println("write error:", err)
6767
log.Println("latestState:", latestState)
68+
state <- latestState
6869
break
6970
}
7071
}

src/client/controller.cljs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@
153153

154154
(k/reg-event-fx ::trend-enter
155155
(fn [{:keys [db]} [{:keys [index]}]]
156-
(let [trend-id (-> db :state :trends (get (int index)) :id)]
157-
(merge {:db (assoc db :active-trend-index index)}
158-
(socket-command ["active-trend" (str trend-id)])))))
156+
(merge {:db (assoc db :active-trend-index index)}
157+
(socket-command ["active-trend" (str index)]))))
159158

160159
(k/reg-event-fx ::trend-leave
161160
(fn [{:keys [db]} _]

0 commit comments

Comments
 (0)