Skip to content

Commit af6069b

Browse files
author
Lucas Rebscher
committed
Clean up experiments frontend code
1 parent 4ab51bd commit af6069b

4 files changed

Lines changed: 38 additions & 44 deletions

File tree

webapp/Utils.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -242,38 +242,6 @@ const Utils = {
242242
? { ...output, ...Utils.flatten(obj[key], `${path}[${key}].`) }
243243
: { ...output, ...Utils.flatten(obj[key], `${path + key}.`) }), {});
244244
},
245-
246-
/**
247-
* Converts a value based on `type` of the netpyne metadata `field`.
248-
*
249-
* @param {*} field metadata field of netpyne.
250-
* @param {*} value value to be converted to proper type.
251-
* @returns value converted to `type`.
252-
*/
253-
convertFieldValue (field, value) {
254-
if (field == null) {
255-
return value;
256-
}
257-
258-
switch (field.type) {
259-
case 'int':
260-
return Number(value);
261-
262-
case 'float':
263-
return Number(value);
264-
265-
case 'str':
266-
return String(value);
267-
268-
case 'bool':
269-
return Boolean(value);
270-
271-
default:
272-
// .. handling of more types
273-
// list(float), dict, list(list(float)), func
274-
return value;
275-
}
276-
},
277245
};
278246

279247
export default Utils;

webapp/components/experiments/ExperimentHelper.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1-
import Utils from '../../Utils';
21
import { REAL_TYPE } from '../../constants';
32

3+
/**
4+
* Converts a value based on `type` of the netpyne metadata `field`.
5+
*
6+
* @param {*} field metadata field of netpyne.
7+
* @param {*} value value to be converted to proper type.
8+
* @returns value converted to `type`.
9+
*/
10+
export const convertFieldValue = (field, value) => {
11+
if (field == null) {
12+
return value;
13+
}
14+
15+
switch (field.type) {
16+
case REAL_TYPE.INT:
17+
return Number(value);
18+
19+
case REAL_TYPE.FLOAT:
20+
return Number(value);
21+
22+
case REAL_TYPE.STR:
23+
return String(value);
24+
25+
case REAL_TYPE.BOOL:
26+
return Boolean(value);
27+
28+
default:
29+
// .. handling of more types
30+
// list(float), dict, list(list(float)), func
31+
return value;
32+
}
33+
};
34+
435
export const isValidValue = (value, type) => {
536
if (type == null) {
637
return false;
@@ -70,7 +101,7 @@ export const validateListParameter = (parameter) => {
70101

71102
const validValue = values.every((element) => isValidValue(element, field?.type));
72103
if (validValue) {
73-
values = values.map((el) => Utils.convertFieldValue(field, el));
104+
values = values.map((el) => convertFieldValue(field, el));
74105
}
75106

76107
return {
@@ -87,7 +118,7 @@ export const validateRangeParameter = (parameter, val, key) => {
87118
return {
88119
...parameter,
89120
[`${key}Val`]: val,
90-
[key]: validValue ? Utils.convertFieldValue(parameter.field, val) : val,
121+
[key]: validValue ? convertFieldValue(parameter.field, val) : val,
91122
[`${key}error`]: !validValue,
92123
[`${key}helperText`]: validValue ? '' : getErrorText(parameter?.field?.type),
93124
};

webapp/redux/actions/experiments.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
export const GET_EXPERIMENTS = 'GET_EXPERIMENTS';
22
export const SET_EXPERIMENTS = 'SET_EXPERIMENTS';
3-
export const RESET_EXPERIMENT = 'RESET_EXPERIMENT';
43
export const CLONE_EXPERIMENT = 'CLONE_EXPERIMENT';
54
export const VIEW_EXPERIMENTS_RESULTS = 'VIEW_EXPERIMENT_RESULTS';
65
export const TRIAL_LOAD_MODEL_SPEC = 'TRIAL_LOAD_MODEL_SPEC';
76
export const OPEN_LAUNCH_DIALOG = 'OPEN_LAUNCH_DIALOG';
87
export const CLOSE_LAUNCH_DIALOG = 'CLOSE_LAUNCH_DIALOG';
98

109
/**
11-
* Resets configuration of current Experiment.
12-
* User can start now with a new Experiment.
10+
* Triggers fetching the Experiments from the backend.
1311
*/
14-
export const resetCurrentExperiment = () => ({
15-
type: RESET_EXPERIMENT,
16-
});
17-
1812
export const getExperiments = () => ({
1913
type: GET_EXPERIMENTS,
2014
});
@@ -35,6 +29,9 @@ export const viewExperimentResults = (payload) => ({
3529
payload,
3630
});
3731

32+
/**
33+
* Load the model specification of the specified trial.
34+
*/
3835
export const loadTrialModelSpec = (payload) => ({
3936
type: TRIAL_LOAD_MODEL_SPEC,
4037
payload,

webapp/redux/middleware/middleware.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ import { openBackendErrorDialog } from '../actions/errors';
2323
import { closeDrawerDialogBox } from '../actions/drawer';
2424
import Utils from '../../Utils';
2525
import { downloadJsonResponse, downloadPythonResponse } from './utils';
26-
2726
import { setWidgets, setLayout } from '../actions/layout';
2827
import * as Constants from '../../constants';
29-
import { openLaunchDialog } from '../actions/experiments';
3028

3129
let previousLayout = {
3230
edit: undefined,

0 commit comments

Comments
 (0)