2021-11-25 15:31:10 +00:00
|
|
|
/* Imports */
|
2022-01-30 15:26:05 +00:00
|
|
|
import Head from "next/head";
|
2021-11-25 15:31:10 +00:00
|
|
|
import React, { useState } from "react";
|
2022-01-30 15:26:05 +00:00
|
|
|
import { DrawGraph, removeOldSvg } from "./labeledGraph";
|
2022-01-31 21:59:14 +00:00
|
|
|
import { SubmitButton } from "./submitButton";
|
2022-01-30 15:26:05 +00:00
|
|
|
import { DisplayElement } from "./displayElement";
|
|
|
|
import { DisplayAsMarkdown } from "./displayAsMarkdown";
|
|
|
|
import { CreateTable, buildRows } from "./findPaths";
|
|
|
|
import { DataSetChanger } from "./datasetChanger";
|
|
|
|
import { ComparisonsChanger } from "./comparisonsChanger";
|
|
|
|
import { pushToMongo } from "./pushToMongo.js";
|
|
|
|
import {
|
|
|
|
increasingList,
|
|
|
|
maxMergeSortSteps,
|
|
|
|
expectedNumMergeSortSteps,
|
|
|
|
conservativeNumMergeSortSteps,
|
|
|
|
} from "./utils.js";
|
2021-11-25 15:31:10 +00:00
|
|
|
|
2021-12-07 19:40:43 +00:00
|
|
|
/* DEFINTIONS */
|
2022-05-02 22:22:56 +00:00
|
|
|
const DEFAULT_COMPARE = () => "x to y"; // 1/Math.random() - 1 // Useful for testing, cause I can make the default number change.
|
2022-01-30 15:26:05 +00:00
|
|
|
const estimatedMergeSortSteps = conservativeNumMergeSortSteps; // pander to human biases so that users complain less.
|
2021-12-07 19:40:43 +00:00
|
|
|
|
2021-12-08 11:59:17 +00:00
|
|
|
/* Misc. helpers */
|
2022-01-30 15:26:05 +00:00
|
|
|
let buildLinks = (quantitativeComparisons) =>
|
2022-01-31 22:30:26 +00:00
|
|
|
quantitativeComparisons.map(
|
|
|
|
([element1, element2, distance, reasoning, squiggleString]) => ({
|
|
|
|
source: element1,
|
|
|
|
target: element2,
|
|
|
|
distance: distance,
|
|
|
|
reasoning: reasoning,
|
|
|
|
squiggleString: squiggleString,
|
|
|
|
})
|
|
|
|
);
|
2021-11-25 15:31:10 +00:00
|
|
|
|
|
|
|
Array.prototype.containsArray = function (val) {
|
|
|
|
var hash = {};
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
|
|
|
hash[this[i]] = i;
|
|
|
|
}
|
|
|
|
return hash.hasOwnProperty(val);
|
2022-01-30 15:26:05 +00:00
|
|
|
};
|
2021-11-25 15:31:10 +00:00
|
|
|
|
|
|
|
let checkIfListIsOrdered = (arr, binaryComparisons) => {
|
2022-01-30 15:26:05 +00:00
|
|
|
let l = arr.length;
|
|
|
|
let isOrdered = true;
|
2021-11-25 15:31:10 +00:00
|
|
|
for (let i = 0; i < l - 1; i++) {
|
2022-01-30 15:26:05 +00:00
|
|
|
isOrdered =
|
|
|
|
isOrdered && binaryComparisons.containsArray([arr[i], arr[i + 1]]);
|
2021-11-25 15:31:10 +00:00
|
|
|
}
|
2022-01-30 15:26:05 +00:00
|
|
|
return isOrdered;
|
|
|
|
};
|
2021-11-25 15:31:10 +00:00
|
|
|
|
2022-01-30 15:26:05 +00:00
|
|
|
let nicelyFormatLinks = (quantitativeComparisons, listOfElements) =>
|
2022-01-31 21:59:14 +00:00
|
|
|
quantitativeComparisons.map(
|
|
|
|
([element1, element2, distance, reasoning, squiggleString]) => ({
|
|
|
|
source: listOfElements[element1].name,
|
|
|
|
target: listOfElements[element2].name,
|
|
|
|
distance: distance,
|
|
|
|
reasoning: reasoning,
|
|
|
|
squiggleString: squiggleString,
|
|
|
|
})
|
|
|
|
);
|
2021-11-25 15:31:10 +00:00
|
|
|
|
|
|
|
// Main react component
|
|
|
|
export default function ComparisonView({ listOfElementsForView }) {
|
2021-12-08 11:59:17 +00:00
|
|
|
/* State */
|
|
|
|
// initial state values
|
2022-01-30 15:26:05 +00:00
|
|
|
let initialListOfElements = listOfElementsForView.map((element, i) => ({
|
|
|
|
...element,
|
|
|
|
id: i,
|
|
|
|
}));
|
|
|
|
let initialPosList = increasingList(listOfElementsForView.length); // [0,1,2,3,4]
|
|
|
|
let initialComparePair = [
|
|
|
|
initialPosList[initialPosList.length - 2],
|
|
|
|
initialPosList[initialPosList.length - 1],
|
|
|
|
];
|
2022-05-02 22:16:14 +00:00
|
|
|
let initialInputValue = "x to y";
|
2022-01-30 15:26:05 +00:00
|
|
|
let initialReasoning = "";
|
|
|
|
let initialBinaryComparisons = [];
|
|
|
|
let initialQuantitativeComparisons = [];
|
|
|
|
let initialIsListOdered = false;
|
|
|
|
let initialOrderedList = [];
|
|
|
|
let initialShowAdvancedOptions = false;
|
|
|
|
let initialShowComparisons = false;
|
|
|
|
let initialShowLoadComparisons = false;
|
|
|
|
let initialShowChangeDataSet = false;
|
2021-11-28 15:33:19 +00:00
|
|
|
let initialNumSteps = 0;
|
2022-01-30 15:26:05 +00:00
|
|
|
let initialMaxSteps = maxMergeSortSteps(listOfElementsForView.length);
|
|
|
|
let initialExpectedSteps = estimatedMergeSortSteps(
|
|
|
|
listOfElementsForView.length
|
|
|
|
);
|
|
|
|
let initialTableRows = [];
|
|
|
|
let initialDontPushSubmitButtonAnyMore = false;
|
2021-11-25 15:31:10 +00:00
|
|
|
|
2021-12-08 11:59:17 +00:00
|
|
|
// state variables and functions
|
2022-01-30 15:26:05 +00:00
|
|
|
const [listOfElements, setListOfElements] = useState(initialListOfElements);
|
|
|
|
const [posList, setPosList] = useState(initialPosList);
|
|
|
|
const [toComparePair, setToComparePair] = useState(initialComparePair);
|
2022-01-31 21:19:22 +00:00
|
|
|
const [inputValue, setInputValue] = useState(initialInputValue);
|
2022-01-30 15:26:05 +00:00
|
|
|
const [reasoning, setReasoning] = useState(initialReasoning);
|
|
|
|
const [binaryComparisons, setBinaryComparisons] = useState(
|
|
|
|
initialBinaryComparisons
|
|
|
|
);
|
|
|
|
const [quantitativeComparisons, setQuantitativeComparisons] = useState(
|
|
|
|
initialQuantitativeComparisons
|
|
|
|
); // More expressive, but more laborious to search through. For the ordering step, I only manipulate the binaryComparisons.
|
|
|
|
|
|
|
|
const [isListOrdered, setIsListOrdered] = useState(initialIsListOdered);
|
|
|
|
const [orderedList, setOrderedList] = useState(initialOrderedList);
|
|
|
|
const [dontPushSubmitButtonAnyMore, setDontPushSubmitButtonAnyMore] =
|
|
|
|
useState(initialDontPushSubmitButtonAnyMore);
|
|
|
|
|
|
|
|
let [showAdvancedOptions, changeShowAdvanceOptions] = useState(
|
|
|
|
initialShowAdvancedOptions
|
|
|
|
);
|
|
|
|
let [showComparisons, changeShowComparisons] = useState(
|
|
|
|
initialShowComparisons
|
|
|
|
);
|
|
|
|
let [showLoadComparisons, changeShowLoadComparisons] = useState(
|
|
|
|
initialShowLoadComparisons
|
|
|
|
);
|
|
|
|
let [showChangeDataSet, changeshowChangeDataSet] = useState(
|
|
|
|
initialShowChangeDataSet
|
|
|
|
);
|
2021-12-07 19:40:43 +00:00
|
|
|
let [numSteps, changeNumSteps] = useState(initialNumSteps);
|
2022-01-30 15:26:05 +00:00
|
|
|
let [maxSteps, changeMaxSteps] = useState(initialMaxSteps);
|
|
|
|
let [expectedSteps, changeExpectedSteps] = useState(initialExpectedSteps);
|
|
|
|
let [tableRows, setTableRows] = useState(initialTableRows);
|
2021-11-25 15:31:10 +00:00
|
|
|
|
2021-12-08 11:59:17 +00:00
|
|
|
/* Convenience utils: restart + changeDataSet */
|
2022-01-30 15:26:05 +00:00
|
|
|
let restart = (
|
|
|
|
posList,
|
|
|
|
initialBinaryComparisons2,
|
|
|
|
initialQuantitativeComparisons2
|
|
|
|
) => {
|
|
|
|
//({posList, initialBinaryComparisons2, initialQuantitativeComparisons2}) => {
|
|
|
|
setToComparePair([
|
|
|
|
posList[posList.length - 2],
|
|
|
|
posList[posList.length - 1],
|
|
|
|
]);
|
2022-01-31 21:19:22 +00:00
|
|
|
setInputValue(initialInputValue);
|
2022-01-30 15:26:05 +00:00
|
|
|
setBinaryComparisons(initialBinaryComparisons2 || initialBinaryComparisons);
|
|
|
|
setQuantitativeComparisons(
|
|
|
|
initialQuantitativeComparisons2 || initialQuantitativeComparisons
|
|
|
|
);
|
|
|
|
setIsListOrdered(initialIsListOdered);
|
|
|
|
setOrderedList(initialOrderedList);
|
|
|
|
changeNumSteps(initialNumSteps);
|
|
|
|
removeOldSvg();
|
|
|
|
setTableRows(initialTableRows);
|
|
|
|
setDontPushSubmitButtonAnyMore(initialDontPushSubmitButtonAnyMore);
|
|
|
|
};
|
2021-11-25 15:31:10 +00:00
|
|
|
|
|
|
|
let changeDataSet = (listOfElementsNew) => {
|
2022-01-30 15:26:05 +00:00
|
|
|
listOfElementsNew = listOfElementsNew.map((element, i) => ({
|
|
|
|
...element,
|
|
|
|
id: i,
|
|
|
|
}));
|
|
|
|
let newPosList = increasingList(listOfElementsNew.length);
|
|
|
|
let newListLength = listOfElementsNew.length;
|
|
|
|
|
|
|
|
setListOfElements(listOfElementsNew);
|
|
|
|
setPosList(increasingList(listOfElementsNew.length));
|
|
|
|
setToComparePair([
|
|
|
|
newPosList[newPosList.length - 2],
|
|
|
|
newPosList[newPosList.length - 1],
|
|
|
|
]);
|
|
|
|
|
|
|
|
changeExpectedSteps(estimatedMergeSortSteps(newListLength));
|
|
|
|
changeMaxSteps(maxMergeSortSteps(newListLength));
|
|
|
|
|
|
|
|
restart(newPosList);
|
2022-01-28 17:50:45 +00:00
|
|
|
// restart({posList: newPosList})
|
2022-01-30 15:26:05 +00:00
|
|
|
};
|
2022-01-28 17:50:45 +00:00
|
|
|
|
2022-01-28 18:48:47 +00:00
|
|
|
let changeComparisons = async (links) => {
|
2022-01-30 15:26:05 +00:00
|
|
|
let quantitativeComparisons2 = [];
|
|
|
|
let binaryComparisons2 = [];
|
|
|
|
links.shift();
|
2022-01-28 18:48:47 +00:00
|
|
|
for (let link of links) {
|
2022-02-08 21:26:15 +00:00
|
|
|
let { source, target, distance, reasoning, squiggleString } = link;
|
2022-01-30 15:26:05 +00:00
|
|
|
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);
|
2022-01-28 18:48:47 +00:00
|
|
|
if (element1 == -1 || element2 == -1) {
|
2022-01-30 15:26:05 +00:00
|
|
|
console.log("link", link);
|
|
|
|
console.log(source);
|
|
|
|
console.log(target);
|
|
|
|
throw new Error("Comparisons include unknown elements, please retry");
|
2022-01-28 17:50:45 +00:00
|
|
|
}
|
2022-02-08 21:26:15 +00:00
|
|
|
quantitativeComparisons2.push([
|
|
|
|
element1,
|
|
|
|
element2,
|
|
|
|
distance,
|
|
|
|
reasoning,
|
|
|
|
squiggleString || distance,
|
|
|
|
]);
|
2022-01-30 15:26:05 +00:00
|
|
|
binaryComparisons2.push([element1, element2]);
|
2022-01-28 17:50:45 +00:00
|
|
|
}
|
|
|
|
// return ({quantitativeComparisons: quantitativeComparisons2, binaryComparisons: binaryComparisons2})
|
|
|
|
//restart({posList, initialBinaryComparisons2=initialBinaryComparisons, initialQuantitativeComparisons2=initialQuantitativeComparisons})
|
2022-01-28 18:48:47 +00:00
|
|
|
// restart(posList, binaryComparisons2, quantitativeComparisons2)
|
2022-01-30 15:26:05 +00:00
|
|
|
setQuantitativeComparisons(quantitativeComparisons2);
|
|
|
|
setBinaryComparisons(binaryComparisons2);
|
|
|
|
};
|
2021-11-25 15:31:10 +00:00
|
|
|
|
|
|
|
// Manipulations
|
|
|
|
let compareTwoElements = (newBinaryComparisons, element1, element2) => {
|
2022-01-30 15:26:05 +00:00
|
|
|
let element1Greater = newBinaryComparisons.containsArray([
|
|
|
|
element1,
|
|
|
|
element2,
|
|
|
|
]);
|
|
|
|
let element2Greater = newBinaryComparisons.containsArray([
|
|
|
|
element2,
|
|
|
|
element1,
|
|
|
|
]);
|
2021-11-25 15:31:10 +00:00
|
|
|
if (element1Greater || element2Greater) {
|
2022-01-30 15:26:05 +00:00
|
|
|
return element1Greater && !element2Greater;
|
2021-11-25 15:31:10 +00:00
|
|
|
} else {
|
2022-01-30 15:26:05 +00:00
|
|
|
setToComparePair([element1, element2]);
|
2021-11-25 15:31:10 +00:00
|
|
|
//console.log(`No comparison found between ${element1} and ${element2}`)
|
|
|
|
//console.log(`Comparisons:`)
|
|
|
|
//console.log(JSON.stringify(newBinaryComparisons, null, 4));
|
2022-01-30 15:26:05 +00:00
|
|
|
return "No comparison found";
|
2021-11-25 15:31:10 +00:00
|
|
|
}
|
2022-01-30 15:26:05 +00:00
|
|
|
};
|
2021-11-25 15:31:10 +00:00
|
|
|
|
|
|
|
function merge(newBinaryComparisons, left, right) {
|
|
|
|
let sortedArr = []; // the sorted elements will go here
|
|
|
|
|
|
|
|
while (left.length && right.length) {
|
|
|
|
// insert the biggest element to the sortedArr
|
2022-01-30 15:26:05 +00:00
|
|
|
let comparison = compareTwoElements(
|
|
|
|
newBinaryComparisons,
|
|
|
|
left[0],
|
|
|
|
right[0]
|
|
|
|
);
|
2021-11-25 15:31:10 +00:00
|
|
|
if (comparison == "No comparison found") {
|
2022-01-30 15:26:05 +00:00
|
|
|
return "No comparison found; unable to proceed";
|
|
|
|
} else if (comparison) {
|
|
|
|
// left[0] > right[0]
|
2021-11-25 15:31:10 +00:00
|
|
|
sortedArr.push(left.shift());
|
|
|
|
} else {
|
|
|
|
sortedArr.push(right.shift());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// use spread operator and create a new array, combining the three arrays
|
|
|
|
return [...sortedArr, ...left, ...right]; // if they don't have the same size, the remaining ones will be greater than the ones before
|
|
|
|
}
|
|
|
|
|
|
|
|
function mergeSort({ array, comparisons }) {
|
|
|
|
if (array == "No comparison found; unable to proceed") {
|
2022-01-30 15:26:05 +00:00
|
|
|
return "No comparison found; unable to proceed";
|
2021-11-25 15:31:10 +00:00
|
|
|
}
|
|
|
|
const half = array.length / 2;
|
|
|
|
|
|
|
|
// the base case is array length <=1
|
|
|
|
if (array.length <= 1) {
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
const left = array.slice(0, half); // the first half of the array
|
2022-01-30 15:26:05 +00:00
|
|
|
const right = array.slice(half, array.length); // Note that splice is destructive.
|
|
|
|
let orderedFirstHalf = mergeSort({ array: left, comparisons });
|
|
|
|
let orderedSecondHalf = mergeSort({ array: right, comparisons });
|
|
|
|
if (
|
|
|
|
orderedFirstHalf != "No comparison found; unable to proceed" &&
|
|
|
|
orderedSecondHalf != "No comparison found; unable to proceed"
|
|
|
|
) {
|
2021-11-25 15:31:10 +00:00
|
|
|
let result = merge(comparisons, orderedFirstHalf, orderedSecondHalf);
|
2022-01-30 15:26:05 +00:00
|
|
|
return result;
|
2021-11-25 15:31:10 +00:00
|
|
|
} else {
|
2022-01-30 15:26:05 +00:00
|
|
|
return "No comparison found; unable to proceed";
|
2021-11-25 15:31:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let nextStepSimple = (posList, binaryComparisons, element1, element2) => {
|
|
|
|
//console.log("Binary comparisons: ")
|
|
|
|
//console.log(JSON.stringify(binaryComparisons, null, 4));
|
|
|
|
|
2022-01-30 15:26:05 +00:00
|
|
|
let newComparison = [element1, element2]; // [element1, element2]
|
|
|
|
let newBinaryComparisons = [...binaryComparisons, newComparison];
|
2021-11-25 15:31:10 +00:00
|
|
|
//console.log("New binaryComparisons: ")
|
|
|
|
//console.log(JSON.stringify(newBinaryComparisons, null, 4));
|
2022-01-30 15:26:05 +00:00
|
|
|
setBinaryComparisons(newBinaryComparisons);
|
2021-11-25 15:31:10 +00:00
|
|
|
|
2022-01-30 15:26:05 +00:00
|
|
|
let result = mergeSort({
|
|
|
|
array: posList,
|
|
|
|
comparisons: newBinaryComparisons,
|
|
|
|
});
|
2021-11-25 15:31:10 +00:00
|
|
|
//console.log(result)
|
2022-01-30 15:26:05 +00:00
|
|
|
if (
|
|
|
|
result != "No comparison found; unable to proceed" &&
|
|
|
|
checkIfListIsOrdered(result, newBinaryComparisons)
|
|
|
|
) {
|
2021-11-25 15:31:10 +00:00
|
|
|
// console.log(`isListOrdered: ${isListOrdered}`)
|
2022-01-30 15:26:05 +00:00
|
|
|
console.log("poslist@nextStepSimple");
|
|
|
|
console.log(posList);
|
|
|
|
console.log("result@nextStepSimple");
|
|
|
|
console.log(result);
|
2021-11-25 15:31:10 +00:00
|
|
|
|
2022-01-30 15:26:05 +00:00
|
|
|
return [true, result];
|
2021-11-25 15:31:10 +00:00
|
|
|
} else {
|
2022-01-30 15:26:05 +00:00
|
|
|
return [false, result];
|
2021-11-25 15:31:10 +00:00
|
|
|
}
|
2022-01-30 15:26:05 +00:00
|
|
|
};
|
|
|
|
|
2022-01-31 21:19:22 +00:00
|
|
|
let nextStepInput = async ({
|
2022-01-30 15:26:05 +00:00
|
|
|
posList,
|
|
|
|
binaryComparisons,
|
2022-01-31 21:19:22 +00:00
|
|
|
inputValue,
|
2022-01-30 15:26:05 +00:00
|
|
|
reasoning,
|
|
|
|
element1,
|
|
|
|
element2,
|
2022-01-31 21:59:14 +00:00
|
|
|
squiggleString,
|
2022-01-30 15:26:05 +00:00
|
|
|
}) => {
|
2021-12-08 15:46:17 +00:00
|
|
|
if (!dontPushSubmitButtonAnyMore) {
|
2022-01-31 21:19:22 +00:00
|
|
|
if (inputValue < 1 && inputValue > 0) {
|
2022-02-08 22:44:59 +00:00
|
|
|
let inverse = 1 / inputValue;
|
|
|
|
if (squiggleString == inputValue) {
|
|
|
|
inputValue = inverse;
|
|
|
|
squiggleString = inverse;
|
|
|
|
} else {
|
|
|
|
inputValue = inverse;
|
|
|
|
squiggleString = `(${squiggleString})^(-1)`;
|
|
|
|
}
|
2022-01-30 15:26:05 +00:00
|
|
|
[element1, element2] = [element2, element1];
|
2021-12-08 15:46:17 +00:00
|
|
|
}
|
2022-01-31 21:19:22 +00:00
|
|
|
console.log(`posList@nextStepInput:`);
|
2022-01-30 15:26:05 +00:00
|
|
|
console.log(posList);
|
|
|
|
let [successStatus, result] = nextStepSimple(
|
|
|
|
posList,
|
|
|
|
binaryComparisons,
|
|
|
|
element1,
|
|
|
|
element2
|
|
|
|
);
|
|
|
|
|
|
|
|
let newQuantitativeComparison = [
|
|
|
|
element1,
|
|
|
|
element2,
|
2022-01-31 21:19:22 +00:00
|
|
|
inputValue,
|
2022-01-30 15:26:05 +00:00
|
|
|
reasoning,
|
2022-01-31 21:59:14 +00:00
|
|
|
squiggleString || inputValue,
|
2022-01-30 15:26:05 +00:00
|
|
|
];
|
|
|
|
let newQuantitativeComparisons = [
|
|
|
|
...quantitativeComparisons,
|
|
|
|
newQuantitativeComparison,
|
|
|
|
];
|
|
|
|
setQuantitativeComparisons(newQuantitativeComparisons);
|
|
|
|
|
2022-01-31 21:19:22 +00:00
|
|
|
setInputValue(DEFAULT_COMPARE());
|
2022-01-30 15:26:05 +00:00
|
|
|
setReasoning("");
|
|
|
|
changeNumSteps(numSteps + 1);
|
2021-12-08 15:46:17 +00:00
|
|
|
if (successStatus) {
|
2022-01-30 15:26:05 +00:00
|
|
|
setDontPushSubmitButtonAnyMore(true);
|
2021-12-08 15:46:17 +00:00
|
|
|
|
2022-01-30 15:26:05 +00:00
|
|
|
let jsObject = nicelyFormatLinks(
|
|
|
|
quantitativeComparisons,
|
|
|
|
listOfElements
|
|
|
|
);
|
|
|
|
await pushToMongo(jsObject);
|
|
|
|
console.log(jsObject);
|
2021-12-08 15:46:17 +00:00
|
|
|
|
2022-01-30 15:26:05 +00:00
|
|
|
alert(
|
|
|
|
"Comparisons completed. Background work might take a while, or straight-out fail"
|
|
|
|
);
|
|
|
|
setIsListOrdered(true);
|
|
|
|
setOrderedList(result);
|
2021-12-08 11:59:17 +00:00
|
|
|
|
|
|
|
await buildRows({
|
|
|
|
isListOrdered: true,
|
|
|
|
orderedList: result,
|
|
|
|
listOfElements,
|
|
|
|
links: buildLinks(newQuantitativeComparisons),
|
|
|
|
rows: tableRows,
|
2022-01-30 15:26:05 +00:00
|
|
|
setTableRows,
|
|
|
|
});
|
2021-12-08 15:46:17 +00:00
|
|
|
/*
|
|
|
|
setTimeout(async () => {
|
|
|
|
// Make sure to do this after the
|
2021-12-08 11:59:17 +00:00
|
|
|
|
2021-12-08 15:46:17 +00:00
|
|
|
}, 100);
|
|
|
|
*/
|
|
|
|
}
|
2021-11-25 15:31:10 +00:00
|
|
|
}
|
2022-01-30 15:26:05 +00:00
|
|
|
};
|
2021-11-25 15:31:10 +00:00
|
|
|
|
|
|
|
// Html
|
|
|
|
return (
|
|
|
|
<div className="flex flex-col items-center justify-center min-h-screen py-2">
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Webpage name & favicon */}
|
2021-11-25 15:31:10 +00:00
|
|
|
<div className="mt-20">
|
2022-01-30 15:26:05 +00:00
|
|
|
<Head>
|
2021-11-25 15:31:10 +00:00
|
|
|
<title>Utility Function Extractor</title>
|
|
|
|
<link rel="icon" href="/favicon.ico" />
|
|
|
|
</Head>
|
|
|
|
</div>
|
|
|
|
<main className="flex flex-col items-center w-full flex-1 px-20 text-center">
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Heading */}
|
2022-01-30 15:26:05 +00:00
|
|
|
<h1 className="text-6xl font-bold">Utility Function Extractor</h1>
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Approximate progress indicator */}
|
2021-12-08 15:46:17 +00:00
|
|
|
|
2021-11-28 15:33:19 +00:00
|
|
|
<p>{`${numSteps} out of ~${expectedSteps} (max ${maxSteps}) comparisons`}</p>
|
2021-11-25 15:31:10 +00:00
|
|
|
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Comparison section */}
|
2021-12-08 12:49:29 +00:00
|
|
|
<div className={isListOrdered ? "hidden" : ""}>
|
2021-11-25 15:31:10 +00:00
|
|
|
<div className="flex flex-wrap items-center max-w-4xl sm:w-full mt-10">
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Element 1 */}
|
|
|
|
<div className="flex m-auto border-gray-300 border-4 h-72 w-72 p-5">
|
2021-11-25 15:31:10 +00:00
|
|
|
<div className="block m-auto text-center">
|
2022-01-30 15:26:05 +00:00
|
|
|
<DisplayElement
|
|
|
|
element={listOfElements[toComparePair[0]]}
|
|
|
|
></DisplayElement>
|
2021-11-25 15:31:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-01-31 21:59:14 +00:00
|
|
|
{/* Comparison actuator (text, previously number) */}
|
2021-11-25 15:31:10 +00:00
|
|
|
<div className="flex m-auto w-72">
|
|
|
|
<div className="block m-auto text-center">
|
|
|
|
<br />
|
|
|
|
<label>
|
|
|
|
{`... is `}
|
|
|
|
<br />
|
2021-11-28 15:33:19 +00:00
|
|
|
<input
|
2022-01-31 21:59:14 +00:00
|
|
|
type="text"
|
2021-11-28 15:33:19 +00:00
|
|
|
className="text-center text-blueGray-600 bg-white rounded text-lg border-0 shadow outline-none focus:outline-none focus:ring w-8/12 h-10 m-2"
|
2022-01-31 21:19:22 +00:00
|
|
|
value={inputValue}
|
2021-11-28 15:33:19 +00:00
|
|
|
onChange={(event) => {
|
|
|
|
//console.log(event)
|
|
|
|
//console.log(event.target.value)
|
2022-01-31 21:19:22 +00:00
|
|
|
setInputValue(event.target.value);
|
2021-11-28 15:33:19 +00:00
|
|
|
}}
|
|
|
|
/>
|
2021-11-25 15:31:10 +00:00
|
|
|
<br />
|
|
|
|
{`times as valuable as ...`}
|
|
|
|
</label>
|
|
|
|
<br />
|
|
|
|
|
2022-01-31 21:59:14 +00:00
|
|
|
<SubmitButton
|
2021-11-25 15:31:10 +00:00
|
|
|
posList={posList}
|
|
|
|
binaryComparisons={binaryComparisons}
|
2022-01-31 21:19:22 +00:00
|
|
|
inputValue={inputValue}
|
2021-11-25 15:31:10 +00:00
|
|
|
reasoning={reasoning}
|
|
|
|
toComparePair={toComparePair}
|
2022-01-31 21:19:22 +00:00
|
|
|
nextStepInput={nextStepInput}
|
2021-12-08 15:46:17 +00:00
|
|
|
dontPushSubmitButtonAnyMore={dontPushSubmitButtonAnyMore}
|
2021-11-25 15:31:10 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-08 15:46:17 +00:00
|
|
|
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Element 2 */}
|
|
|
|
<div className="flex m-auto border-gray-300 border-4 h-72 w-72 p-5">
|
2021-11-25 15:31:10 +00:00
|
|
|
<div className="block m-auto text-center">
|
2022-01-30 15:26:05 +00:00
|
|
|
<DisplayElement
|
|
|
|
element={listOfElements[toComparePair[1]]}
|
|
|
|
></DisplayElement>
|
2021-11-25 15:31:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<br />
|
2021-11-25 15:56:48 +00:00
|
|
|
|
2021-11-25 15:31:10 +00:00
|
|
|
<label className="">
|
2022-03-07 19:15:04 +00:00
|
|
|
{"Notes and reasoning:"}
|
2022-01-30 15:26:05 +00:00
|
|
|
<textarea
|
|
|
|
className="mt-2 px-3 py-4 placeholder-blueGray-300 text-blueGray-600 relative bg-white bg-white rounded text-base border-0 shadow outline-none focus:outline-none focus:ring w-full"
|
2022-05-02 22:16:14 +00:00
|
|
|
placeholder={
|
|
|
|
numSteps == 0
|
|
|
|
? "Please write your name here if you want QURI to be able to identify your answers later"
|
|
|
|
: ""
|
|
|
|
}
|
2021-11-28 15:33:19 +00:00
|
|
|
value={reasoning}
|
|
|
|
onChange={(event) => setReasoning(event.target.value)}
|
2021-11-25 15:31:10 +00:00
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
<br />
|
|
|
|
</div>
|
|
|
|
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Results section */}
|
2022-01-28 20:09:41 +00:00
|
|
|
<div className={isListOrdered ? "" : "hidden"}>
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Graph */}
|
2022-02-08 22:44:59 +00:00
|
|
|
<div className="flex items-center text-center">
|
2022-01-30 15:26:05 +00:00
|
|
|
<DrawGraph
|
|
|
|
isListOrdered={isListOrdered}
|
|
|
|
orderedList={orderedList}
|
|
|
|
listOfElements={listOfElements}
|
|
|
|
links={buildLinks(quantitativeComparisons)}
|
|
|
|
></DrawGraph>
|
2022-01-28 20:09:41 +00:00
|
|
|
</div>
|
2021-12-08 11:59:17 +00:00
|
|
|
|
|
|
|
{/* Comparison table */}
|
2022-01-28 20:09:41 +00:00
|
|
|
<div className="flex items-center text-center ">
|
2021-12-08 11:59:17 +00:00
|
|
|
<CreateTable
|
|
|
|
isListOrdered={isListOrdered}
|
|
|
|
orderedList={orderedList}
|
|
|
|
listOfElements={listOfElements}
|
|
|
|
links={buildLinks(quantitativeComparisons)}
|
|
|
|
tableRows={tableRows}
|
|
|
|
setTableRows={setTableRows}
|
2022-01-30 15:26:05 +00:00
|
|
|
></CreateTable>
|
2021-12-08 11:59:17 +00:00
|
|
|
</div>
|
2021-11-25 15:31:10 +00:00
|
|
|
</div>
|
2021-12-08 15:46:17 +00:00
|
|
|
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Convenience functions */}
|
2021-11-25 15:31:10 +00:00
|
|
|
<div className="w-2/12 flex justify-center mt-10">
|
|
|
|
<button
|
|
|
|
className="text-gray-500 text-sm"
|
|
|
|
onClick={() => changeShowAdvanceOptions(!showAdvancedOptions)}
|
|
|
|
>
|
|
|
|
Advanced options ▼
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
2022-01-30 15:26:05 +00:00
|
|
|
<div
|
|
|
|
className={
|
|
|
|
showAdvancedOptions
|
|
|
|
? "flex flex-wrap -mx-4 overflow-hidden"
|
|
|
|
: "hidden"
|
|
|
|
}
|
|
|
|
>
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Button: Restart */}
|
2022-01-28 17:50:45 +00:00
|
|
|
<div className="my-4 px-4 w-1/4 overflow-hidden">
|
2021-11-25 15:31:10 +00:00
|
|
|
<button
|
|
|
|
className="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded mt-5"
|
2022-01-30 15:26:05 +00:00
|
|
|
onClick={() => restart(posList)}
|
|
|
|
>
|
2022-01-28 17:50:45 +00:00
|
|
|
{/* onClick={() => restart({posList})}> */}
|
2021-11-25 15:31:10 +00:00
|
|
|
Restart
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Button: Show comparisons */}
|
2022-01-28 17:50:45 +00:00
|
|
|
<div className="my-4 px-4 w-1/4 overflow-hidden">
|
2021-11-25 15:31:10 +00:00
|
|
|
<button
|
|
|
|
className="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded mt-5"
|
2022-01-30 15:26:05 +00:00
|
|
|
onClick={() => changeShowComparisons(!showComparisons)}
|
|
|
|
>
|
2021-11-25 15:31:10 +00:00
|
|
|
Show comparisons
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-01-28 17:50:45 +00:00
|
|
|
{/* Button: Load comparisons */}
|
|
|
|
<div className="my-4 px-4 w-1/4 overflow-hidden">
|
|
|
|
<button
|
|
|
|
className="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded mt-5"
|
2022-01-30 15:26:05 +00:00
|
|
|
onClick={() => changeShowLoadComparisons(!showLoadComparisons)}
|
|
|
|
>
|
2022-01-28 20:09:41 +00:00
|
|
|
Load comparisons
|
2022-01-28 17:50:45 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Button: Change dataset */}
|
2022-01-28 17:50:45 +00:00
|
|
|
<div className="my-4 px-4 w-1/4 overflow-hidden">
|
2021-11-25 15:31:10 +00:00
|
|
|
<button
|
|
|
|
className="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded mt-5"
|
2022-01-30 15:26:05 +00:00
|
|
|
onClick={() => changeshowChangeDataSet(!showChangeDataSet)}
|
|
|
|
>
|
2021-11-25 15:31:10 +00:00
|
|
|
Use your own data
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Change dataset section */}
|
2021-12-08 12:49:29 +00:00
|
|
|
<div className={showChangeDataSet ? "inline mt-5" : "hidden"}>
|
2021-12-08 11:59:17 +00:00
|
|
|
<DataSetChanger handleSubmit={changeDataSet} />
|
2021-11-25 15:31:10 +00:00
|
|
|
</div>
|
|
|
|
|
2021-12-08 11:59:17 +00:00
|
|
|
{/* Show comparisons section */}
|
2021-12-08 12:49:29 +00:00
|
|
|
<div className={showComparisons ? "inline mt-5" : "hidden"}>
|
2021-11-25 15:31:10 +00:00
|
|
|
<div className="text-left">
|
|
|
|
<DisplayAsMarkdown
|
2022-01-28 18:48:47 +00:00
|
|
|
markdowntext={`
|
2022-01-30 15:26:05 +00:00
|
|
|
${
|
|
|
|
"" /*
|
2022-01-28 18:48:47 +00:00
|
|
|
## Comparisons
|
|
|
|
### Binary comparisons
|
|
|
|
${JSON.stringify(binaryComparisons, null, 4)}
|
2022-01-30 15:26:05 +00:00
|
|
|
*/
|
|
|
|
}
|
2022-01-28 18:48:47 +00:00
|
|
|
### Numerical comparisons
|
2022-01-30 15:26:05 +00:00
|
|
|
${JSON.stringify(
|
|
|
|
nicelyFormatLinks(quantitativeComparisons, listOfElements),
|
|
|
|
null,
|
|
|
|
4
|
|
|
|
)}
|
2022-01-28 18:48:47 +00:00
|
|
|
`}
|
2022-01-30 15:26:05 +00:00
|
|
|
className={""}
|
|
|
|
></DisplayAsMarkdown>
|
2021-11-25 15:31:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-01-28 17:50:45 +00:00
|
|
|
{/* Load comparisons section */}
|
|
|
|
<div className={showLoadComparisons ? "inline mt-5" : "hidden"}>
|
2022-01-30 15:26:05 +00:00
|
|
|
<ComparisonsChanger handleSubmit={changeComparisons} />
|
2022-01-28 17:50:45 +00:00
|
|
|
{/*<ComparisonsChanger handleSubmit={changeComparisons} />*/}
|
|
|
|
</div>
|
2021-11-25 15:31:10 +00:00
|
|
|
</main>
|
|
|
|
</div>
|
2022-01-30 15:26:05 +00:00
|
|
|
);
|
2021-11-25 15:31:10 +00:00
|
|
|
}
|