Skip to content

Commit

Permalink
Updating case
Browse files Browse the repository at this point in the history
  • Loading branch information
local-minimum committed Aug 8, 2018
1 parent a686363 commit 6d5bf52
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 152 deletions.
75 changes: 36 additions & 39 deletions scanomatic/ui_server_data/js/src/qc/actions.js
Expand Up @@ -5,52 +5,45 @@ import {
} from './selectors';
import type {
State, TimeSeries, PlateOfTimeSeries, QualityIndexQueue,
PlateValueArray, Phenotype, QCMarkType, QCMarksMap,
PlateValueArray, Phenotype, Mark, QCMarksMap,
} from './state';
import { getPlateGrowthData, getPhenotypeData, setCurveQCMark, setCurveQCMarkAll } from '../api';

export type Action
= {| type: 'PLATE_SET', plate: number |}
| {| type: 'PROJECT_SET', project: string |}
| {| type: 'CURVE_FOCUS', plate: number, row: number, col: number |}
| {| type: 'CURVE_QCMARK_SET', plate: number, row: number, col: number, mark: QCMarkType, phenotype: ?Phenotype |}
= {| +type: 'PLATE_SET', plate: number |}
| {| +type: 'PROJECT_SET', project: string |}
| {| +type: 'CURVE_FOCUS', plate: number, row: number, col: number |}
| {| +type: 'CURVE_QCMARK_SET', plate: number, row: number, col: number, mark: Mark, phenotype: ?Phenotype |}
| {|
type: 'PLATE_GROWTHDATA_SET',
+type: 'PLATE_GROWTHDATA_SET',
plate: number,
times: TimeSeries,
smooth: PlateOfTimeSeries,
raw: PlateOfTimeSeries,
|}
| {| type: 'QUALITYINDEX_QUEUE_SET', queue: QualityIndexQueue |}
| {| type: 'QUALITYINDEX_SET', index: number |}
| {| type: 'QUALITYINDEX_NEXT' |}
| {| type: 'QUALITYINDEX_PREVIOUS' |}
| {| type: 'PHENOTYPE_SET', phenotype: Phenotype |}
| {| +type: 'QUALITYINDEX_QUEUE_SET', queue: QualityIndexQueue |}
| {| +type: 'QUALITYINDEX_SET', index: number |}
| {| +type: 'QUALITYINDEX_NEXT' |}
| {| +type: 'QUALITYINDEX_PREVIOUS' |}
| {| +type: 'PHENOTYPE_SET', phenotype: Phenotype |}
| {|
type: 'PLATE_PHENOTYPEDATA_SET',
+type: 'PLATE_PHENOTYPEDATA_SET',
plate: number,
phenotype: Phenotype,
phenotypes: PlateValueArray,
qcmarks: QCMarksMap,
|}
| {|
type: 'CURVE_QCMARK_SET',
plate: number,
row: number,
col: number,
phenotype: ?Phenotype,
mark: QCMarkType,
|}
| {|
type: 'CURVE_QCMARK_SETDIRTY',
plate: number,
row: number,
col: number,
phenotype: ?Phenotype,
mark: QCMarkType,
+type: 'CURVE_QCMARK_SET',
+plate: number,
+row: number,
+col: number,
+phenotype: ?Phenotype,
+mark: Mark,
+dirty: bool,
|}
| {|
type: 'CURVE_QCMARK_REMOVEDIRTY',
+type: 'CURVE_QCMARK_REMOVEDIRTY',
plate: number,
row: number,
col: number,
Expand Down Expand Up @@ -134,7 +127,7 @@ export function setStoreCurveQCMark(
plate: number,
row: number,
col: number,
mark: QCMarkType,
mark: Mark,
phenotype: ?Phenotype,
) : Action {
return {
Expand All @@ -144,23 +137,25 @@ export function setStoreCurveQCMark(
plate,
col,
row,
dirty: false,
};
}

export function setStoreCurveQCMarkDirty(
plate: number,
row: number,
col: number,
mark: QCMarkType,
mark: Mark,
phenotype: ?Phenotype,
) : Action {
return {
type: 'CURVE_QCMARK_SETDIRTY',
type: 'CURVE_QCMARK_SET',
phenotype,
mark,
plate,
col,
row,
dirty: true,
};
}

Expand All @@ -181,7 +176,7 @@ export function setQCMarkNotDirty(
export type ThunkAction = (dispatch: Action => any, getState: () => State) => any;

export function updateFocusCurveQCMark(
mark: QCMarkType,
mark: Mark,
phenotype: ?Phenotype,
key: string,
) : ThunkAction {
Expand Down Expand Up @@ -219,14 +214,16 @@ export function updateFocusCurveQCMark(
} else {
previousMark = getFocusCurveQCMarkAllPhenotypes(state);
}
previousMark
.forEach((prevMark, pheno) => dispatch(setStoreCurveQCMark(
plate,
focus.row,
focus.col,
prevMark || 'OK',
pheno,
)));
if (previousMark) {
previousMark
.forEach((prevMark, pheno) => dispatch(setStoreCurveQCMark(
plate,
focus.row,
focus.col,
prevMark || 'OK',
pheno,
)));
}
return Promise.resolve();
});
};
Expand Down
56 changes: 28 additions & 28 deletions scanomatic/ui_server_data/js/src/qc/actions.spec.js
Expand Up @@ -38,10 +38,10 @@ describe('/qc/actions', () => {
'GenerationTimeWhen',
[[0]],
new Map([
['badData', [[0], [0]]],
['empty', [[1], [1]]],
['noGrowth', [[2], [2]]],
['undecidedProblem', [[3], [3]]],
['BadData', [[0], [0]]],
['Empty', [[1], [1]]],
['NoGrowth', [[2], [2]]],
['UndecidedProblem', [[3], [3]]],
]),
))
.toEqual({
Expand All @@ -50,10 +50,10 @@ describe('/qc/actions', () => {
phenotype: 'GenerationTimeWhen',
phenotypes: [[0]],
qcmarks: new Map([
['badData', [[0], [0]]],
['empty', [[1], [1]]],
['noGrowth', [[2], [2]]],
['undecidedProblem', [[3], [3]]],
['BadData', [[0], [0]]],
['Empty', [[1], [1]]],
['NoGrowth', [[2], [2]]],
['UndecidedProblem', [[3], [3]]],
]),
});
});
Expand Down Expand Up @@ -187,8 +187,8 @@ describe('/qc/actions', () => {
'GenerationTime',
[[10, 154]],
new Map([
['badData', [[0], [1]]],
['empty', null],
['BadData', [[0], [1]]],
['Empty', null],
]),
)
.build();
Expand All @@ -214,8 +214,8 @@ describe('/qc/actions', () => {
'GenerationTime',
[[10, 154]],
new Map([
['badData', [[0], [1]]],
['empty', null],
['BadData', [[0], [1]]],
['Empty', null],
]),
)
.build();
Expand Down Expand Up @@ -293,28 +293,28 @@ describe('/qc/actions', () => {
const gtData = {
phenotypes: [[0]],
qcmarks: new Map([
['badData', [[], []]],
['empty', [[0], [1]]],
['noGrowth', [[1], [0]]],
['undecidedProblem', [[1, 1], [0, 1]]],
['BadData', [[], []]],
['Empty', [[0], [1]]],
['NoGrowth', [[1], [0]]],
['UndecidedProblem', [[1, 1], [0, 1]]],
]),
};
const gtWhenData = {
phenotypes: [[5]],
qcmarks: new Map([
['badData', [[1], [1]]],
['empty', [[2], [1]]],
['noGrowth', [[1], [2]]],
['undecidedProblem', [[2, 1], [0, 1]]],
['BadData', [[1], [1]]],
['Empty', [[2], [1]]],
['NoGrowth', [[1], [2]]],
['UndecidedProblem', [[2, 1], [0, 1]]],
]),
};
const expYeildData = {
phenotypes: [[4]],
qcmarks: new Map([
['badData', [[1], [4]]],
['empty', [[2], [4]]],
['noGrowth', [[1], [4]]],
['undecidedProblem', [[2, 1], [0, 4]]],
['BadData', [[1], [4]]],
['Empty', [[2], [4]]],
['NoGrowth', [[1], [4]]],
['UndecidedProblem', [[2, 1], [0, 4]]],
]),
};
let getPhenotypeData;
Expand Down Expand Up @@ -415,10 +415,10 @@ describe('/qc/actions', () => {
const gtData = {
phenotypes: [[0]],
qcmarks: new Map([
['badData', [[], []]],
['empty', [[0], [1]]],
['noGrowth', [[1], [0]]],
['undecidedProblem', [[1, 1], [0, 1]]],
['BadData', [[], []]],
['Empty', [[0], [1]]],
['NoGrowth', [[1], [0]]],
['UndecidedProblem', [[1, 1], [0, 1]]],
]),
};
let getPhenotypeData;
Expand Down
24 changes: 12 additions & 12 deletions scanomatic/ui_server_data/js/src/qc/reducers/plate.js
@@ -1,6 +1,6 @@
// @flow
import type { Action } from '../actions';
import type { Plate as State, QCMarkType, QCMarksMap, PlateCoordinatesArray } from '../state';
import type { Plate as State, Mark, QCMarksMap, PlateCoordinatesArray } from '../state';

const initialState : State = { number: 0, qIndex: 0 };

Expand All @@ -22,8 +22,8 @@ function addMark(previous: ?PlateCoordinatesArray, row: number, col: number)
}

function removeMark(previous: ?PlateCoordinatesArray, row: number, col: number)
: ?PlateCoordinatesArray {
if (!previous) return null;
: PlateCoordinatesArray {
if (!previous) return [[], []];
const next = [[], []];
for (let i = 0; i < previous[0].length; i += 1) {
if (previous[0][i] !== row && previous[1][i] !== col) {
Expand All @@ -34,13 +34,14 @@ function removeMark(previous: ?PlateCoordinatesArray, row: number, col: number)
return next;
}

function updateQCMarks(marks: QCMarksMap, row: number, col: number, mark: QCMarkType) : QCMarksMap {
return new Map([
['noGrowth', mark === 'NoGrowth' ? addMark(marks.get('noGrowth'), row, col) : removeMark(marks.get('noGrowth'), row, col)],
['empty', mark === 'Empty' ? addMark(marks.get('empty'), row, col) : removeMark(marks.get('empty'), row, col)],
['badData', mark === 'BadData' ? addMark(marks.get('badData'), row, col) : removeMark(marks.get('badData'), row, col)],
['undecidedProblem', mark === 'UndecidedProblem' ? addMark(marks.get('undecidedProblem'), row, col) : removeMark(marks.get('undecidedProblem'), row, col)],
]);
function updateQCMarks(marks: QCMarksMap, row: number, col: number, mark: Mark) : QCMarksMap {
return new Map(['NoGrowth', 'Empty', 'BadData', 'UndecidedProblem']
.map(markType => [
markType,
mark === markType ?
addMark(marks.get(markType), row, col) :
removeMark(marks.get(markType), row, col),
]));
}

export default function plate(state: State = initialState, action: Action) {
Expand Down Expand Up @@ -72,7 +73,6 @@ export default function plate(state: State = initialState, action: Action) {
},
);
}
case 'CURVE_QCMARK_SETDIRTY':
case 'CURVE_QCMARK_SET': {
if (action.plate !== state.number) return state;
const nextQC = new Map(state.qcmarks);
Expand All @@ -97,7 +97,7 @@ export default function plate(state: State = initialState, action: Action) {
}
return Object.assign({}, state, {
qcmarks: nextQC,
dirty: action.type === 'CURVE_QCMARK_SETDIRTY' ?
dirty: action.dirty ?
(state.dirty || []).concat([[action.row, action.col]]) :
(state.dirty || [])
.filter(([row, col]) => action.row !== row || action.col !== col),
Expand Down

0 comments on commit 6d5bf52

Please sign in to comment.