Skip to content

Commit

Permalink
Merge pull request #28 from Cambio-Project/mtl-stimuli
Browse files Browse the repository at this point in the history
Add MTL Stimuli creation and application to analyses
  • Loading branch information
franksn90 authored May 8, 2024
2 parents 9e24227 + 0f32b88 commit 51b7218
Show file tree
Hide file tree
Showing 19 changed files with 1,311 additions and 393 deletions.
1,328 changes: 1,018 additions & 310 deletions components/PSPWizard.vue

Large diffs are not rendered by default.

69 changes: 41 additions & 28 deletions components/ScenarioEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default {
environmentExperiment: null,
environmentLoad: null,
environmentMonitoringData: null,
environmentMTLFiles: null,
responses: null,
importErrorMessage: null,
Expand Down Expand Up @@ -67,16 +66,16 @@ export default {
if (typeof body.Scenario.environment.monitoringData !== "undefined") {
this.environmentMonitoringData = body.Scenario.environment.monitoringData
}
if (typeof body.Scenario.environment.mtlFiles !== "undefined") {
this.environmentMTLFiles = body.Scenario.environment.mtlFiles
}
if (typeof body.Scenario.responses !== "undefined") {
this.responses = body.Scenario.responses
}
},
// create response with pspwizard
openPSPResponse() {
this.$router.push('/pspwizardSite?simID=' + this.simID);
this.$router.push('/pspwizardSite?simID=' + this.simID + '&type=response');
},
openPSPStimulus() {
this.$router.push('/pspwizardSite?simID=' + this.simID + '&type=stimulus');
},
// remove stimulus
removeStimulus(index) {
Expand All @@ -94,14 +93,10 @@ export default {
removeEnvironmentLoad(index) {
this.deleteField("environment.load", index)
},
// remove load
// remove monitoring data
removeEnvironmentMonitoringData(index) {
this.deleteField("environment.monitoringData", index)
},
// remove load
removeEnvironmentMTLFiles(index) {
this.deleteField("environment.mtlFiles", index)
},
// remove response
removeResponse(index) {
this.deleteField("responses", index)
Expand Down Expand Up @@ -155,11 +150,6 @@ export default {
this.environmentMonitoringData = []
this.upload(type, fileInput)
},
uploadMTLFiles(type) {
const fileInput = this.$refs.fileInputEnvironmentMTLFiles;
this.environmentMTLFiles = []
this.upload(type, fileInput)
},
async upload(type, fileInput) {
this.loadedFiles = []
console.log("HERE")
Expand Down Expand Up @@ -322,7 +312,6 @@ export default {
this.environmentExperiment = null
this.environmentLoad = null
this.environmentMonitoringData = null
this.environmentMTLFiles = null
this.responses = null
this.showTooltip = false
},
Expand Down Expand Up @@ -423,7 +412,43 @@ const domain = "http://" + config.public.miSimDomain + ":" + config.public.miSim
<div class="message-container">

<p>Stimuli:</p>
<li v-for="(stimulus, index) in stimuli" :key="stimulus" class="left">
{{ index + 1 }}.
<select v-model="stimulus.target_logic" class="select-box">
<option v-for="targetLogic in targetLogics" :key="targetLogic" :value="targetLogics.indexOf(targetLogic)">
{{ targetLogic }}
</option>
</select>

<span v-if="stimulus.target_logic===0">
{{ stimulus.SEL }}
</span>
<span v-if="stimulus.target_logic===1">
{{ stimulus.LTL }}
</span>
<span v-if="stimulus.target_logic===2">
{{ stimulus.MTL }}
</span>
<span v-if="stimulus.target_logic===3">
{{ stimulus.Prism }}
</span>
<span v-if="stimulus.target_logic===4">
{{ stimulus.Quantitative_Prism }}
</span>
<span v-if="stimulus.target_logic===5">
{{ stimulus.TBV_untimed }}
</span>
<span v-if="stimulus.target_logic===6">
{{ stimulus.TBV_timed }}
</span>

<button class="remove-button" @click="removeStimulus(index)">Remove</button>
<br>
<i class="sel-line"> <strong>SEL:</strong> {{ stimulus.SEL }} </i> <br> <br>

</li>

<UButton @click="openPSPStimulus">Add Stimulus</UButton>
</div>

<div class="message-container">
Expand Down Expand Up @@ -478,18 +503,6 @@ const domain = "http://" + config.public.miSimDomain + ":" + config.public.miSim
</li>
</ul>

<p>MTL-Files:</p>
<input class="custom-file-input" id="fileInput" type="file"
ref="fileInputEnvironmentMTLFiles" @change="uploadMTLFiles('environment.mtlFiles')">

<ul>
<li v-for="(file, index) in environmentMTLFiles">
{{ Object.keys(file) }}
<button class="remove-button" @click="removeEnvironmentMTLFiles(index)">Remove</button>
<br>
</li>
</ul>

</div>

<div class="message-container">
Expand Down
48 changes: 42 additions & 6 deletions components/Scenarios.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
const body = await res.json();
scenario.mosimState = 'done';
console.log("MiSim Response for simulationID: " + simulationID + ": ", body)
console.log("MoSim Response for simulationID: " + simulationID + ": ", body)
return 'done'
},
Expand Down Expand Up @@ -163,6 +163,9 @@ export default {
scenario.responses.forEach(response => {
response.target_logic = this.target;
})
scenario.stimuli.forEach(stimulus => {
stimulus.target_logic = this.target;
})
});
},
//Download a single scenario as json
Expand Down Expand Up @@ -304,6 +307,44 @@ export default {
<h4 class="text-mb font-bold mb-1">
Stimuli:
</h4>
<span>
<!--{{scenario.responses[0]}}-->
<li v-for="(stimulus, index) in scenario.stimuli" :key="stimulus"
:style="{ color: getVerificationTextColor(scenario, index)}" class="left">
{{ index + 1 }}.
<select v-model="stimulus.target_logic" class="select-box">
<option v-for="targetLogic in targetLogics" :key="targetLogic"
:value="targetLogics.indexOf(targetLogic)">{{ targetLogic }}</option>
</select>
<span v-if="stimulus.target_logic===0">
{{ stimulus.SEL }}
</span>
<span v-if="stimulus.target_logic===1">
{{ stimulus.LTL }}
</span>
<span v-if="stimulus.target_logic===2">
{{ stimulus.MTL }}
</span>
<span v-if="stimulus.target_logic===3">
{{ stimulus.Prism }}
</span>
<span v-if="stimulus.target_logic===4">
{{ stimulus.Quantitative_Prism }}
</span>
<span v-if="stimulus.target_logic===5">
{{ stimulus.TBV_untimed }}
</span>
<span v-if="stimulus.target_logic===6">
{{ stimulus.TBV_timed }}
</span>

<div>
<i class="sel-line"> <strong>SEL:</strong> {{ stimulus.SEL }} </i>
<br> <br>
</div>
</li>
</span>

</div>

<div class="left mb-8">
Expand Down Expand Up @@ -331,11 +372,6 @@ export default {
- Monitoring Data: <i>{{ Object.keys(monitoringData)[0] }}</i>
</li>
</ul>
<ul>
<li v-for="mtlFile in scenario.environment.mtlFiles">
- MTL-File: <i>{{ Object.keys(mtlFile)[0] }}</i>
</li>
</ul>
</div>

<h4 class="left text-mb font-bold mb-1">
Expand Down
14 changes: 14 additions & 0 deletions server/api/allCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Command} from "~/server/models/command.model";

export default defineEventHandler(async (event) => {

let commands: any = []

try {
commands = await Command.find({})
} catch (e) {
console.log("Error finding commands")
}

return commands
});
14 changes: 14 additions & 0 deletions server/api/allListeners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Listener} from "~/server/models/listener.model";

export default defineEventHandler(async (event) => {

let listeners: any = []

try {
listeners = await Listener.find({})
} catch (e) {
console.log("Error finding events")
}

return listeners
});
21 changes: 21 additions & 0 deletions server/api/changeCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {Command} from "~/server/models/command.model";

export default defineEventHandler(async (event) => {
// read the request body
const body = await readBody(event);
const requestBody = JSON.parse(body);

try {
// extract the ID of the item to be updated
const commandId = requestBody._id;
// remove _id from the update data
delete requestBody._id;

// update the event
const updatedCommand = await Command.updateOne({_id: commandId}, requestBody);

} catch (e) {
console.log("Error updating command:", e);
return {"done": false};
}
});
21 changes: 21 additions & 0 deletions server/api/changeListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {Listener} from "~/server/models/listener.model";

export default defineEventHandler(async (event) => {
// read the request body
const body = await readBody(event);
const requestBody = JSON.parse(body);

try {
// extract the ID of the item to be updated
const listenerId = requestBody._id;
// remove _id from the update data
delete requestBody._id;

// update the event
const updatedListener = await Listener.updateOne({_id: listenerId}, requestBody);

} catch (e) {
console.log("Error updating listener:", e);
return {"done": false};
}
});
19 changes: 19 additions & 0 deletions server/api/deleteCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Command} from "~/server/models/command.model";

export default defineEventHandler(async (event) => {
// Read the request body
const body = await readBody(event);
const requestBody = JSON.parse(body);

try {
// extract the ID of the item to be deleted
const commandId = requestBody._id;

// find and delete the event by its ID
const deletedCommand = await Command.deleteOne({ _id: commandId });

} catch (e) {
console.log("Error deleting command:", e);
return { "done": false };
}
});
19 changes: 19 additions & 0 deletions server/api/deleteListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Listener} from "~/server/models/listener.model";

export default defineEventHandler(async (event) => {
// Read the request body
const body = await readBody(event);
const requestBody = JSON.parse(body);

try {
// extract the ID of the item to be deleted
const listenerId = requestBody._id;

// find and delete the event by its ID
const deletedListener = await Listener.deleteOne({ _id: listenerId });

} catch (e) {
console.log("Error deleting event:", e);
return { "done": false };
}
});
19 changes: 19 additions & 0 deletions server/api/saveCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Command} from "~/server/models/command.model";
import * as crypto from "crypto";

export default defineEventHandler(async (event) => {
let body = await readBody(event)
body = JSON.parse(body)

body["_id"] = crypto.randomUUID()

try {
await Command.create(body)
} catch (e) {
console.log("Error creating command")
}

return {
"done": true
};
});
19 changes: 19 additions & 0 deletions server/api/saveListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Listener} from "~/server/models/listener.model";
import * as crypto from "crypto";

export default defineEventHandler(async (event) => {
let body = await readBody(event);
body = JSON.parse(body)

body["_id"] = crypto.randomUUID()

try {
await Listener.create(body)
} catch (e) {
console.log("Error creating listener")
}

return {
"done": true
};
});
Loading

0 comments on commit 51b7218

Please sign in to comment.