-
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 #35 from bcgov/feature/generate-scenarios
Generate scenarios for isolation testing.
- Loading branch information
Showing
11 changed files
with
324 additions
and
22 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
74 changes: 74 additions & 0 deletions
74
app/components/ScenariosManager/IsolationTester/IsolationTester.module.css
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
.instructionsList { | ||
list-style: none; | ||
padding: 20px; | ||
margin: 20px 0; | ||
background-color: #f4f4f9; | ||
border-radius: 8px; | ||
border: 1px solid #eaeaea; | ||
} | ||
|
||
.instructionsList li { | ||
margin-bottom: 15px; | ||
padding: 10px; | ||
background: #fff; | ||
border-radius: 6px; | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | ||
font-size: 16px; | ||
line-height: 1.5; | ||
position: relative; | ||
} | ||
|
||
.instructionsList li::before { | ||
content: counter(li); | ||
counter-increment: li; | ||
position: absolute; | ||
left: -30px; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
background: #007bff; | ||
color: white; | ||
border-radius: 50%; | ||
width: 24px; | ||
height: 24px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.instructionsList a { | ||
color: #007bff; | ||
text-decoration: none; | ||
} | ||
|
||
.instructionsList a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
.instructionsList { | ||
counter-reset: li; | ||
} | ||
|
||
.upload { | ||
margin-right: 10px; | ||
} | ||
|
||
.runButton { | ||
margin-left: 10px; | ||
} | ||
|
||
.scenarioGenerator { | ||
width: 100%; | ||
} | ||
|
||
@media (max-width: 1100px) { | ||
.scenarioGenerator { | ||
flex-wrap: wrap; | ||
} | ||
} | ||
|
||
@media (max-width: 768px) { | ||
.scenarioGenerator { | ||
flex-direction: column; | ||
width: 100%; | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
app/components/ScenariosManager/IsolationTester/IsolationTester.tsx
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { Flex, Button, message, InputNumber, Collapse } from "antd"; | ||
import { Scenario } from "@/app/types/scenario"; | ||
import { getCSVTests } from "@/app/utils/api"; | ||
import { RuleMap } from "@/app/types/rulemap"; | ||
import ScenarioFormatter from "../ScenarioFormatter"; | ||
import styles from "./IsolationTester.module.css"; | ||
import { DecisionGraphType } from "@gorules/jdm-editor"; | ||
import { valueType } from "antd/es/statistic/utils"; | ||
|
||
interface IsolationTesterProps { | ||
scenarios: Scenario[]; | ||
simulationContext?: Record<string, any>; | ||
setSimulationContext: (data: any) => void; | ||
resetTrigger: boolean; | ||
jsonFile: string; | ||
rulemap: RuleMap; | ||
ruleContent?: DecisionGraphType; | ||
ruleVersion?: string | boolean; | ||
} | ||
|
||
export default function IsolationTester({ | ||
scenarios, | ||
simulationContext, | ||
setSimulationContext, | ||
resetTrigger, | ||
jsonFile, | ||
rulemap, | ||
ruleContent, | ||
ruleVersion, | ||
}: IsolationTesterProps) { | ||
const [testScenarioCount, setTestScenarioCount] = useState<valueType | null>(10); | ||
|
||
const handleCSVTests = async () => { | ||
const ruleName = ruleVersion === "draft" ? "Draft" : ruleVersion === "inreview" ? "In Review" : "Published"; | ||
try { | ||
const csvContent = await getCSVTests(jsonFile, ruleName, ruleContent, simulationContext, testScenarioCount); | ||
message.success(`Scenario Tests: ${csvContent}`); | ||
} catch (error) { | ||
message.error("Error downloading scenarios."); | ||
console.error("Error:", error); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const editScenario = { ...simulationContext, rulemap: true }; | ||
setSimulationContext(editScenario); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [resetTrigger]); | ||
|
||
return ( | ||
<Flex gap={"small"}> | ||
<div> | ||
<Flex gap={"small"}> | ||
<ol className={styles.instructionsList}> | ||
<li> | ||
This tab allows you to test your rule by defining specific variables you would like to remain unchanged | ||
while generating possible scenarios that combine the possibilities of the other variables you leave blank. | ||
</li> | ||
<li> | ||
Define any variables you would like to remain unchanged. The more that you define, the more specific the | ||
tests will be. | ||
<Collapse | ||
items={[ | ||
{ | ||
key: "1", | ||
label: "Input Variables", | ||
children: ( | ||
<Flex gap="middle" className={styles.IsolationTester}> | ||
{simulationContext && ( | ||
<Flex gap={"small"} align="end"> | ||
<ScenarioFormatter | ||
title="Inputs" | ||
rawData={simulationContext} | ||
setRawData={(data) => setSimulationContext(data)} | ||
scenarios={scenarios} | ||
rulemap={rulemap} | ||
/> | ||
</Flex> | ||
)} | ||
</Flex> | ||
), | ||
}, | ||
]} | ||
/> | ||
</li> | ||
<li> | ||
{" "} | ||
Any undefined variables will be randomly generated based on the validation values defined in klamm for | ||
these inputs. | ||
</li> | ||
<li> | ||
Enter the maximum number of scenarios you would like to generate (there is a maximum of 1000):{" "} | ||
<InputNumber | ||
value={testScenarioCount} | ||
onChange={(value) => setTestScenarioCount(value)} | ||
changeOnBlur | ||
defaultValue={10} | ||
min={1} | ||
max={1000} | ||
/> | ||
</li> | ||
<li> | ||
Generate a CSV file with your created tests:{" "} | ||
<Button onClick={handleCSVTests} size="large" type="primary"> | ||
Generate Tests | ||
</Button> | ||
</li> | ||
</ol> | ||
</Flex> | ||
</div> | ||
</Flex> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./IsolationTester"; |
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
Oops, something went wrong.