diff --git a/lib/findPaths.js b/lib/findPaths.js index 977a781..99879cf 100644 --- a/lib/findPaths.js +++ b/lib/findPaths.js @@ -1,8 +1,18 @@ /* Imports*/ import React from "react"; +import { toLocale, truncateValueForDisplay } from "../lib/utils.js" /* Utilities */ let avg = arr => arr.reduce((a,b) => (a+b)) / arr.length +let formatLargeOrSmall = num => { + if(num > 1){ + return toLocale(truncateValueForDisplay(num)) + }else if(num != 0){ + return num.toFixed(-Math.floor(Math.log(num)/Math.log(10))); + }else{ + return "~0" + } +} /* Main function */ @@ -108,9 +118,9 @@ export function CreateTableWithDistances({isListOrdered, orderedList, listOfElem     {row.name}     - {JSON.stringify(row.distances, null, 2)} + {JSON.stringify(row.distances.map(d => formatLargeOrSmall(d)), null, 2).replaceAll(`"`, "")}     - {avg(row.distances).toFixed(2)} + {formatLargeOrSmall(avg(row.distances))} )} diff --git a/lib/utils.js b/lib/utils.js index 431b068..4252e08 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -4,5 +4,13 @@ export const hashString = (string) => crypto.createHash('md5').update(string).di export const transformSliderValueToActualValue = value => 10 ** value //>= 2 ? Math.round(10 ** value) : Math.round(10 * 10 ** value) / 10 export const toLocale = x => Number(x).toLocaleString() -export const truncateValueForDisplay = value => value > 10 ? Number(Math.round(value).toPrecision(2)) : Math.round(value * 10) / 10 +export const truncateValueForDisplay = value => { + if(value > 10){ + return Number(Math.round(value).toPrecision(2)) + }else if(value > 1){ + return Math.round(value * 10) / 10 + } else if(value < 1){ + + } +} export const transformSliderValueToPracticalValue = value => truncateValueForDisplay(transformSliderValueToActualValue(value)) diff --git a/pages/index.js b/pages/index.js index ab22fc3..8463708 100644 --- a/pages/index.js +++ b/pages/index.js @@ -14,7 +14,7 @@ import { DisplayAsMarkdown } from '../lib/displayAsMarkdown' import { CreateTableWithDistances } from '../lib/findPaths' import { TextAreaForJson } from "../lib/textAreaForJson" import { pushToMongo } from "../lib/pushToMongo.js" -import { toLocale, transformSliderValueToPracticalValue } from "../lib/utils.js" +import { toLocale, transformSliderValueToPracticalValue, transformSliderValueToActualValue } from "../lib/utils.js" /* Helpers */ let increasingList = (n) => Array.from(Array(n).keys()) @@ -220,7 +220,7 @@ export default function Home({ listOfElementsDefault }) { console.log(posList) let successStatus = nextStepSimple(posList, binaryComparisons, element1, element2) - let newQuantitativeComparison = [element1, element2, transformSliderValueToPracticalValue(sliderValue)] + let newQuantitativeComparison = [element1, element2, transformSliderValueToActualValue(sliderValue)] let newQuantitativeComparisons = [...quantitativeComparisons, newQuantitativeComparison] setQuantitativeComparisons(newQuantitativeComparisons) diff --git a/pages/listOfResearchOutputs.json b/pages/listOfResearchOutputs.json index 3ae5223..6dcdbcd 100644 --- a/pages/listOfResearchOutputs.json +++ b/pages/listOfResearchOutputs.json @@ -13,7 +13,8 @@ }, { "name": "Categorizing Variants of Goodhart's Law", - "url": "https://arxiv.org/abs/1803.04585" + "url": "https://arxiv.org/abs/1803.04585", + "isReferenceValue": true }, { "name": "The Vulnerable World Hypothesis",