Skip to content

Commit

Permalink
POST endpoint for saving current plot configuration
Browse files Browse the repository at this point in the history
A new endpoint POST /plot-config is created. Takes the simulation status and writes it in the expected format to
PlotConfig.json in the directory where the simulation was loaded from. A  preflight endpoint is added to allow cross origin
calls from figwheel running at port 3449.

Closes #110
  • Loading branch information
Flakstad authored and Flakstad committed May 6, 2020
1 parent ef29a28 commit e1cbd96
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ password to access it:

### Step 2: Cse Client

If you want to include the cse-client in the server you will have to manually copy in the client app. Latest build of
If you want to include the cse-client in the server you will have to manually copy in the client app. Latest build of
the client is available here: https://osp-jenkins.azurewebsites.net/job/open-simulation-platform/job/cse-client/job/master/lastSuccessfulBuild/artifact/

Extract the files into:

./resources/public

Alternatively you can run the client using figwheel as described in https://github.com/open-simulation-platform/cse-client

### Step 3: Build and run
Expand All @@ -41,45 +41,45 @@ You can do this in two ways:

From the cse-server-go source directory, get C/C++ dependencies using Conan:

conan install . -s build_type=Release -g virtualrunenv
conan install . -u -s build_type=Release -g virtualrunenv
go build

To run the application on Windows:
activate_run.bat

activate_run.bat (activate_run.ps1 in PowerShell)
cse-server-go.exe
deactivate_run.bat when done
deactivate_run.bat when done (deactivate_run.ps1 in PowerShell)

To run the application on Linux:

source activate_run.sh
./cse-server-go
./deactivate_run.sh when done

Open a browser at http://localhost:8000/status to verify that it's running (you should see some JSON).

#### Alternative 2: Manually handle cse-core dependencies

You will have to define CGO environment variables with arguments pointing to your cse-core headers and libraries. An
You will have to define CGO environment variables with arguments pointing to your cse-core headers and libraries. An
example for Windows can be:

set CGO_CFLAGS=-IC:\dev\cse-core\include
set CGO_LDFLAGS=-LC:\dev\cse-core\bin -lcsecorec -lcsecorecpp
go build

To run the application on Windows you need to also update the path to point to your libraries:

set PATH=C:\cse-core\bin;%PATH%
cse-server-go.exe

To run the application on Linux you need to update the LD_LIBRARY_PATH:

LD_LIBRARY_PATH=~dev/cse-core/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
./cse-server-go

Open a browser at http://localhost:8000/status to verify that it's running (you should see some JSON).

### Create distribution with built-in client

To package the application with the client you can use packr. You can install packr and build distributable with:
Expand Down
30 changes: 30 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@ func Server(command chan []string, state chan structs.JsonResponse, simulationSt
json.NewEncoder(w).Encode(sim.MetaData)
})

router.HandleFunc("/plot-config", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
}).Methods("OPTIONS")

router.HandleFunc("/plot-config", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
configDir := simulationStatus.ConfigDir
trends := simulationStatus.Trends
plots := []structs.Plot{}
for i := 0; i < len(trends); i++ {
trendValues := trends[i].TrendSignals
variables := []structs.PlotVariable{}
for j := 0; j < len(trendValues); j++ {
plotVariable := structs.PlotVariable{trendValues[j].Module, trendValues[j].Signal}
variables = append(variables, plotVariable)
}
plot := structs.Plot{trends[i].Label, trends[i].PlotType, variables}
plots = append(plots, plot)
}
plotConfig := structs.PlotConfig{plots}
plotConfigJson, _ := json.Marshal(plotConfig)
err := ioutil.WriteFile(configDir + "/" + "PlotConfig.json", plotConfigJson, 0644)
if err != nil {
log.Println("Could not write PlotConfig to file, data: ", plotConfig, ", error was:", err)
}
json.NewEncoder(w).Encode("Wrote plot configuration to " + configDir + "/" + "PlotConfig.json")
}).Methods("POST")

router.HandleFunc("/value/{module}/{cardinality}/{signal}", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
vars := mux.Vars(r)
Expand Down

0 comments on commit e1cbd96

Please sign in to comment.