From 5064245b4c12ccda2c269e3b54f0df4c41717be9 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Wed, 22 May 2024 15:19:04 +0200 Subject: [PATCH 01/24] Fix Transform all Target Logics Button in Scenario Editor only transforms Responses --- components/ScenarioEditor.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/ScenarioEditor.vue b/components/ScenarioEditor.vue index 8d5cebd..85f41b2 100644 --- a/components/ScenarioEditor.vue +++ b/components/ScenarioEditor.vue @@ -127,6 +127,9 @@ export default { this.responses.forEach(response => { response.target_logic = this.target; }) + this.stimuli.forEach(stimulus => { + stimulus.target_logic = this.target; + }) }, uploadStimuli(type) { const fileInput = this.$refs.fileInputStimulus; From 3da90c8d350898ea574a6f52dd59be9868e26f02 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Wed, 22 May 2024 15:37:55 +0200 Subject: [PATCH 02/24] Delete result metrics in DB when scenario is deleted --- components/Scenario.vue | 6 +++--- components/Scenarios.vue | 6 +++--- server/api/deleteScenario.ts | 28 ++++++++-------------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/components/Scenario.vue b/components/Scenario.vue index 49ef6ad..a2f48aa 100644 --- a/components/Scenario.vue +++ b/components/Scenario.vue @@ -86,11 +86,11 @@ export default { this.$router.push('/scenariosSite'); }, // Remove one scenario - async removeScenario(ID) { + async removeScenario(simulationID) { const res = await fetch("/api/deleteScenario", { method: "POST", body: JSON.stringify({ - ID: ID + simulationID: simulationID }) }) const body = await res.json(); @@ -300,7 +300,7 @@ export default {
- +
diff --git a/components/Scenarios.vue b/components/Scenarios.vue index abb766a..5f1a1e8 100644 --- a/components/Scenarios.vue +++ b/components/Scenarios.vue @@ -106,11 +106,11 @@ export default { } }, // Remove one scenario - async removeScenario(ID) { + async removeScenario(simulationID) { const res = await fetch("/api/deleteScenario", { method: "POST", body: JSON.stringify({ - ID: ID + simulationID: simulationID }) }) const body = await res.json(); @@ -392,7 +392,7 @@ export default { + @click="removeScenario(scenario.simulationID);"> diff --git a/server/api/deleteScenario.ts b/server/api/deleteScenario.ts index 8738c0a..0c2b8a9 100644 --- a/server/api/deleteScenario.ts +++ b/server/api/deleteScenario.ts @@ -1,34 +1,22 @@ import {Scenario} from "~/server/models/scenario.model"; + export default defineEventHandler(async (event) => { // Read the request body var body = await readBody(event) body = JSON.parse(body) - if (typeof body.ID === "undefined") { + if (typeof body.simulationID === "undefined") { return { "success": false, - "message": "ID not defined" - } - } + "message": "simulationID not defined" + } + } - const ID = body.ID + const simulationID = body.simulationID try { - // const scenario = await Scenario.findOne({ _id: ID }); - - // if (!scenario) { - // return { - // success: false, - // message: "Scenario not found", - // }; - // } - - // delete the value from the array - // @ts-ignore - await Scenario.deleteOne({ _id: ID }); - - //await scenario.save(); - + await Scenario.deleteOne({simulationID: simulationID}); + await Result.deleteOne({simulationID: simulationID}); } catch (e) { console.log(e) return { From 18b550f232147f3f54c1d8a05febb899f11e32d1 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Thu, 23 May 2024 10:16:05 +0200 Subject: [PATCH 03/24] Add notifications and check for duplicate events/listeners/commands --- components/PSPWizard.vue | 71 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/components/PSPWizard.vue b/components/PSPWizard.vue index 8702c27..9e9c93f 100644 --- a/components/PSPWizard.vue +++ b/components/PSPWizard.vue @@ -84,6 +84,7 @@ export default { } **/], simID: this.$route.query.simID, type: this.$route.query.type, + popUp: null, customCommandName: "", customCommandContent: "", customListenerName: "", @@ -528,8 +529,13 @@ export default { } }, async addCustomEvent() { + let trimmedName = this.customPredicateName.trim() // Add the custom event to the list if it is not empty - if (this.customPredicateName.trim() !== "") { + if (trimmedName !== "") { + if (this.eventNameExists(trimmedName)) { + await this.failureMessage("Failure", "Name " + trimmedName + " already exists. Please choose another name.") + return + } /** this.events.push({ eventName: this.customPredicateName + "(" + this.customMeasurementSource + ")", @@ -564,11 +570,18 @@ export default { this.customPredicateLogic = ""; this.customPredicateComparisonValue = ""; this.customMeasurementSource = ""; + + await this.successMessage("Added Event", "The event " + body.customPredicateName + " has been added successfully") } }, async addCustomCommand() { + let trimmedName = this.customCommandName.trim() // Add the custom command to the list if it is not empty - if (this.customCommandName.trim() !== "") { + if (trimmedName !== "") { + if (this.commandNameExists(trimmedName) || this.listenerNameExists(trimmedName)) { + await this.failureMessage("Failure", "Name " + trimmedName + " already exists. Please choose another name.") + return + } // write the event to the mongodb database const body = { @@ -587,11 +600,43 @@ export default { // clear the input fields after adding the custom event this.customCommandName = ""; this.customCommandContent = ""; + + await this.successMessage("Added Command", "The command " + body.command_name + " has been added successfully") } }, + listenerNameExists(name) { + for (let listener of this.state.listeners) { + if (listener.listener_name.trim() === name) { + return true + } + } + return false + }, + commandNameExists(name) { + for (let command of this.state.commands) { + if (command.command_name.trim() === name) { + return true + } + } + return false + }, + eventNameExists(name) { + for (let event of this.state.events) { + if (event.predicate_name.trim() === name) { + return true + } + } + return false + }, async addCustomListener() { // Add the custom event to the list if it is not empty - if (this.customListenerName.trim() !== "") { + let trimmedName = this.customListenerName.trim() + if (trimmedName !== "") { + if (this.commandNameExists(trimmedName) || this.listenerNameExists(trimmedName)) { + await this.failureMessage("Failure", "Name " + trimmedName + " already exists. Please choose another name.") + return + } + // write the event to the mongodb database const body = { listener_name: this.customListenerName, @@ -609,8 +654,26 @@ export default { // clear the input fields after adding the custom event this.customListenerName = ""; this.customListenerContent = ""; + + await this.successMessage("Added Listener", "The listener " + body.listener_name + " has been added successfully") } }, + async successMessage(title, description) { + this.popUp.add({ + icon: "i-heroicons-check-badge", + title: title, + color: "green", + description: description + }) + }, + async failureMessage(title, description) { + this.popUp.add({ + icon: "i-heroicons-no-symbol", + title: title, + color: "red", + description: description + }) + }, handleComparisonInputChange() { // remove non-numeric characters from the input this.customPredicateComparisonValue = this.customPredicateComparisonValue.replace(/\D/g, ''); @@ -1272,6 +1335,7 @@ export default { }, beforeMount() { this.initFields() + this.popUp = useToast() }, }; @@ -1281,7 +1345,6 @@ export default {

PSPWizard

-
From 9443c53d7baa5a8025be1631efb4adfa0647e6a0 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Thu, 23 May 2024 22:17:17 +0200 Subject: [PATCH 04/24] Move method out into composable for api calls --- components/Scenarios.vue | 5 ++--- components/composables/api.js | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 components/composables/api.js diff --git a/components/Scenarios.vue b/components/Scenarios.vue index 5f1a1e8..fa1341c 100644 --- a/components/Scenarios.vue +++ b/components/Scenarios.vue @@ -1,5 +1,6 @@ diff --git a/components/Scenario.vue b/components/Scenario.vue index 5b41d4d..418effb 100644 --- a/components/Scenario.vue +++ b/components/Scenario.vue @@ -9,6 +9,7 @@ import { verifySimulation } from "~/components/composables/api.js"; import {toRefinement, toScenarioEditor} from "~/components/composables/navigation.js"; +import {successMessage} from "~/components/composables/popup.js"; export default { name: "ScenarioList", @@ -21,7 +22,6 @@ export default { target: null, result: null, scenario: null, - popUp: null, }; }, methods: { @@ -31,30 +31,20 @@ export default { const simulationID = await initScenario(); toScenarioEditor(simulationID, this.$router); }, - async startSimulation(simulationID, scenario) { - - this.popUp.add({ - title: 'Simulation Started', - description: 'SimID: ' + scenario.simulationID - }); + async startSimulation(scenario) { + await successMessage("Simulation started", 'SimID: ' + scenario.simulationID) scenario.simState = 'running'; - - await startSimulation(simulationID); + await startSimulation(scenario.simulationID); + await successMessage("Simulation finished", 'SimID: ' + scenario.simulationID) scenario.simState = 'done'; - return 'done' }, - async startSearch(simulationID, scenario) { - - this.popUp.add({ - title: 'Search Started', - description: 'SimID: ' + scenario.simulationID - }); + async startSearch(scenario) { + await successMessage("Search started", 'SimID: ' + scenario.simulationID) scenario.mosimState = 'running'; - - await startSearch(simulationID); + await startSearch(scenario.simulationID); + await successMessage("Search finished", 'SimID: ' + scenario.simulationID) scenario.mosimState = 'done'; - return 'done' }, // Open the ScenarioEditor to edit a scenario @@ -211,8 +201,6 @@ export default { this.scenario.simState = "none" this.scenario.mosimState = "none" - this.popUp = useToast() - console.log(this.scenario) }, }; @@ -444,12 +432,12 @@ export default { + @click="startSimulation(scenario);"> Start Simulation + @click="startSearch(scenario);"> Start Search Verify Simulation diff --git a/components/Scenarios.vue b/components/Scenarios.vue index b883311..e3647c9 100644 --- a/components/Scenarios.vue +++ b/components/Scenarios.vue @@ -9,6 +9,7 @@ import { startSimulation, verifySearch, verifySimulation } from "~/components/composables/api.js"; import {toScenarioDetails, toScenarioEditor} from "~/components/composables/navigation.js"; +import {successMessage} from "~/components/composables/popup.js"; export default { name: "ScenarioList", @@ -33,7 +34,6 @@ export default { target: null, results: null, scenarios: null, - popUp: null, }; }, methods: { @@ -45,22 +45,18 @@ export default { toScenarioEditor(simulationID, this.$router) }, async startSimulation(scenario) { - this.popUp.add({ - title: 'Simulation Started', - description: 'SimID: ' + scenario.simulationID - }); + await successMessage("Simulation started", 'SimID: ' + scenario.simulationID) scenario.simState = 'running'; await startSimulation(scenario.simulationID) + await successMessage("Simulation finished", 'SimID: ' + scenario.simulationID) scenario.simState = 'done'; return 'done' }, async startSearch(scenario) { - this.popUp.add({ - title: 'Search Started', - description: 'SimID: ' + scenario.simulationID - }); + await successMessage("Search started", 'SimID: ' + scenario.simulationID) scenario.mosimState = 'running'; - await startSearch(scenario.simulationID) + await startSearch(scenario.simulationID); + await successMessage("Search finished", 'SimID: ' + scenario.simulationID) scenario.mosimState = 'done'; return 'done' }, @@ -222,8 +218,6 @@ export default { this.scenarios[i].mosimState = "none" } - this.popUp = useToast() - console.log(this.scenarios) }, }; diff --git a/components/composables/popup.js b/components/composables/popup.js new file mode 100644 index 0000000..960de1b --- /dev/null +++ b/components/composables/popup.js @@ -0,0 +1,19 @@ +const popUp = useToast() + +export async function successMessage(title, description) { + popUp.add({ + icon: "i-heroicons-check-badge", + title: title, + color: "green", + description: description + }) +} + +export async function failureMessage(title, description) { + popUp.add({ + icon: "i-heroicons-no-symbol", + title: title, + color: "red", + description: description + }) +} \ No newline at end of file From 6fa112fea2350ffd887843cc93cc84e1cfed8518 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Mon, 27 May 2024 15:10:48 +0200 Subject: [PATCH 12/24] Adjust remaining navigation operations --- components/Scenario.vue | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/components/Scenario.vue b/components/Scenario.vue index 418effb..1914d1d 100644 --- a/components/Scenario.vue +++ b/components/Scenario.vue @@ -8,7 +8,7 @@ import { startSimulation, verifySearch, verifySimulation } from "~/components/composables/api.js"; -import {toRefinement, toScenarioEditor} from "~/components/composables/navigation.js"; +import {toRefinement, toScenarioEditor, toScenariosOverview} from "~/components/composables/navigation.js"; import {successMessage} from "~/components/composables/popup.js"; export default { @@ -25,6 +25,8 @@ export default { }; }, methods: { + toScenariosOverview, + toScenarioEditor, toRefinement, // Open the ScenarioEditor with to create a new scenario async openEditor() { @@ -47,20 +49,13 @@ export default { scenario.mosimState = 'done'; return 'done' }, - // Open the ScenarioEditor to edit a scenario - async editScenario(simID) { - this.$router.push('/scenarioEditorSite/?simID=' + simID); - }, async updateResults() { this.result = await getResult(this.simID); }, - async complete() { - this.$router.push('/scenariosSite'); - }, // Remove one scenario async removeScenario(simulationID) { await deleteScenario(simulationID) - this.$router.push('/scenariosSite'); + toScenariosOverview(this.$router) }, async verifyScenario(scenario) { await verifySimulation(scenario); @@ -235,7 +230,7 @@ export default {
- + @@ -544,7 +539,7 @@ export default {
- Complete + Complete
From df8b138917b197bff5b05c60d17a6e50386c5bf8 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Mon, 27 May 2024 15:20:56 +0200 Subject: [PATCH 13/24] Remove console prints --- components/PSPWizard.vue | 13 ------------- components/Scenario.vue | 2 -- components/ScenarioEditor.vue | 5 ----- components/Scenarios.vue | 2 -- server/api/allResults.ts | 2 -- server/api/allScenarios.ts | 2 -- server/api/getPSPMapping.ts | 2 -- server/api/initScenario.ts | 1 - server/api/updateScenarioPredicates.ts | 7 ------- 9 files changed, 36 deletions(-) diff --git a/components/PSPWizard.vue b/components/PSPWizard.vue index 6f8225b..565adb5 100644 --- a/components/PSPWizard.vue +++ b/components/PSPWizard.vue @@ -880,25 +880,14 @@ export default { this.forceRerender() - // Debug - console.log(responsePayload) - console.log(this.pspSpecification.mapping); - console.log('Transformation successful!'); - } catch (error) { // Handle any errors that occur during the HTTP request console.error('Error transforming to temporal logic:', error); } }, async transformToTemporalLogic() { - const payload = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.pspSpecification.selectedTargetLogic, this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit, this.state.events); - - console.log(payload) - console.log(this.pspSpecification.selectedChainedEvents) - await this.sendTransformRequest(JSON.stringify(payload)) - this.forceRerender() }, handleInputChange() { @@ -961,8 +950,6 @@ export default { const jsonData = JSON.parse(fileReader.result); this.jsonData = JSON.stringify(jsonData, null, 2); - console.log(jsonData); - // reset all fields this.resetAllFields() diff --git a/components/Scenario.vue b/components/Scenario.vue index 1914d1d..1300c53 100644 --- a/components/Scenario.vue +++ b/components/Scenario.vue @@ -195,8 +195,6 @@ export default { this.scenario.simState = "none" this.scenario.mosimState = "none" - - console.log(this.scenario) }, }; diff --git a/components/ScenarioEditor.vue b/components/ScenarioEditor.vue index 4a369ae..2bbe8b7 100644 --- a/components/ScenarioEditor.vue +++ b/components/ScenarioEditor.vue @@ -141,8 +141,6 @@ export default { }, async upload(type, fileInput) { this.loadedFiles = [] - console.log("HERE") - console.log(fileInput) for (const file of fileInput.files) { const filename = file.name if (filename.split(".").pop() === "json") { @@ -182,8 +180,6 @@ export default { const jsonData = JSON.parse(fileReader.result); this.jsonData = JSON.stringify(jsonData, null, 2); - console.log(jsonData); - // check if at least one field for a scenario is available if (jsonData.name == null && jsonData.category == null && jsonData.description == null && jsonData.stimuli == null && jsonData.environment.architecture == null && jsonData.environment.experiment == null && jsonData.environment.load == null && jsonData.responses == null) { this.importErrorMessage = "The imported scenario has no valid field. Define either one or more of the fields name, category, description, stimuli, environment and responses."; @@ -314,7 +310,6 @@ export default { }, forceRerender() { this.componentKey += 1; - console.log("Rerendering!") }, }, beforeMount() { diff --git a/components/Scenarios.vue b/components/Scenarios.vue index e3647c9..c7916f4 100644 --- a/components/Scenarios.vue +++ b/components/Scenarios.vue @@ -217,8 +217,6 @@ export default { this.scenarios[i].simState = "none" this.scenarios[i].mosimState = "none" } - - console.log(this.scenarios) }, }; diff --git a/server/api/allResults.ts b/server/api/allResults.ts index 286bbfa..c76048e 100644 --- a/server/api/allResults.ts +++ b/server/api/allResults.ts @@ -9,8 +9,6 @@ export default defineEventHandler(async (event) => { console.log("Error finding results") } - console.log(results) - return { results: results }; diff --git a/server/api/allScenarios.ts b/server/api/allScenarios.ts index 3fdba7a..7182025 100644 --- a/server/api/allScenarios.ts +++ b/server/api/allScenarios.ts @@ -11,8 +11,6 @@ export default defineEventHandler(async (event) => { console.log("Error finding scenarios") } - console.log(scenarios) - return { scenarios: scenarios }; diff --git a/server/api/getPSPMapping.ts b/server/api/getPSPMapping.ts index 83fe7b6..a497619 100644 --- a/server/api/getPSPMapping.ts +++ b/server/api/getPSPMapping.ts @@ -5,8 +5,6 @@ export default defineEventHandler(async (event) => { const config = useRuntimeConfig(event) const url = "http://"+config.public.pspDomain+":"+config.public.pspPort+"/transformPattern" - console.log(url) - const response = await fetch(url, { method: "POST", headers: { diff --git a/server/api/initScenario.ts b/server/api/initScenario.ts index f9ee25e..d4f26a4 100644 --- a/server/api/initScenario.ts +++ b/server/api/initScenario.ts @@ -9,7 +9,6 @@ export default defineEventHandler(async (event) => { category: "None", specification: {measurementSources: ["DB_WRITE_1_ResponseTimes", "DB_READ_1_ResponseTimes", "AllResponseTimes", "NL_latency"]} }); - console.log("Created Scenario with simulationID: " + simulationID) } catch (err) { console.log(err) } diff --git a/server/api/updateScenarioPredicates.ts b/server/api/updateScenarioPredicates.ts index fef0ced..35e0fc7 100644 --- a/server/api/updateScenarioPredicates.ts +++ b/server/api/updateScenarioPredicates.ts @@ -16,7 +16,6 @@ export default defineEventHandler(async (event) => { } var body = await readBody(event) - console.log(body) //body = JSON.parse(body) /* if (typeof body.simulationID === "undefined" || body.fieldName === "undefined" || body.fieldValue === "undefined") { @@ -29,10 +28,6 @@ export default defineEventHandler(async (event) => { const responseIndex = body.response_index const predicates = body.predicates - console.log(simId); - console.log(responseIndex); - console.log(predicates); - try { const scenario = await Scenario.findOne({ simulationID: simId }); @@ -50,8 +45,6 @@ export default defineEventHandler(async (event) => { responses: responses, }); - console.log(updatedScenario) - } catch (e) { console.log(e) return { From a21a497efe267929dbacea731c4a3187abc38506 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Mon, 27 May 2024 16:27:30 +0200 Subject: [PATCH 14/24] Move duplicate code to general declaration --- server/api/verifySearch.ts | 28 +--------------------------- server/api/verifySimulation.ts | 28 +--------------------------- server/utils/verifyUtils.ts | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 54 deletions(-) create mode 100644 server/utils/verifyUtils.ts diff --git a/server/api/verifySearch.ts b/server/api/verifySearch.ts index 91dcce3..0dc4df3 100644 --- a/server/api/verifySearch.ts +++ b/server/api/verifySearch.ts @@ -1,8 +1,7 @@ -import {MeasurementPoint} from "~/models/measurement-point"; -import {Predicate} from "~/models/predicate"; import {ResponseSpecification} from "~/models/response-specification"; import fs from "fs"; import {pushSearchResult} from "~/server/utils/pushSearchResult"; +import {getMeasurementPointsFromPredicates, sendVerificationRequest} from "~/server/utils/verifyUtils"; export default defineEventHandler(async (event) => { const config = useRuntimeConfig(event) @@ -57,28 +56,3 @@ export default defineEventHandler(async (event) => { results: allVerificationResults, } }) - -const getMeasurementPointsFromPredicates = (predicates: Predicate[]) => { - return predicates.map(predicate => { - const measurementPoint: MeasurementPoint = { - measurement_column: predicate.measurement_source, - measurement_name: predicate.measurement_source, - }; - return measurementPoint; - }); -} - -const sendVerificationRequest = async (responseSepcification: ResponseSpecification, TBVERIFIER_URL: string) => { - const formdata = new FormData(); - formdata.append("formula_json", JSON.stringify(responseSepcification)); - const requestOptions: RequestInit = { - method: 'POST', - body: formdata, - redirect: 'follow', - }; - const response = await fetch(TBVERIFIER_URL, requestOptions); - - // Result - const verificationResult = await response.json(); - return verificationResult.result === 'True'; -} diff --git a/server/api/verifySimulation.ts b/server/api/verifySimulation.ts index aacbe63..f7c9966 100644 --- a/server/api/verifySimulation.ts +++ b/server/api/verifySimulation.ts @@ -1,7 +1,6 @@ -import {MeasurementPoint} from "~/models/measurement-point"; -import {Predicate} from "~/models/predicate"; import {ResponseSpecification} from "~/models/response-specification"; import {pushSimulationResult} from "~/server/utils/pushSimulationResult"; +import {getMeasurementPointsFromPredicates, sendVerificationRequest} from "~/server/utils/verifyUtils"; export default defineEventHandler(async (event) => { const config = useRuntimeConfig(event) @@ -41,28 +40,3 @@ export default defineEventHandler(async (event) => { result: responseVerificationResults, } }) - -const getMeasurementPointsFromPredicates = (predicates: Predicate[]) => { - return predicates.map(predicate => { - const measurementPoint: MeasurementPoint = { - measurement_column: predicate.measurement_source, - measurement_name: predicate.measurement_source, - }; - return measurementPoint; - }); -} - -const sendVerificationRequest = async (responseSepcification: ResponseSpecification, TBVERIFIER_URL: string) => { - const formdata = new FormData(); - formdata.append("formula_json", JSON.stringify(responseSepcification)); - const requestOptions: RequestInit = { - method: 'POST', - body: formdata, - redirect: 'follow', - }; - const response = await fetch(TBVERIFIER_URL, requestOptions); - - // Result - const verificationResult = await response.json(); - return verificationResult.result === 'True'; -} diff --git a/server/utils/verifyUtils.ts b/server/utils/verifyUtils.ts new file mode 100644 index 0000000..11c561f --- /dev/null +++ b/server/utils/verifyUtils.ts @@ -0,0 +1,28 @@ +import {Predicate} from "~/models/predicate"; +import {MeasurementPoint} from "~/models/measurement-point"; +import {ResponseSpecification} from "~/models/response-specification"; + +export const getMeasurementPointsFromPredicates = (predicates: Predicate[]) => { + return predicates.map(predicate => { + const measurementPoint: MeasurementPoint = { + measurement_column: predicate.measurement_source, + measurement_name: predicate.measurement_source, + }; + return measurementPoint; + }); +} + +export const sendVerificationRequest = async (responseSepcification: ResponseSpecification, TBVERIFIER_URL: string) => { + const formdata = new FormData(); + formdata.append("formula_json", JSON.stringify(responseSepcification)); + const requestOptions: RequestInit = { + method: 'POST', + body: formdata, + redirect: 'follow', + }; + const response = await fetch(TBVERIFIER_URL, requestOptions); + + // Result + const verificationResult = await response.json(); + return verificationResult.result === 'True'; +} From 490b6da87936b26e4b31227a6c47a591dc7f02e1 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Mon, 27 May 2024 16:28:43 +0200 Subject: [PATCH 15/24] Remove commented-out and unnecessary code --- components/PSPWizard.vue | 106 +++-------- components/Scenario.vue | 170 +----------------- components/ScenarioEditor.vue | 94 +--------- components/Scenarios.vue | 235 +------------------------ pages/index.vue | 7 +- server/api/changeCommand.ts | 2 +- server/api/changeEvent.ts | 4 +- server/api/changeListener.ts | 2 +- server/api/dbPing.ts | 1 - server/api/deleteCommand.ts | 2 +- server/api/deleteEvent.ts | 4 +- server/api/deleteListener.ts | 4 +- server/api/saveEvent.ts | 1 - server/api/saveScenario.ts | 1 - server/api/setScenarioField.ts | 3 - server/api/updateScenarioPredicates.ts | 104 +++++------ 16 files changed, 85 insertions(+), 655 deletions(-) diff --git a/components/PSPWizard.vue b/components/PSPWizard.vue index 565adb5..608a8e5 100644 --- a/components/PSPWizard.vue +++ b/components/PSPWizard.vue @@ -93,15 +93,7 @@ export default { timeUnit: "time units", interval: ["Interval"] }, - events: [/**{ - eventName: "Test(Test)", - predicate: { - predicate_name: "A", - predicate_logic: "biggerEqual", - predicate_comparison_value: "100", - measurement_source: "resp_time_high" - } - } **/], + events: [], simID: this.$route.query.simID, type: this.$route.query.type, customCommandName: "", @@ -260,23 +252,22 @@ export default { * @param {string} selectedScope - The selected scope type. * @param {string} selectedScopeEventQ - The selected Q event for the scope. * @param {string} selectedScopeEventR - The selected R event for the scope. - * @param {Object[]} events - An array of available events. * * @return {Object} - The created scope object. */ - createScope(selectedScope, selectedScopeEventQ, selectedScopeEventR, events) { + createScope(selectedScope, selectedScopeEventQ, selectedScopeEventR) { const scope = { type: selectedScope }; // include q_event if it exists if (selectedScopeEventQ && selectedScopeEventQ.trim() !== "") { - scope.q_event = this.createEvent(selectedScopeEventQ, events); + scope.q_event = this.createEvent(selectedScopeEventQ); } // include r_event if it exists if (selectedScopeEventR && selectedScopeEventR.trim() !== "") { - scope.r_event = this.createEvent(selectedScopeEventR, events); + scope.r_event = this.createEvent(selectedScopeEventR); } return scope; @@ -301,15 +292,15 @@ export default { }, // creates the pattern part of the payload - createPattern(selectedPatternType, selectedOccurrence, selectedOrder, selectedEventP, selectedEventS, selectedChainedEvents, selectedTime, selectedTimeUnitType, selectedInterval, selectedConstraintEvent, selectedTimeBound, selectedProbabilityBound, timeUnit, probability, upperLimit, lowerLimit, events) { + createPattern(selectedPatternType, selectedOccurrence, selectedOrder, selectedEventP, selectedEventS, selectedChainedEvents, selectedTime, selectedTimeUnitType, selectedInterval, selectedConstraintEvent, selectedTimeBound, selectedProbabilityBound, timeUnit, probability, upperLimit, lowerLimit) { const pattern = { type: selectedPatternType === 'Occurrence' ? selectedOccurrence : selectedOrder, - p_event: this.createEvent(selectedEventP, events) + p_event: this.createEvent(selectedEventP) }; // include s_event if exists if (selectedEventS && selectedEventS.trim() !== "") { - pattern.s_event = this.createEvent(selectedEventS, events) + pattern.s_event = this.createEvent(selectedEventS) } // include chained_events if one exists @@ -318,14 +309,12 @@ export default { let ch_event = { // event is required - event: this.createEvent(chainedEvent.event.name, events), - //constrain_event: createEvent(chainedEvent.constrain_event.name, events), - //time_bound: time_bound(chainedEvent) + event: this.createEvent(chainedEvent.event.name), }; // constrain_event is optional if (chainedEvent.constrain_event && chainedEvent.constrain_event.name !== "Constraint") { - ch_event.constrain_event = this.createEvent(chainedEvent.constrain_event.name, events) + ch_event.constrain_event = this.createEvent(chainedEvent.constrain_event.name) } // time_bound is optional @@ -402,7 +391,7 @@ export default { } if (selectedConstraintEvent && selectedConstraintEvent !== "Constraint") { - pattern.pattern_constrains.constrain_event = this.createEvent(selectedConstraintEvent, events) + pattern.pattern_constrains.constrain_event = this.createEvent(selectedConstraintEvent) } } @@ -410,10 +399,10 @@ export default { }, // creates the payload - createPayload(selectedScope, selectedScopeEventQ, selectedScopeEventR, selectionPatternType, selectedOccurrence, selectedOrder, selectedEventP, selectedEventS, selectedChainedEvents, selectedTime, selectedTimeUnitType, selectedInterval, selectedConstraintEvent, selectedTargetLogic, selectedTimeBound, selectedProbabilityBound, timeUnit, probability, upperLimit, lowerLimit, events) { + createPayload(selectedScope, selectedScopeEventQ, selectedScopeEventR, selectionPatternType, selectedOccurrence, selectedOrder, selectedEventP, selectedEventS, selectedChainedEvents, selectedTime, selectedTimeUnitType, selectedInterval, selectedConstraintEvent, selectedTargetLogic, selectedTimeBound, selectedProbabilityBound, timeUnit, probability, upperLimit, lowerLimit) { return { - scope: this.createScope(selectedScope, selectedScopeEventQ, selectedScopeEventR, events), - pattern: this.createPattern(selectionPatternType, selectedOccurrence, selectedOrder, selectedEventP, selectedEventS, selectedChainedEvents, selectedTime, selectedTimeUnitType, selectedInterval, selectedConstraintEvent, selectedTimeBound, selectedProbabilityBound, timeUnit, probability, upperLimit, lowerLimit, events), + scope: this.createScope(selectedScope, selectedScopeEventQ, selectedScopeEventR), + pattern: this.createPattern(selectionPatternType, selectedOccurrence, selectedOrder, selectedEventP, selectedEventS, selectedChainedEvents, selectedTime, selectedTimeUnitType, selectedInterval, selectedConstraintEvent, selectedTimeBound, selectedProbabilityBound, timeUnit, probability, upperLimit, lowerLimit), target_logic: selectedTargetLogic }; }, @@ -422,7 +411,6 @@ export default { * Creates an event object with the given name from an array of events. * * @param {string} name - The name of the event to create. - * @param {Array} events - An array of events. * * @return {Object} - An event object with the specified name and associated specification. * The event object has the following properties: @@ -430,7 +418,7 @@ export default { * - specification: An object containing the specifications of the event, * including the predicate name, logic, comparison value, and measurement source. */ - createEvent(name, events) { + createEvent(name) { if (this.type === "response") { const event = this.state.events.find(event => event.event_name === name); return { @@ -538,26 +526,15 @@ export default { await failureMessage("Failure", "Name " + trimmedName + " already exists. Please choose another name.") return } - /** - this.events.push({ - eventName: this.customPredicateName + "(" + this.customMeasurementSource + ")", - predicate: { - predicate_name: this.customPredicateName, - predicate_logic: this.customPredicateLogic, - predicate_comparison_value: this.customPredicateComparisonValue, - measurement_source: this.customMeasurementSource - } - }); - **/ - // write the event to the mongodb database + // write the event to the mongodb database const body = { - event_name: this.customPredicateName + "(" + this.customMeasurementSource + ")", - predicate_name: this.customPredicateName, - predicate_logic: this.customPredicateLogic, - predicate_comparison_value: this.customPredicateComparisonValue, - measurement_source: this.customMeasurementSource, - } + event_name: this.customPredicateName + "(" + this.customMeasurementSource + ")", + predicate_name: this.customPredicateName, + predicate_logic: this.customPredicateLogic, + predicate_comparison_value: this.customPredicateComparisonValue, + measurement_source: this.customMeasurementSource, + } await saveEvent(body) // also add this event to the local event array @@ -659,26 +636,6 @@ export default { setTimeout(this.setEventChangeFields, 200) }, async setEventChangeFields() { - /* - // get the event id from the mongodb database - const body = { - event_name: this.customPredicateName + "(" + this.customMeasurementSource + ")", - predicate_name: this.customPredicateName, - predicate_logic: this.customPredicateLogic, - predicate_comparison_value: this.customPredicateComparisonValue, - measurement_source: this.customMeasurementSource, - } - - const response = await fetch("/api/getEventByProperties", { - method: "POST", - body: JSON.stringify(body) - }) - - console.log(response); - - this.changedEventId = await response.json(); - */ - this.changedEventId = this.eventToChange._id; this.changedPredicateName = this.eventToChange.predicate_name @@ -832,10 +789,6 @@ export default { // also delete from the local array this.measurementSourceOptions.splice(deleteIndex, 1) }, - addProbability() { - // Add the custom probabilitity - this.pspSpecification.probability.push() - }, handleProbabilityChange() { // Reset probabilityBound and probability when unchecked this.pspSpecification.selectedProbabilityBound = null; @@ -886,7 +839,7 @@ export default { } }, async transformToTemporalLogic() { - const payload = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.pspSpecification.selectedTargetLogic, this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit, this.state.events); + const payload = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.pspSpecification.selectedTargetLogic, this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit); await this.sendTransformRequest(JSON.stringify(payload)) this.forceRerender() }, @@ -909,16 +862,11 @@ export default { }, addChainedEvent() { this.pspSpecification.selectedChainedEvents.push({ - event: { - //name: "", - //specification: "" - }, + event: {}, constrain_event: { name: "Constraint" - //specification: "" }, time_bound: { - //time_unit: "", type: "none", time_unit: "time units" } @@ -1147,7 +1095,7 @@ export default { // add all mappings to the commit for (index in this.targetLogicOptions) { - var payload = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.targetLogicOptions[index], this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit, this.state.events); + var payload = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.targetLogicOptions[index], this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit); // Perform the HTTP request with the input data const response = await getPSPMapping(payload); @@ -1184,7 +1132,7 @@ export default { } // add predicates to commit - const pl = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.targetLogicOptions[0], this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit, this.state.events); + const pl = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.targetLogicOptions[0], this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit); const response = await getPSPMapping(pl) const responsePayload = await response.data.value.result let eventArray = []; @@ -2795,10 +2743,6 @@ export default { font-weight: bold; } -.expand-icon { - cursor: pointer; -} - .button { background-color: #ccc; border: none; diff --git a/components/Scenario.vue b/components/Scenario.vue index 1300c53..0f59268 100644 --- a/components/Scenario.vue +++ b/components/Scenario.vue @@ -264,15 +264,8 @@ export default { Stimuli: -
  • {{ index + 1 }}. - {{ stimulus.SEL }} @@ -339,13 +332,8 @@ export default { -
  • {{ index + 1 }}. - {{ response.SEL }} @@ -524,16 +512,6 @@ export default { - -
    - -
    - -
    - - - -
  • @@ -544,35 +522,6 @@ export default { \ No newline at end of file diff --git a/server/api/changeCommand.ts b/server/api/changeCommand.ts index 713aab9..d1b11d7 100644 --- a/server/api/changeCommand.ts +++ b/server/api/changeCommand.ts @@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => { delete requestBody._id; // update the event - const updatedCommand = await Command.updateOne({_id: commandId}, requestBody); + await Command.updateOne({_id: commandId}, requestBody); } catch (e) { console.log("Error updating command:", e); diff --git a/server/api/changeEvent.ts b/server/api/changeEvent.ts index 2e2ad49..5925638 100644 --- a/server/api/changeEvent.ts +++ b/server/api/changeEvent.ts @@ -12,10 +12,10 @@ export default defineEventHandler(async (event) => { delete requestBody._id; // update the event - const updatedEvent = await Event.updateOne({ _id: eventId }, requestBody); + await Event.updateOne({_id: eventId}, requestBody); } catch (e) { console.log("Error updating event:", e); - return { "done": false }; + return {"done": false}; } }); \ No newline at end of file diff --git a/server/api/changeListener.ts b/server/api/changeListener.ts index 82d5c91..75de1ca 100644 --- a/server/api/changeListener.ts +++ b/server/api/changeListener.ts @@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => { delete requestBody._id; // update the event - const updatedListener = await Listener.updateOne({_id: listenerId}, requestBody); + await Listener.updateOne({_id: listenerId}, requestBody); } catch (e) { console.log("Error updating listener:", e); diff --git a/server/api/dbPing.ts b/server/api/dbPing.ts index dddbbcd..20956ec 100644 --- a/server/api/dbPing.ts +++ b/server/api/dbPing.ts @@ -1,4 +1,3 @@ -import { User } from "~/server/models/user.model"; import mongoose from "mongoose"; export default defineEventHandler(async (event) => { diff --git a/server/api/deleteCommand.ts b/server/api/deleteCommand.ts index 6f62459..6298559 100644 --- a/server/api/deleteCommand.ts +++ b/server/api/deleteCommand.ts @@ -10,7 +10,7 @@ export default defineEventHandler(async (event) => { const commandId = requestBody._id; // find and delete the event by its ID - const deletedCommand = await Command.deleteOne({ _id: commandId }); + await Command.deleteOne({ _id: commandId }); } catch (e) { console.log("Error deleting command:", e); diff --git a/server/api/deleteEvent.ts b/server/api/deleteEvent.ts index f80f506..91fc426 100644 --- a/server/api/deleteEvent.ts +++ b/server/api/deleteEvent.ts @@ -10,10 +10,10 @@ export default defineEventHandler(async (event) => { const eventId = requestBody._id; // find and delete the event by its ID - const deletedEvent = await Event.deleteOne({ _id: eventId }); + await Event.deleteOne({_id: eventId}); } catch (e) { console.log("Error deleting event:", e); - return { "done": false }; + return {"done": false}; } }); \ No newline at end of file diff --git a/server/api/deleteListener.ts b/server/api/deleteListener.ts index ea80226..0045fad 100644 --- a/server/api/deleteListener.ts +++ b/server/api/deleteListener.ts @@ -10,10 +10,10 @@ export default defineEventHandler(async (event) => { const listenerId = requestBody._id; // find and delete the event by its ID - const deletedListener = await Listener.deleteOne({ _id: listenerId }); + await Listener.deleteOne({_id: listenerId}); } catch (e) { console.log("Error deleting event:", e); - return { "done": false }; + return {"done": false}; } }); \ No newline at end of file diff --git a/server/api/saveEvent.ts b/server/api/saveEvent.ts index 0544d2e..2e2b7de 100644 --- a/server/api/saveEvent.ts +++ b/server/api/saveEvent.ts @@ -1,6 +1,5 @@ import {Event} from "~/server/models/event.model"; import * as crypto from "crypto"; -import {User} from "~/server/models/user.model"; export default defineEventHandler(async (event) => { diff --git a/server/api/saveScenario.ts b/server/api/saveScenario.ts index 67f4f5b..168898a 100644 --- a/server/api/saveScenario.ts +++ b/server/api/saveScenario.ts @@ -1,6 +1,5 @@ import {Scenario} from "~/server/models/scenario.model"; import * as crypto from "crypto"; -import {User} from "~/server/models/user.model"; export default defineEventHandler(async (event) => { diff --git a/server/api/setScenarioField.ts b/server/api/setScenarioField.ts index 97caccb..002e22c 100644 --- a/server/api/setScenarioField.ts +++ b/server/api/setScenarioField.ts @@ -1,6 +1,3 @@ -import crypto from "crypto"; -import {Event} from "~/server/models/event.model"; - export default defineEventHandler(async (event) => { var body = await readBody(event) body = JSON.parse(body) diff --git a/server/api/updateScenarioPredicates.ts b/server/api/updateScenarioPredicates.ts index 35e0fc7..7e6d10f 100644 --- a/server/api/updateScenarioPredicates.ts +++ b/server/api/updateScenarioPredicates.ts @@ -1,59 +1,49 @@ -import crypto from "crypto"; -import { Event } from "~/server/models/event.model"; - export default defineEventHandler(async (event) => { - setResponseHeaders(event, { - "Access-Control-Allow-Methods": "GET,HEAD,PUT,PATCH,POST,DELETE", - "Access-Control-Allow-Origin": "*", - 'Access-Control-Allow-Credentials': 'true', - "Access-Control-Allow-Headers": '*', - "Access-Control-Expose-Headers": '*' - }); - if (event.method === 'OPTIONS') { - event.node.res.statusCode = 204 - event.node.res.statusMessage = "No Content." - return 'OK' - } - - var body = await readBody(event) - //body = JSON.parse(body) - - /* if (typeof body.simulationID === "undefined" || body.fieldName === "undefined" || body.fieldValue === "undefined") { - return { - "success": false, - } - } */ - - const simId = body.sim_id; - const responseIndex = body.response_index - const predicates = body.predicates - - try { - const scenario = await Scenario.findOne({ simulationID: simId }); - - if (!scenario) { - return { - success: false, - message: "Scenario not found", - }; - } - - const responses = scenario.responses; - responses[responseIndex].predicates_info = predicates; - - const updatedScenario = await Scenario.updateOne({ simulationID: simId }, { - responses: responses, - }); - - } catch (e) { - console.log(e) - return { - "success": false, - "message": "Error updating the entry" - }; - } - - return { - "success": true, - }; + setResponseHeaders(event, { + "Access-Control-Allow-Methods": "GET,HEAD,PUT,PATCH,POST,DELETE", + "Access-Control-Allow-Origin": "*", + 'Access-Control-Allow-Credentials': 'true', + "Access-Control-Allow-Headers": '*', + "Access-Control-Expose-Headers": '*' + }); + if (event.method === 'OPTIONS') { + event.node.res.statusCode = 204 + event.node.res.statusMessage = "No Content." + return 'OK' + } + + var body = await readBody(event) + + const simId = body.sim_id; + const responseIndex = body.response_index + const predicates = body.predicates + + try { + const scenario = await Scenario.findOne({simulationID: simId}); + + if (!scenario) { + return { + success: false, + message: "Scenario not found", + }; + } + + const responses = scenario.responses; + responses[responseIndex].predicates_info = predicates; + + await Scenario.updateOne({simulationID: simId}, { + responses: responses, + }); + + } catch (e) { + console.log(e) + return { + "success": false, + "message": "Error updating the entry" + }; + } + + return { + "success": true, + }; }) \ No newline at end of file From f52c0ef253d68845c96fa3684398d9e751e04f1b Mon Sep 17 00:00:00 2001 From: franksn90 Date: Mon, 27 May 2024 16:44:53 +0200 Subject: [PATCH 16/24] Update minor style violations --- components/PSPWizard.vue | 4 ++-- server/api/allEvents.ts | 1 - server/api/allScenarios.ts | 1 - server/api/dbPing.ts | 2 +- server/api/deleteScenario.ts | 2 +- server/api/getResult.ts | 2 +- server/api/getScenario.ts | 2 +- server/api/saveEvent.ts | 3 +-- server/api/saveScenario.ts | 3 +-- server/api/setScenarioField.ts | 2 +- server/api/updateScenarioPredicates.ts | 2 +- 11 files changed, 10 insertions(+), 14 deletions(-) diff --git a/components/PSPWizard.vue b/components/PSPWizard.vue index 608a8e5..a40d08d 100644 --- a/components/PSPWizard.vue +++ b/components/PSPWizard.vue @@ -1095,7 +1095,7 @@ export default { // add all mappings to the commit for (index in this.targetLogicOptions) { - var payload = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.targetLogicOptions[index], this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit); + const payload = this.createPayload(this.pspSpecification.selectedScope, this.pspSpecification.selectedScopeEventQ, this.pspSpecification.selectedScopeEventR, this.pspSpecification.selectedPatternType, this.pspSpecification.selectedOccurrence, this.pspSpecification.selectedOrder, this.pspSpecification.selectedEventP, this.pspSpecification.selectedEventS, this.pspSpecification.selectedChainedEvents, this.pspSpecification.selectedTime, this.pspSpecification.selectedTimeUnitType, this.pspSpecification.selectedInterval, this.pspSpecification.selectedConstraintEvent, this.targetLogicOptions[index], this.pspSpecification.selectedTimeBound, this.pspSpecification.selectedProbabilityBound, this.pspSpecification.timeUnit, this.pspSpecification.probability, this.pspSpecification.upperLimit, this.pspSpecification.lowerLimit); // Perform the HTTP request with the input data const response = await getPSPMapping(payload); @@ -1148,7 +1148,7 @@ export default { }); responseObject.predicates_info = eventArray; - var type + let type; switch (this.type) { case 'response': type = "responses" diff --git a/server/api/allEvents.ts b/server/api/allEvents.ts index dcd0e4d..7b319ca 100644 --- a/server/api/allEvents.ts +++ b/server/api/allEvents.ts @@ -1,5 +1,4 @@ import {Event} from "~/server/models/event.model"; -import * as crypto from "crypto"; export default defineEventHandler(async (event) => { diff --git a/server/api/allScenarios.ts b/server/api/allScenarios.ts index 7182025..1cc0ff4 100644 --- a/server/api/allScenarios.ts +++ b/server/api/allScenarios.ts @@ -1,5 +1,4 @@ import {Scenario} from "~/server/models/scenario.model"; -import * as crypto from "crypto"; export default defineEventHandler(async (event) => { diff --git a/server/api/dbPing.ts b/server/api/dbPing.ts index 20956ec..3840f05 100644 --- a/server/api/dbPing.ts +++ b/server/api/dbPing.ts @@ -37,7 +37,7 @@ export default defineEventHandler(async (event) => { } try { // @ts-ignore - const response = await fetch(endpointStatus[endpoint].domain, { method: 'POST' }); + await fetch(endpointStatus[endpoint].domain, { method: 'POST' }); // @ts-ignore endpointStatus[endpoint].status = "green" } catch (error) {} diff --git a/server/api/deleteScenario.ts b/server/api/deleteScenario.ts index 0c2b8a9..77a524f 100644 --- a/server/api/deleteScenario.ts +++ b/server/api/deleteScenario.ts @@ -2,7 +2,7 @@ import {Scenario} from "~/server/models/scenario.model"; export default defineEventHandler(async (event) => { // Read the request body - var body = await readBody(event) + let body = await readBody(event); body = JSON.parse(body) if (typeof body.simulationID === "undefined") { diff --git a/server/api/getResult.ts b/server/api/getResult.ts index 9825c50..ec14309 100644 --- a/server/api/getResult.ts +++ b/server/api/getResult.ts @@ -1,6 +1,6 @@ export default defineEventHandler(async (event) => { - var body = await readBody(event) + let body = await readBody(event); body = JSON.parse(body) if (typeof body.simulationID === "undefined") { diff --git a/server/api/getScenario.ts b/server/api/getScenario.ts index 699d73d..18d7f03 100644 --- a/server/api/getScenario.ts +++ b/server/api/getScenario.ts @@ -1,6 +1,6 @@ export default defineEventHandler(async (event) => { - var body = await readBody(event) + let body = await readBody(event); body = JSON.parse(body) if (typeof body.simulationID === "undefined") { diff --git a/server/api/saveEvent.ts b/server/api/saveEvent.ts index 2e2b7de..f2bf8d0 100644 --- a/server/api/saveEvent.ts +++ b/server/api/saveEvent.ts @@ -2,8 +2,7 @@ import {Event} from "~/server/models/event.model"; import * as crypto from "crypto"; export default defineEventHandler(async (event) => { - - var body = await readBody(event) + let body = await readBody(event); body = JSON.parse(body) body["_id"] = crypto.randomUUID() diff --git a/server/api/saveScenario.ts b/server/api/saveScenario.ts index 168898a..c80eef3 100644 --- a/server/api/saveScenario.ts +++ b/server/api/saveScenario.ts @@ -2,8 +2,7 @@ import {Scenario} from "~/server/models/scenario.model"; import * as crypto from "crypto"; export default defineEventHandler(async (event) => { - - var body = await readBody(event) + let body = await readBody(event); body = JSON.parse(body) body["simulationID"] = crypto.randomUUID() diff --git a/server/api/setScenarioField.ts b/server/api/setScenarioField.ts index 002e22c..8b27159 100644 --- a/server/api/setScenarioField.ts +++ b/server/api/setScenarioField.ts @@ -1,5 +1,5 @@ export default defineEventHandler(async (event) => { - var body = await readBody(event) + let body = await readBody(event); body = JSON.parse(body) if (typeof body.simulationID === "undefined" || body.fieldName === "undefined" || body.fieldValue === "undefined") { diff --git a/server/api/updateScenarioPredicates.ts b/server/api/updateScenarioPredicates.ts index 7e6d10f..42899ae 100644 --- a/server/api/updateScenarioPredicates.ts +++ b/server/api/updateScenarioPredicates.ts @@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => { return 'OK' } - var body = await readBody(event) + const body = await readBody(event); const simId = body.sim_id; const responseIndex = body.response_index From 62d76d4850a289ac3e3099dc0d30d9d0d76f8331 Mon Sep 17 00:00:00 2001 From: franksn90 Date: Mon, 27 May 2024 18:43:19 +0200 Subject: [PATCH 17/24] Move general result and scenario actions to own files --- components/Scenario.vue | 182 ++++----------------- components/ScenarioEditor.vue | 20 +-- components/Scenarios.vue | 188 +++++----------------- components/composables/resultActions.js | 77 +++++++++ components/composables/scenarioActions.js | 78 +++++++++ 5 files changed, 230 insertions(+), 315 deletions(-) create mode 100644 components/composables/resultActions.js create mode 100644 components/composables/scenarioActions.js diff --git a/components/Scenario.vue b/components/Scenario.vue index 0f59268..5ee4f56 100644 --- a/components/Scenario.vue +++ b/components/Scenario.vue @@ -1,15 +1,25 @@ @@ -364,7 +358,7 @@ const config = useRuntimeConfig()
    {{ "Transform all Target Logics to " }} - diff --git a/components/Scenarios.vue b/components/Scenarios.vue index 4d701de..d6aaf11 100644 --- a/components/Scenarios.vue +++ b/components/Scenarios.vue @@ -1,15 +1,26 @@