From 56bab8f861d4284a288a94b89477675dedcb5f0b Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 28 Nov 2021 15:33:19 +0000 Subject: [PATCH] feat: Added expected and maximum number of comparisons --- .gitignore | 3 +++ lib/comparisonView.js | 40 +++++++++++++++++++------------- lib/utils.js | 54 ++++++++++++++++++++++++++++++++----------- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index e87ca9f..04016ed 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ # personal notes Notes.md +# hacky upload script +lib/pushToMongoManually.js + # convenience old folder pages/.old/* pages/.old diff --git a/lib/comparisonView.js b/lib/comparisonView.js index 99ecd96..0139769 100644 --- a/lib/comparisonView.js +++ b/lib/comparisonView.js @@ -11,6 +11,7 @@ import { DisplayAsMarkdown } from './displayAsMarkdown' import { CreateTableWithDistances } from './findPaths' import { TextAreaForJson } from "./textAreaForJson" import { pushToMongo } from "./pushToMongo.js" +import { maxMergeSortSteps, expectedNumMergeSortSteps } from "./utils.js" /* Helpers */ let increasingList = (n) => Array.from(Array(n).keys()) @@ -40,10 +41,6 @@ export default function ComparisonView({ listOfElementsForView }) { // State let initialListOfElements = listOfElementsForView.map((element, i) => ({ ...element, id: i })) let initialPosList = increasingList(listOfElementsForView.length) // [0,1,2,3,4] - //let listOfElements = listOfElementsForView.map((element, i) => ({...element, id: i})) - //let list = increasingList(listOfElementsForView.length) // [0,1,2,3,4] - - //let initialComparePair = [list[list.length-2], list[list.length-1]] let initialComparePair = [initialPosList[initialPosList.length - 2], initialPosList[initialPosList.length - 1]] let initialSliderValue = 1 let initialReasoning = '' @@ -54,6 +51,13 @@ export default function ComparisonView({ listOfElementsForView }) { let initialShowAdvancedOptions = false let initialShowComparisons = false let initialShowChangeDataSet = false + let initialNumSteps = 0; + let maxSteps = maxMergeSortSteps(listOfElementsForView.length) + let expectedSteps = expectedNumMergeSortSteps(listOfElementsForView.length) + + //let listOfElements = listOfElementsForView.map((element, i) => ({...element, id: i})) + //let list = increasingList(listOfElementsForView.length) // [0,1,2,3,4] + //let initialComparePair = [list[list.length-2], list[list.length-1]] const [listOfElements, setListOfElements] = useState(initialListOfElements) const [posList, setPosList] = useState(initialPosList) @@ -72,6 +76,8 @@ export default function ComparisonView({ listOfElementsForView }) { let [showAdvancedOptions, changeShowAdvanceOptions] = useState(initialShowAdvancedOptions); let [showComparisons, changeShowComparisons] = useState(initialShowComparisons); let [showChangeDataSet, changeshowChangeDataSet] = useState(initialShowChangeDataSet); + let [numSteps, increaseNumSteps] = useState(initialNumSteps); + let restart = (posList) => { setToComparePair([posList[posList.length - 2], posList[posList.length - 1]]) @@ -195,6 +201,7 @@ export default function ComparisonView({ listOfElementsForView }) { setSliderValue(1) setReasoning('') + increaseNumSteps(numSteps+1) if (successStatus) { let jsObject = nicelyFormatLinks(quantitativeComparisons, listOfElements) pushToMongo(jsObject) @@ -216,6 +223,7 @@ export default function ComparisonView({ listOfElementsForView }) {

Utility Function Extractor

+

{`${numSteps} out of ~${expectedSteps} (max ${maxSteps}) comparisons`}

@@ -237,17 +245,17 @@ export default function ComparisonView({ listOfElementsForView }) { @@ -279,8 +287,8 @@ export default function ComparisonView({ listOfElementsForView }) {