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 */}
-

Comparisons

{/* Load comparisons section */}
- + {/**/}
diff --git a/lib/comparisonsChanger.js b/lib/comparisonsChanger.js index 622f508..b778ebd 100644 --- a/lib/comparisonsChanger.js +++ b/lib/comparisonsChanger.js @@ -1,8 +1,9 @@ import React, { useState } from 'react'; export function ComparisonsChanger({handleSubmit}){ - let [value, setValue] = useState(`[ - Blah, blah`) + // let defaultText=JSON.stringify(nicelyFormatLinks(quantitativeComparisons, listOfElements), null, 4) + + let [value, setValue] = useState(``) const [displayingDoneMessage, setDisplayingDoneMessage] = useState(false) const [displayingDoneMessageTimer, setDisplayingDoneMessageTimer] = useState(null) @@ -22,9 +23,11 @@ export function ComparisonsChanger({handleSubmit}){ //console.log(typeof(newData)) //console.log(newData) handleSubmit(newData) + /* if(!newData.length || newData.length < 2){ throw Error("Not enough objects") } + */ setDisplayingDoneMessage(true) let timer = setTimeout(() => setDisplayingDoneMessage(false), 3000); setDisplayingDoneMessageTimer(timer) @@ -76,7 +79,7 @@ Your old input was: ${value}`