-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-160: Allow dynamic sorting of Decision Tree levels
- Loading branch information
Showing
4 changed files
with
71 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,65 @@ | ||
import { arrayMove } from 'react-sortable-hoc' | ||
import client from '~/utils/client' | ||
import { errorHandler } from '~/utils/toast' | ||
|
||
export const setFields = fields => ({ | ||
type: 'POSTPROCESSING.SET_FIELDS', | ||
data: fields, | ||
}) | ||
|
||
export const onFieldsSortEnd = (fields, oldIndex, newIndex) => async dispatch => { | ||
export const onFieldsSortEnd = ( | ||
fields, | ||
thrGridIn, | ||
thrGridOut, | ||
oldIndex, | ||
newIndex | ||
) => async dispatch => { | ||
await dispatch(setFields(arrayMove(fields, oldIndex, newIndex))) | ||
|
||
const sortGrid = grid => | ||
oldIndex < newIndex | ||
? grid.map(row => | ||
arrayMove( | ||
arrayMove(row, oldIndex * 2 + 1, newIndex * 2 + 2), | ||
oldIndex * 2 + 1, | ||
newIndex * 2 + 2 | ||
) | ||
) | ||
: grid.map(row => | ||
arrayMove( | ||
arrayMove(row, oldIndex * 2 + 1, newIndex * 2 + 1), | ||
oldIndex * 2 + 2, | ||
newIndex * 2 + 2 | ||
) | ||
) | ||
|
||
const newThrGridIn = sortGrid(thrGridIn) | ||
await dispatch({ | ||
type: 'POSTPROCESSING.SET_THRESHOLD_SPLITS', | ||
grid: newThrGridIn, | ||
}) | ||
|
||
const labels = newThrGridIn[0].slice(1).map(cell => cell.value) | ||
const records = newThrGridIn | ||
.slice(1) | ||
.map(row => _.flatMap(row.slice(1), cell => cell.value)) | ||
|
||
const minIndex = oldIndex < newIndex ? oldIndex : newIndex | ||
|
||
client | ||
.post('/postprocessing/create-wt-matrix', { labels, records }) | ||
.then(response => { | ||
const sortedThrGridOut = sortGrid(thrGridOut) | ||
const fullThrGridOut = response.data.matrix | ||
|
||
dispatch({ | ||
type: 'POSTPROCESSING.SET_WT_MATRIX', | ||
grid: sortedThrGridOut.map((row, idx) => { | ||
const left = row.slice(0, minIndex * 2 + 1) | ||
const right = fullThrGridOut[idx].slice(minIndex * 2) | ||
return left.concat(right) | ||
}), | ||
}) | ||
}) | ||
.catch(errorHandler) | ||
} |
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