Skip to content
Snippets Groups Projects
Commit 215d7623 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

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

parent 40fbf9c6
No related branches found
No related tags found
No related merge requests found
Pipeline #24333 passed
...@@ -200,6 +200,9 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string } ...@@ -200,6 +200,9 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string }
const vals = [...valArr]; const vals = [...valArr];
const map = {}; const map = {};
//console.log(keys);
//console.log(vals);
while(keys.length > 0){ while(keys.length > 0){
const scores = {}; const scores = {};
const matches = {}; const matches = {};
...@@ -227,6 +230,7 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string } ...@@ -227,6 +230,7 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string }
map[chosenKey] = matches[chosenKey]; map[chosenKey] = matches[chosenKey];
keys.splice(keys.indexOf(chosenKey), 1); keys.splice(keys.indexOf(chosenKey), 1);
vals.splice(vals.indexOf(matches[chosenKey]), 1); vals.splice(vals.indexOf(matches[chosenKey]), 1);
//console.log(map);
} }
const orderedMap = {}; const orderedMap = {};
...@@ -234,6 +238,7 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string } ...@@ -234,6 +238,7 @@ const levMapStrings = (keyArr: string[], valArr: string[]): { [string]: string }
orderedMap[k] = map[k]; orderedMap[k] = map[k];
} }
//console.log(orderedMap);
return orderedMap; return orderedMap;
}; };
...@@ -587,7 +592,6 @@ export class ExperimentEditor extends React.Component<Props, State> { ...@@ -587,7 +592,6 @@ export class ExperimentEditor extends React.Component<Props, State> {
onChange={e => { onChange={e => {
const str = e.target.value; const str = e.target.value;
//Object.keys(this.props.data.contents.datasets).map(dsName
const newDs = JSON.parse(str); const newDs = JSON.parse(str);
//console.log(newDs); //console.log(newDs);
this.setContents({...this.props.data.contents, datasets: newDs}); this.setContents({...this.props.data.contents, datasets: newDs});
...@@ -628,7 +632,17 @@ export class ExperimentEditor extends React.Component<Props, State> { ...@@ -628,7 +632,17 @@ export class ExperimentEditor extends React.Component<Props, State> {
const tcDs = tcDss.pop(); const tcDs = tcDss.pop();
let setsIdx = sets.findIndex(set => set.set === tcDs.name && dbSetIsValidForTcDataset(set, tcDs)); let setsIdx = sets.findIndex(set => set.set === tcDs.name && dbSetIsValidForTcDataset(set, tcDs));
if(setsIdx === -1){ 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) if(setsIdx === -1)
return [dbProtStr, false]; return [dbProtStr, false];
......
...@@ -239,18 +239,18 @@ describe('<ExperimentEditor />', () => { ...@@ -239,18 +239,18 @@ describe('<ExperimentEditor />', () => {
//console.log('doing dataset'); //console.log('doing dataset');
wrapper.find('svg #block_training_data').simulate('click'); 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(updateFunc.callCount).to.equal(1);
expect(wrapper.props().data.contents).to.have.deep.property('datasets', { expect(wrapper.props().data.contents).to.have.deep.property('datasets', {
'testing_data': { 'testing_data': {
'database': 'iris/1', 'database': 'iris/1',
'protocol': 'Main', 'protocol': 'Main',
'set': 'training' 'set': 'testing'
}, },
'training_data': { 'training_data': {
'database': 'iris/1', 'database': 'iris/1',
'protocol': 'Main', 'protocol': 'Main',
'set': 'testing' 'set': 'training'
} }
}); });
...@@ -492,12 +492,12 @@ describe('<ExperimentEditor />', () => { ...@@ -492,12 +492,12 @@ describe('<ExperimentEditor />', () => {
'testing_data': { 'testing_data': {
'database': 'iris/1', 'database': 'iris/1',
'protocol': 'Main', 'protocol': 'Main',
'set': 'training' 'set': 'testing'
}, },
'training_data': { 'training_data': {
'database': 'iris/1', 'database': 'iris/1',
'protocol': 'Main', 'protocol': 'Main',
'set': 'testing' 'set': 'training'
} }
}, },
'globals': { 'globals': {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment