diff --git a/lib/comparisonView.js b/lib/comparisonView.js index 9ed7765..822f0ff 100644 --- a/lib/comparisonView.js +++ b/lib/comparisonView.js @@ -9,7 +9,7 @@ import { CreateTable, buildRows } from './findPaths' import { DataSetChanger } from "./datasetChanger" import { ComparisonsChanger } from "./comparisonsChanger" import { pushToMongo } from "./pushToMongo.js" -import { increasingList, maxMergeSortSteps, expectedNumMergeSortSteps } from "./utils.js" +import { increasingList, maxMergeSortSteps, expectedNumMergeSortSteps, sleep } from "./utils.js" /* DEFINTIONS */ const DEFAULT_COMPARE = () => 1 // 1/Math.random() - 1 @@ -83,7 +83,7 @@ export default function ComparisonView({ listOfElementsForView }) { let [tableRows, setTableRows] = useState(initialTableRows) /* Convenience utils: restart + changeDataSet */ - let restart = (posList) => {//({posList, initialBinaryComparisons2, initialQuantitativeComparisons2}) => { + let restart = (posList, initialBinaryComparisons2, initialQuantitativeComparisons2) => {//({posList, initialBinaryComparisons2, initialQuantitativeComparisons2}) => { setToComparePair([posList[posList.length - 2], posList[posList.length - 1]]) setSliderValue(initialSliderValue) setBinaryComparisons(initialBinaryComparisons2 || initialBinaryComparisons) @@ -113,25 +113,31 @@ export default function ComparisonView({ listOfElementsForView }) { // restart({posList: newPosList}) } - let changeComparisons = (links, listOfElements) => { + let changeComparisons = async (links) => { let quantitativeComparisons2 = [] let binaryComparisons2 = [] - for(let link of links){ - let {source, target, distance, reasoning} = link + links.shift() + for (let link of links) { + let { source, target, distance, reasoning } = link let searchByName = (name, candidate) => candidate.name == name let testForSource = (candidate) => searchByName(source, candidate) let testForTarget = (candidate) => searchByName(target, candidate) let element1 = listOfElements.findIndex(testForSource) let element2 = listOfElements.findIndex(testForTarget) - if(element1 == -1 || element2 == -1){ + if (element1 == -1 || element2 == -1) { + console.log("link", link) + console.log(source) + console.log(target) throw new Error("Comparisons include unknown elements, please retry") } quantitativeComparisons2.push([element1, element2, distance, reasoning]) - binaryComparisons2.push([element1,element2]) + binaryComparisons2.push([element1, element2]) } // return ({quantitativeComparisons: quantitativeComparisons2, binaryComparisons: binaryComparisons2}) //restart({posList, initialBinaryComparisons2=initialBinaryComparisons, initialQuantitativeComparisons2=initialQuantitativeComparisons}) - restart(posList) + // restart(posList, binaryComparisons2, quantitativeComparisons2) + setQuantitativeComparisons(quantitativeComparisons2) + setBinaryComparisons(binaryComparisons2) } // Manipulations @@ -423,7 +429,7 @@ export default function ComparisonView({ listOfElementsForView }) { {/* Button: Change dataset */} @@ -442,17 +448,26 @@ export default function ComparisonView({ listOfElementsForView }) { {/* Show comparisons section */}