Commit 2b24b0ac authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH Committed by Flavio TARSETTI
Browse files

[js][exp] choosing a protocol now smartly maps datasets based on names, fixes #126

parent 6c4ee404
Pipeline #24699 passed with stages
in 58 minutes and 41 seconds
......@@ -200,6 +200,9 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string }
const vals = [...valArr];
const map = {};
//console.log(keys);
//console.log(vals);
while(keys.length > 0){
const scores = {};
const matches = {};
......@@ -227,6 +230,7 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string }
map[chosenKey] = matches[chosenKey];
keys.splice(keys.indexOf(chosenKey), 1);
vals.splice(vals.indexOf(matches[chosenKey]), 1);
//console.log(map);
}
const orderedMap = {};
......@@ -234,6 +238,7 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string }
orderedMap[k] = map[k];
}
//console.log(orderedMap);
return orderedMap;
};
......@@ -587,7 +592,6 @@ export class ExperimentEditor extends React.Component<Props, State> {
onChange={e => {
const str = e.target.value;
//Object.keys(this.props.data.contents.datasets).map(dsName
const newDs = JSON.parse(str);
//console.log(newDs);
this.setContents({...this.props.data.contents, datasets: newDs});
......@@ -628,7 +632,17 @@ export class ExperimentEditor extends React.Component<Props, State> {
const tcDs = tcDss.pop();
let setsIdx = sets.findIndex(set => set.set === tcDs.name && dbSetIsValidForTcDataset(set, tcDs));
if(setsIdx === -1){
setsIdx = sets.findIndex(set => dbSetIsValidForTcDataset(set, tcDs));
const validSets = sets.filter(set => dbSetIsValidForTcDataset(set, tcDs));
let bestScore = 10000;
let bestMatch = 'notfound';
for(const s of validSets){
const score = lev.get(tcDs.name, s.set);
if(score < bestScore){
bestScore = score;
bestMatch = s;
}
}
setsIdx = sets.findIndex(set => set == bestMatch);
}
if(setsIdx === -1)
return [dbProtStr, false];
......
......@@ -239,18 +239,18 @@ describe('<ExperimentEditor />', () => {
//console.log('doing dataset');
wrapper.find('svg #block_training_data').simulate('click');
wrapper.find('div.datasets select').at(0).simulate('change', { target: { value: '{"testing_data":{"database":"iris/1","protocol":"Main","set":"training"},"training_data":{"database":"iris/1","protocol":"Main","set":"testing"}}'}});
wrapper.find('div.datasets select').at(0).simulate('change', { target: { value: '{"testing_data":{"database":"iris/1","protocol":"Main","set":"testing"},"training_data":{"database":"iris/1","protocol":"Main","set":"training"}}'}});
expect(updateFunc.callCount).to.equal(1);
expect(wrapper.props().data.contents).to.have.deep.property('datasets', {
'testing_data': {
'database': 'iris/1',
'protocol': 'Main',
'set': 'training'
'set': 'testing'
},
'training_data': {
'database': 'iris/1',
'protocol': 'Main',
'set': 'testing'
'set': 'training'
}
});
......@@ -492,12 +492,12 @@ describe('<ExperimentEditor />', () => {
'testing_data': {
'database': 'iris/1',
'protocol': 'Main',
'set': 'training'
'set': 'testing'
},
'training_data': {
'database': 'iris/1',
'protocol': 'Main',
'set': 'testing'
'set': 'training'
}
},
'globals': {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment