-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from Cambio-Project/optional-stimuli
Optional Stimuli Feature
- Loading branch information
Showing
7 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,46 @@ | ||
import fs from 'fs'; | ||
|
||
export async function exportStimuli(formData: FormData, type: string, scenario: any) { | ||
export enum AnalysisType { | ||
Simulation, | ||
Monitoring | ||
} | ||
|
||
export async function exportStimuli(formData: FormData, type: string, scenario: any, analysisType: AnalysisType) { | ||
let fileContent = ""; | ||
for (let stimulus of scenario.stimuli!) { | ||
fileContent = fileContent + stimulus.MTL + "\n" | ||
switch (analysisType) { | ||
case AnalysisType.Simulation: | ||
fileContent = getSimulationMTLs(scenario) | ||
break; | ||
case AnalysisType.Monitoring: | ||
fileContent = getMonitoringMTLs(scenario) | ||
break; | ||
} | ||
|
||
let fileName = scenario.simulationID! | ||
await fs.promises.writeFile(fileName, fileContent); | ||
|
||
const file = await fs.promises.readFile("./" + fileName) | ||
const blob = new Blob([file], {type: 'application/octet-stream'}); | ||
formData.append(type, blob, fileName) | ||
await fs.promises.unlink(fileName); | ||
} | ||
|
||
function getSimulationMTLs(scenario: any): string { | ||
let fileContent = ""; | ||
for (let stimulus of scenario.stimuli!) { | ||
if (stimulus.simulationChecked) { | ||
fileContent = fileContent + stimulus.MTL + "\n" | ||
} | ||
} | ||
return fileContent | ||
} | ||
|
||
function getMonitoringMTLs(scenario: any): string { | ||
let fileContent = ""; | ||
for (let stimulus of scenario.stimuli!) { | ||
if (stimulus.monitoringChecked) { | ||
fileContent = fileContent + stimulus.MTL + "\n" | ||
} | ||
} | ||
return fileContent | ||
} |