Skip to content

Commit

Permalink
#13 df: Make it possible to add response parameter for scenario question
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Sep 7, 2023
1 parent 1186a94 commit d261cac
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 66 deletions.
25 changes: 24 additions & 1 deletion src/components/scenariotest/ScenarioDescriptionFormatter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ import WhatIfDescriptionFiller from "./WhatIfDescriptionFiller.jsx";
import scenarioSpecs from "../../data/scenariotest-specs.json";

export default function ScenarioDescriptionFormatter(scenario) {

function replacePlaceholders(inputString) {
let result = inputString;
let expectedToReplace = scenario.expected;
let isSubstituted = false;

if(scenario.all_expected !== null) {
for (let expectedChoice of scenario.all_expected) {
if(result.includes(expectedChoice)) {
result = result.replace(new RegExp(expectedChoice, 'g'), `<span class="bold-text">${expectedToReplace}</span>`);
isSubstituted = true;
}
}
}
if (isSubstituted === false && expectedToReplace === null) {
result = result.replace(new RegExp("expected", 'g'), `<span class="bold-text">[expected]</span>`);
}

return result;
}


let presentence;
if(scenario.description_audience === null) {
let descriptionList = [];
Expand All @@ -28,6 +50,7 @@ export default function ScenarioDescriptionFormatter(scenario) {
let attachment = scenario.attachment === "" ? "" : " " + scenario.attachment;
presentence = descriptionList.join(" ") + attachment;
}
presentence = replacePlaceholders(presentence);

if(scenario.selected_mode === "What if") {
let loadVariantWithPlaceholder = scenarioSpecs.load_design.find(loadVariant => loadVariant.name === scenario.load_design?.name);
Expand All @@ -48,7 +71,7 @@ export default function ScenarioDescriptionFormatter(scenario) {
}
else if(scenario.selected_mode === "Monitoring") {
return (
<p className="description">{scenario.description}</p>
<p className="description" id="description-format" dangerouslySetInnerHTML={{ __html: presentence + '?' }}></p>
)
}
}
38 changes: 24 additions & 14 deletions src/components/scenariotest/ScenarioGenerator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ export default function ScenarioGenerator(mode, wordArray) {
let scenarioArray = [];
for (const metric of allWhatIfMetrics) {
let sentence = {
description: "",
metric: metric.metric,
expected: null,
load_design: null,
resilience_design: null,
what_if_mode: metric.what_if_mode
};
let descriptionSpeakers = replacePlaceholders(metric.speakers, words.speakers, "speakers");
let descriptionMessage = replacePlaceholders(metric.message, words.message, "message")
let descriptionAudience = replacePlaceholders(metric.audience, words.audience, "audience");
sentence.expected = getExpected(metric.expected);

let descriptionSpeakers = replacePlaceholders(metric.speakers, words.speakers, "speakers", sentence.expected);
let descriptionMessage = replacePlaceholders(metric.message, words.message, "message", sentence.expected)
let descriptionAudience = replacePlaceholders(metric.audience, words.audience, "audience", sentence.expected);

sentence.load_design = getLoadDesign(metric.load_design.load_variants);
sentence.resilience_design = getResilienceDesign(metric.resilience_design.resilience_variants);
Expand All @@ -38,8 +36,8 @@ export default function ScenarioGenerator(mode, wordArray) {
sentence.description_message = descriptionMessage;
sentence.description_audience = descriptionAudience;
sentence.attachment = metric.attachment;
sentence.description_load = replacePlaceholders(metric.load_design, words.audience, "load");
sentence.description_resilience = replacePlaceholders(metric.resilience_design, words.audience, "resilience");
sentence.description_load = replacePlaceholders(metric.load_design, words.audience, "load", sentence.expected);
sentence.description_resilience = replacePlaceholders(metric.resilience_design, words.audience, "resilience", sentence.expected);

sentence.description = SentenceBuilder(sentence, "What if");

Expand All @@ -57,15 +55,17 @@ export default function ScenarioGenerator(mode, wordArray) {
let scenarioArray = [];
for (const metric of allMonitoringMetrics) {
let sentence = {
description: "",
metric: metric.metric,
expected: null,
all_expected: metric.expected,
load_design: null,
resilience_design: null
};
let descriptionSpeakers = replacePlaceholders(metric.speakers, words.speakers, "speakers");
let descriptionMessage = replacePlaceholders(metric.message, words.message, "message")
let descriptionAudience = replacePlaceholders(metric.audience, words.audience, "audience");
sentence.expected = getExpected(metric.expected);

let descriptionSpeakers = replacePlaceholders(metric.speakers, words.speakers, "speakers", sentence.expected);
let descriptionMessage = replacePlaceholders(metric.message, words.message, "message", sentence.expected);
let descriptionAudience = replacePlaceholders(metric.audience, words.audience, "audience", sentence.expected);


if(descriptionSpeakers === null
|| descriptionMessage === null
Expand All @@ -87,6 +87,16 @@ export default function ScenarioGenerator(mode, wordArray) {
return scenarioArray;
}

const getExpected = (allExpected) => {
if(allExpected == null) {
return null;
}
else {
let randomIndex = Math.floor(Math.random() * allExpected.length);
return allExpected[randomIndex];
}
}

const getLoadDesign = (loadDesignArray) => {
let loadVariantString = loadDesignArray[Math.floor(Math.random() * loadDesignArray.length)];
let numberLoadVariant;
Expand Down
89 changes: 49 additions & 40 deletions src/components/scenariotest/ScenarioTestMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ScenarioGenerator from "./ScenarioGenerator.jsx";
import deepCopy from "./deepCopy.jsx";
import ScenarioDescriptionFormatter from "./ScenarioDescriptionFormatter.jsx";
import ScenariosToFileWriter from "./ScenariosToFileWriter.jsx";
import SentenceBuilder from "./SentenceBuilder.jsx";

export default function ScenarioTestMenu(props) {

Expand Down Expand Up @@ -160,6 +161,8 @@ export default function ScenarioTestMenu(props) {
allDefinedScenariosCopy[index].what_if_mode = null;
allDefinedScenariosCopy[index].saved_load_design = null;
allDefinedScenariosCopy[index].saved_resilience_design = null;
allDefinedScenariosCopy[index].saved_resilience_design = null;
allDefinedScenariosCopy[index].all_expected = null;

setAllDefinedScenarios(allDefinedScenariosCopy);
}
Expand Down Expand Up @@ -227,6 +230,7 @@ export default function ScenarioTestMenu(props) {
allDefinedScenariosCopy[index].what_if_mode = null;
allDefinedScenariosCopy[index].saved_load_design = null;
allDefinedScenariosCopy[index].saved_resilience_design = null;
allDefinedScenariosCopy[index].all_expected = null;

setAllDefinedScenarios(allDefinedScenariosCopy);
}
Expand All @@ -250,6 +254,7 @@ export default function ScenarioTestMenu(props) {
allDefinedScenariosCopy[index].what_if_mode = selectedScenario.what_if_mode;
allDefinedScenariosCopy[index].saved_load_design = selectedScenario.load_design;
allDefinedScenariosCopy[index].saved_resilience_design = selectedScenario.resilience_design;
allDefinedScenariosCopy[index].all_expected = selectedScenario.all_expected;

document.getElementById("search-input").value = "";

Expand Down Expand Up @@ -303,9 +308,13 @@ export default function ScenarioTestMenu(props) {

}

const handleResponseParameterChange = (responseParameter, index) => {
const handleExpectedChange = (responseParameter, index) => {
let allDefinedScenariosCopy = deepCopy(allDefinedScenarios);
allDefinedScenariosCopy[index].expected = responseParameter;
let scenario = allDefinedScenariosCopy[index];
scenario.expected = responseParameter;

scenario.description = SentenceBuilder(scenario, scenario.selected_mode);

setAllDefinedScenarios(allDefinedScenariosCopy);
}

Expand Down Expand Up @@ -425,7 +434,7 @@ export default function ScenarioTestMenu(props) {

let generatedSentences = ScenarioGenerator(mode, wordArray);

//ScenariosToFileWriter(generatedSentences);
ScenariosToFileWriter(generatedSentences);

return generatedSentences;
}
Expand Down Expand Up @@ -696,6 +705,41 @@ export default function ScenarioTestMenu(props) {
</div>
: null}


{scenario.selected_mode !== null && scenario.description !== null && scenario.expected !== null ?
<div>
<label className="label">
<h6>
Response Measure
<span className="ml-1 font-normal text-sm"
data-tooltip-id="response-measure-tooltip"
data-tooltip-place="right"
data-tooltip-content='The Load Design allows you to further design the simulated load depending on the selected stimulus. For instance, if you design a "Load Peak" stimulus, you will need to specify the final peak to be achieved and how long it takes to reach it.'>&#9432;</span>
</h6>
<Tooltip id="response-measure-tooltip" style={{maxWidth: '256px'}}/>
</label>

<div className="btn-group">
{scenario.all_expected !== null && scenario.all_expected.map((expectedParameter => {
return (
<>
<input type="radio" value={expectedParameter}
onClick={() => handleExpectedChange(expectedParameter, index)}
name={"Response Measure" + index}
data-title={expectedParameter}
className={scenario.expected === expectedParameter? "btn btn-primary" : "btn"}
data-tooltip-id={expectedParameter}
data-tooltip-content={"Value: " + expectedParameter}/>
<Tooltip
id={expectedParameter}/>
</>
)
}))}
</div>

</div>
: null}

{scenario.selected_mode === "What if" && scenario.description !== null ?
<div className="activity-container">
<label className="label">
Expand All @@ -709,8 +753,7 @@ export default function ScenarioTestMenu(props) {
<Tooltip id="response-measure-tooltip" style={{maxWidth: '256px'}}/>
</label>
<label className="label">
<span
className="label-text">Do you want to change the Load Design?</span>
<span className="label-text">Do you want to change the Load Design?</span>
</label>
<div className="btn-group">
<input type="radio" value="Yes"
Expand Down Expand Up @@ -886,40 +929,6 @@ export default function ScenarioTestMenu(props) {
: null}
</div>
: null}

{/*{scenario.selected_mode !== null && scenario.description !== null && (scenario.selected_mode === "Monitoring" || (scenario.selected_mode === "What if" && scenario.load_decision !== null && scenario.resilience_decision !== null)) ?*/}
{/* <div>*/}
{/* <label className="label">*/}
{/* <h6>*/}
{/* Response Measure*/}
{/* <span className="ml-1 font-normal text-sm"*/}
{/* data-tooltip-id="response-measure-tooltip"*/}
{/* data-tooltip-place="right"*/}
{/* data-tooltip-content='The Load Design allows you to further design the simulated load depending on the selected stimulus. For instance, if you design a "Load Peak" stimulus, you will need to specify the final peak to be achieved and how long it takes to reach it.'>&#9432;</span>*/}
{/* </h6>*/}
{/* <Tooltip id="response-measure-tooltip" style={{maxWidth: '256px'}}/>*/}
{/* </label>*/}

{/* <div className="btn-group">*/}
{/* {allMonitoringMetrics.find((metric) => metric.metric === scenario.metric).expected.map((responseParameter => {*/}
{/* return (*/}
{/* <>*/}
{/* <input type="radio" value={responseParameter.value}*/}
{/* onClick={() => handleResponseParameterChange(responseParameter, index)}*/}
{/* name={"Response Measure" + index}*/}
{/* data-title={responseParameter.value}*/}
{/* className={scenario.expected === responseParameter? "btn btn-primary" : "btn"}*/}
{/* data-tooltip-id={responseParameter.value}*/}
{/* data-tooltip-content={"Value: " + responseParameter.value + " " + responseParameter.unit}/>*/}
{/* <Tooltip*/}
{/* id={responseParameter.value}/>*/}
{/* </>*/}
{/* )*/}
{/* }))}*/}
{/* </div>*/}

{/* </div>*/}
{/* : null}*/}
<button className="btn deleting-container-button"
disabled={isDeletingContainerDisabled}
onClick={() => deleteScenario(index)}>X
Expand Down Expand Up @@ -1022,7 +1031,7 @@ export default function ScenarioTestMenu(props) {
</button>

<button onClick={addScenarioTest} className="btn" disabled={isAddingButtonDisabled()}>
Add Test
Add Scenario Test
</button>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/scenariotest/SentenceBuilder.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import scenarioSpecs from "../../data/scenariotest-specs.json";
import WhatIfDescriptionFiller from "./WhatIfDescriptionFiller.jsx";
import replacePlaceholders from "./replacePlaceholders.jsx";

export default function SentenceBuilder(sentence, mode) {

Expand Down
5 changes: 4 additions & 1 deletion src/components/scenariotest/replacePlaceholders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import indefinite from "indefinite";
import compromise from "compromise";
import scenarioSpecs from "../../data/scenariotest-specs.json";

export default function replacePlaceholders(sentencePart, words, part) {
export default function replacePlaceholders(sentencePart, words, part, expected) {

const fitsIn = (type, placeHolder) => {
if (placeHolder === "actor") {
Expand Down Expand Up @@ -177,6 +177,9 @@ export default function replacePlaceholders(sentencePart, words, part) {
}
}
}
else if(placeholder === "expected") {
return expected;
}
else if (part === "load" || part === "resilience") {
if (placeholder === "load") {
return "[load]";
Expand Down
6 changes: 4 additions & 2 deletions src/data/monitoring-metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,13 @@
"number_work_object": null
},
"audience": {
"description": "How often is the response time of [system] satisfactory/tolerable/frustrating",
"description": "How often is the response time of [system] [expected]",
"number_actor": null
},
"attachment": "",
"expected": null
"expected": [
"satisfactory", "tolerable", "frustrating"
]
},
{
"metric": "how_often_request_fail",
Expand Down
14 changes: 7 additions & 7 deletions src/data/scenariotest-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@
],
"timeSlot": [
{
"representation": "00:00 - 00:00",
"startTime": 0.00,
"endTime": 0.00
"representation": "00:00 - 23:59",
"startTime": "00:00",
"endTime": "23:59"
},
{
"representation": "08:00 - 16:00",
"startTime": 8.00,
"endTime": 16.00
"startTime": "08:00",
"endTime": "16:00"
},
{
"representation": "16:00 - 08:00",
"startTime": 16.00,
"endTime": 8.00
"startTime": "16:00",
"endTime": "8:00"
}
]
}
Expand Down

0 comments on commit d261cac

Please sign in to comment.