import React, { useState, useEffect } from "react"; import { findDistances, aggregatePaths } from "utility-tools"; import { Separator } from "./separator.js"; import { truncateValueForDisplay } from "../lib/truncateNums.js"; import { cutOffLongNames } from "../lib/stringManipulations.js"; import { getCoefficientOfVariation } from "../lib/coefficientOfVariation.js"; async function fullResultsTable({ listAfterMergeSort, links }) { console.log("listAfterMergeSort", listAfterMergeSort); console.log(links); let pathsArray = await findDistances({ orderedList: listAfterMergeSort, links: links, }); let aggregatedPaths = await aggregatePaths({ pathsArray: pathsArray, orderedList: listAfterMergeSort, aggregationType: "mean", // VERBOSE: false, }); return aggregatedPaths; } function abridgeArrayAndDisplay(array) { let newArray; let formatForDisplay; if (array.length > 10) { newArray = array.slice(0, 9); formatForDisplay = newArray.map((d) => truncateValueForDisplay(d)); formatForDisplay[9] = "..."; } else { newArray = array; formatForDisplay = newArray.map((d) => truncateValueForDisplay(d)); } let result = JSON.stringify(formatForDisplay, null, 2).replaceAll(`"`, ""); return result; } function getRow(row, i) { return ( {i} {cutOffLongNames(row.name)} {abridgeArrayAndDisplay(row.arrayMeans)} {truncateValueForDisplay(row.aggregatedMeans)} {truncateValueForDisplay(getCoefficientOfVariation(row.arrayMeans))} ); } function reactTableContents(tableContents) { return tableContents.map((row, i) => getRow(row, i)); } export function ResultsTable({ isListOrdered, listAfterMergeSort, links }) { const [isTableComputed, setIsTableComputed] = useState(false); const [tableContents, setTableContents] = useState([]); useEffect(async () => { if (isListOrdered && listAfterMergeSort.length > 0) { // both comparisons aren't strictly necessary, // but it bit me once, so I'm leaving it let tableContentsResult = await fullResultsTable({ listAfterMergeSort, links, }); console.log(tableContentsResult); setTableContents(tableContentsResult); setIsTableComputed(true); } }, [isListOrdered, listAfterMergeSort, links]); return !(isListOrdered && isTableComputed) ? ( "" ) : (
{reactTableContents(tableContents)}
Position Element Possible relative values Aggregated Means* Coefficient of variation

*This is the geometric mean if all elements are either all positive or all negative, and the arithmetic mean otherwise. For a principled aggregation which is able to produce meaningfull 90% confidence intervals, see the{" "} utility-tools package {" "} in npm or github

); }