Skip to content

Commit 57feda0

Browse files
Merge pull request #675 from dali-lab/dev
Allow user to pick model version in Play with the Model
2 parents b9bf490 + 68d5678 commit 57feda0

File tree

7 files changed

+76
-17
lines changed

7 files changed

+76
-17
lines changed

src/screens/play-with-model/component.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { Loading } from '../../components';
1111

1212
import { DATA_MODES } from '../../constants';
1313

14+
export const DEFAULT_MODEL_VERSION = 2024;
15+
1416
const PlayWithModel = (props) => {
1517
const {
1618
clearAllSelections,
@@ -32,11 +34,12 @@ const PlayWithModel = (props) => {
3234
}, [clearAllSelections]);
3335

3436
const [modelInputs, setModelInputs] = useState({
35-
cleridst1: 0,
37+
cleridst1: null,
3638
endobrev: 1,
3739
spb: 0,
3840
spotst1: 0,
3941
spotst2: 0,
42+
modelVersion: DEFAULT_MODEL_VERSION,
4043
});
4144

4245
const updateModelInputs = (updates) => {
@@ -56,6 +59,7 @@ const PlayWithModel = (props) => {
5659
modelInputs.spotst2,
5760
modelInputs.spb,
5861
modelInputs.endobrev,
62+
modelInputs.modelVersion,
5963
);
6064
};
6165

@@ -68,11 +72,12 @@ const PlayWithModel = (props) => {
6872
// sets input fields to 0 if selections not fully specified
6973
if (!selectedState || selectedSubLocation.length !== 1) {
7074
setModelInputs({
71-
cleridst1: 0,
75+
cleridst1: null,
7276
endobrev: 1,
7377
spb: 0,
7478
spotst1: 0,
7579
spotst2: 0,
80+
modelVersion: DEFAULT_MODEL_VERSION,
7681
});
7782
} else {
7883
const {
@@ -81,6 +86,7 @@ const PlayWithModel = (props) => {
8186
spbPer2Weeks,
8287
endobrev,
8388
cleridst1,
89+
modelVersion,
8490
} = predictions[0];
8591

8692
// update the state
@@ -90,6 +96,7 @@ const PlayWithModel = (props) => {
9096
spb: spbPer2Weeks,
9197
endobrev,
9298
cleridst1,
99+
modelVersion,
93100
});
94101
}
95102
}, [county, dataMode, predictions, rangerDistrict, selectedState]);
@@ -105,6 +112,7 @@ const PlayWithModel = (props) => {
105112
modelInputs={modelInputs}
106113
runModel={runModel}
107114
updateModelInputs={updateModelInputs}
115+
defaultModelVersion={DEFAULT_MODEL_VERSION}
108116
/>
109117
<PlayWithModelOutputs
110118
county={county}

src/screens/play-with-model/components/play-with-model-inputs/component.js

+38-9
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import './style.scss';
55
import trapIcon from '../../../../assets/icons/trap.png';
66
import cleridsIcon from '../../../../assets/icons/clerids.png';
77
import endobrevIcon from '../../../../assets/icons/endobrev.png';
8+
import { ChoiceInput } from '../../../../components/input-components';
89

910
const PlayWithModelInputs = (props) => {
1011
const {
1112
modelInputs,
1213
runModel,
1314
updateModelInputs,
1415
year,
16+
defaultModelVersion,
1517
} = props;
1618

1719
const createValueSetter = (fieldName) => (newValue) => {
@@ -22,7 +24,7 @@ const PlayWithModelInputs = (props) => {
2224

2325
const INPUT_INFORMATION = {
2426
SPOTST2: {
25-
text: 'Enter a number for spots in {YEAR-2} (whole year)',
27+
text: 'Enter number of spots two years ago',
2628
icon: trapIcon,
2729
iconAlt: 'number of spots icon',
2830
iconId: 'trap-icon',
@@ -31,7 +33,7 @@ const PlayWithModelInputs = (props) => {
3133
trueFalseSelection: false,
3234
},
3335
SPOTST1: {
34-
text: 'Enter a number for spots in {YEAR-1} (whole year)',
36+
text: 'Enter number of spots in previous year',
3537
icon: trapIcon,
3638
iconAlt: 'number of spots icon',
3739
iconId: 'trap-icon',
@@ -40,7 +42,7 @@ const PlayWithModelInputs = (props) => {
4042
trueFalseSelection: false,
4143
},
4244
CLERIDST1: {
43-
text: 'Enter a number for clerids per 2 weeks in Spring, {YEAR-1}',
45+
text: 'Enter number of clerids / 2 weeks / trap this spring (leave blank if unknown)',
4446
icon: cleridsIcon,
4547
iconAlt: 'number of clerids icon',
4648
iconId: 'clerids-icon',
@@ -49,7 +51,7 @@ const PlayWithModelInputs = (props) => {
4951
trueFalseSelection: false,
5052
},
5153
SPB: {
52-
text: 'Enter a number for SPB per 2 weeks in Spring, {YEAR}',
54+
text: 'Enter number of SPB / 2 weeks / trap this spring',
5355
icon: trapIcon,
5456
iconAlt: 'number of SPB icon',
5557
iconId: 'spb-icon',
@@ -58,7 +60,7 @@ const PlayWithModelInputs = (props) => {
5860
trueFalseSelection: false,
5961
},
6062
ENDOBREV: {
61-
text: 'Was endo-brevicomin used in Spring, {YEAR}?',
63+
text: 'Toggle this switch to “No” if endo-brevicomin was not used',
6264
icon: endobrevIcon,
6365
iconAlt: 'endo-brevicomin icon',
6466
iconId: 'endobrev-icon',
@@ -68,6 +70,21 @@ const PlayWithModelInputs = (props) => {
6870
},
6971
};
7072

73+
const MODEL_VERSION_INPUTS = {
74+
2018: ['SPOTST2', 'SPOTST1', 'CLERIDST1', 'SPB', 'ENDOBREV'],
75+
2024: ['SPOTST1', 'SPB', 'ENDOBREV'],
76+
};
77+
78+
const filterModelVersionInputs = (modelVersion) => {
79+
const filteredInputsInformation = Object.entries(INPUT_INFORMATION).filter((entry) => {
80+
return MODEL_VERSION_INPUTS[modelVersion || defaultModelVersion].includes(entry[0]);
81+
});
82+
83+
return Object.fromEntries(filteredInputsInformation);
84+
};
85+
86+
const inputInformation = filterModelVersionInputs(modelInputs.modelVersion);
87+
7188
const selectionInput = (isTrueFalseSelection, value, setValue) => {
7289
if (!isTrueFalseSelection) {
7390
return (
@@ -119,7 +136,7 @@ const PlayWithModelInputs = (props) => {
119136
<span className="input-description">Change numbers in any of the fields below to gauge effect on predicted risks at right</span>
120137
<span className="required-text">* required</span>
121138
</div>
122-
{Object.entries(INPUT_INFORMATION).map(([key, inputInfo]) => {
139+
{Object.entries(inputInformation).map(([key, inputInfo]) => {
123140
const {
124141
text,
125142
icon,
@@ -154,9 +171,21 @@ const PlayWithModelInputs = (props) => {
154171
);
155172
})}
156173
</div>
157-
<button className="animated-button" id="run-button" type="button" onClick={runModel}>
158-
Run
159-
</button>
174+
<div className="actions-container">
175+
<div className="pick-model-input">
176+
<span>Pick model version</span>
177+
<ChoiceInput
178+
id="modelVersion"
179+
options={[2018, 2024]}
180+
value={modelInputs.modelVersion}
181+
setValue={createValueSetter('modelVersion')}
182+
firstOptionText="Year"
183+
/>
184+
</div>
185+
<button className="animated-button" id="run-button" type="button" onClick={runModel}>
186+
Run
187+
</button>
188+
</div>
160189
</div>
161190
);
162191
};

src/screens/play-with-model/components/play-with-model-inputs/style.scss

+22
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,25 @@ span.required-text {
140140
color: #ffffff;
141141
float: right;
142142
}
143+
144+
.actions-container {
145+
display: flex;
146+
justify-content: space-between;
147+
align-items: center;
148+
149+
.selection-button {
150+
background-color: #f0f2f8;
151+
}
152+
}
153+
154+
.pick-model-input {
155+
display: flex;
156+
flex-direction: column;
157+
align-items: baseline;
158+
159+
span {
160+
font-weight: 600;
161+
line-height: 1.8;
162+
margin-bottom: 5px;
163+
}
164+
}

src/screens/play-with-model/components/play-with-model-outputs/style.scss

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
}
1010

1111
#predictions-generated-title {
12-
margin-top: 20px;
1312
font-size: 16px;
1413
font-weight: 600;
1514
color: #3c4253;

src/screens/play-with-model/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ const mapDispatchToProps = (dispatch) => {
5757
clearError: () => {
5858
dispatch(clearCustomPredictionError());
5959
},
60-
runCustomPrediction: (cleridst1, spotst1, spotst2, SPB, endobrev) => {
61-
dispatch(runCustomPrediction(cleridst1, spotst1, spotst2, SPB, endobrev));
60+
runCustomPrediction: (cleridst1, spotst1, spotst2, SPB, endobrev, modelVersion) => {
61+
dispatch(runCustomPrediction(cleridst1, spotst1, spotst2, SPB, endobrev, modelVersion));
6262
},
6363
};
6464
};

src/services/api.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,14 @@ export async function rangerDistrictAggregateByRangerDistrict(filters = {}) {
246246
* @param {Number|string|Boolean} endobrev whether or not endobrev was used
247247
* @returns {Promise<Object>} model results
248248
*/
249-
export async function runCustomPrediction(cleridst1, spotst1, spotst2, SPB, endobrev) {
249+
export async function runCustomPrediction(cleridst1, spotst1, spotst2, SPB, endobrev, modelVersion) {
250250
const params = {
251251
cleridst1,
252252
endobrev: +endobrev, // note: this casts true to 1 and false to 0 if it is a boolean
253253
SPB,
254254
spotst1,
255255
spotst2,
256+
modelVersion,
256257
};
257258

258259
const url = `${global.AUTOMATION_API_URL}/${R_MODEL_SUBROUTE}`;

src/state/actions/data.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ export function getAggregateLocationData(overrideFilter = {}) {
256256
* @param {Number} SPB num spb this year
257257
* @param {Number|Boolean} endobrev whether or not endobrev was used
258258
*/
259-
export function runCustomPrediction(cleridst1, spotst1, spotst2, SPB, endobrev) {
259+
export function runCustomPrediction(cleridst1, spotst1, spotst2, SPB, endobrev, modelVersion) {
260260
return async (dispatch) => {
261261
dispatch({ type: ActionTypes.FETCHING_CUSTOM_PREDICTION, payload: true });
262262

263263
try {
264-
const response = await api.runCustomPrediction(cleridst1, spotst1, spotst2, SPB, endobrev);
264+
const response = await api.runCustomPrediction(cleridst1, spotst1, spotst2, SPB, endobrev, modelVersion);
265265
dispatch({ type: ActionTypes.SET_CUSTOM_PREDICTION, payload: response });
266266
} catch (error) {
267267
dispatch({

0 commit comments

Comments
 (0)