mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-29 11:48:12 -07:00
bitview: reorg part 3
This commit is contained in:
@@ -3,7 +3,8 @@ import {
|
||||
createHorizontalChoiceField,
|
||||
createHeader,
|
||||
} from "../core/dom";
|
||||
import { throttle } from "../core/scheduling";
|
||||
import { serdeChartableIndex, serdeOptNumber } from "../core/serde";
|
||||
import { throttle } from "../core/timing";
|
||||
|
||||
const keyPrefix = "chart";
|
||||
const ONE_BTC_IN_SATS = 100_000_000;
|
||||
@@ -26,7 +27,7 @@ const CANDLE = "candle";
|
||||
* @param {Elements} args.elements
|
||||
* @param {Env} args.env
|
||||
* @param {VecsResources} args.vecsResources
|
||||
* @param {VecIdToIndexes} args.vecIdToIndexes
|
||||
* @param {MetricToIndexes} args.metricToIndexes
|
||||
* @param {Packages} args.packages
|
||||
*/
|
||||
export function init({
|
||||
@@ -39,7 +40,7 @@ export function init({
|
||||
env,
|
||||
webSockets,
|
||||
vecsResources,
|
||||
vecIdToIndexes,
|
||||
metricToIndexes,
|
||||
packages,
|
||||
}) {
|
||||
elements.charts.append(createShadow("left"));
|
||||
@@ -50,7 +51,7 @@ export function init({
|
||||
|
||||
const { index, fieldset } = createIndexSelector({
|
||||
option,
|
||||
vecIdToIndexes,
|
||||
metricToIndexes,
|
||||
signals,
|
||||
utils,
|
||||
});
|
||||
@@ -63,7 +64,7 @@ export function init({
|
||||
|
||||
const from = signals.createSignal(/** @type {number | null} */ (null), {
|
||||
save: {
|
||||
...utils.serde.optNumber,
|
||||
...serdeOptNumber,
|
||||
keyPrefix: TIMERANGE_LS_KEY,
|
||||
key: "from",
|
||||
serializeParam: firstRun,
|
||||
@@ -71,7 +72,7 @@ export function init({
|
||||
});
|
||||
const to = signals.createSignal(/** @type {number | null} */ (null), {
|
||||
save: {
|
||||
...utils.serde.optNumber,
|
||||
...serdeOptNumber,
|
||||
keyPrefix: TIMERANGE_LS_KEY,
|
||||
key: "to",
|
||||
serializeParam: firstRun,
|
||||
@@ -340,7 +341,7 @@ export function init({
|
||||
case null:
|
||||
case CANDLE: {
|
||||
series = chart.addCandlestickSeries({
|
||||
vecId: "price_ohlc",
|
||||
metric: "price_ohlc",
|
||||
name: "Price",
|
||||
unit: topUnit,
|
||||
setDataCallback: printLatest,
|
||||
@@ -350,7 +351,7 @@ export function init({
|
||||
}
|
||||
case LINE: {
|
||||
series = chart.addLineSeries({
|
||||
vecId: "price_close",
|
||||
metric: "price_close",
|
||||
name: "Price",
|
||||
unit: topUnit,
|
||||
color: colors.default,
|
||||
@@ -370,7 +371,7 @@ export function init({
|
||||
case null:
|
||||
case CANDLE: {
|
||||
series = chart.addCandlestickSeries({
|
||||
vecId: "price_ohlc_in_sats",
|
||||
metric: "price_ohlc_in_sats",
|
||||
name: "Price",
|
||||
unit: topUnit,
|
||||
inverse: true,
|
||||
@@ -381,7 +382,7 @@ export function init({
|
||||
}
|
||||
case LINE: {
|
||||
series = chart.addLineSeries({
|
||||
vecId: "price_close_in_sats",
|
||||
metric: "price_close_in_sats",
|
||||
name: "Price",
|
||||
unit: topUnit,
|
||||
color: colors.default,
|
||||
@@ -446,7 +447,7 @@ export function init({
|
||||
order += orderStart;
|
||||
|
||||
const indexes = /** @type {readonly number[]} */ (
|
||||
vecIdToIndexes[blueprint.key]
|
||||
metricToIndexes[blueprint.metric]
|
||||
);
|
||||
|
||||
if (indexes.includes(index)) {
|
||||
@@ -454,7 +455,7 @@ export function init({
|
||||
case "Baseline": {
|
||||
seriesList.push(
|
||||
chart.addBaselineSeries({
|
||||
vecId: blueprint.key,
|
||||
metric: blueprint.metric,
|
||||
name: blueprint.title,
|
||||
unit,
|
||||
defaultActive: blueprint.defaultActive,
|
||||
@@ -474,7 +475,7 @@ export function init({
|
||||
case "Histogram": {
|
||||
seriesList.push(
|
||||
chart.addHistogramSeries({
|
||||
vecId: blueprint.key,
|
||||
metric: blueprint.metric,
|
||||
name: blueprint.title,
|
||||
unit,
|
||||
color: blueprint.color,
|
||||
@@ -493,7 +494,7 @@ export function init({
|
||||
case undefined:
|
||||
seriesList.push(
|
||||
chart.addLineSeries({
|
||||
vecId: blueprint.key,
|
||||
metric: blueprint.metric,
|
||||
color: blueprint.color,
|
||||
name: blueprint.title,
|
||||
unit,
|
||||
@@ -518,11 +519,11 @@ export function init({
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {Accessor<ChartOption>} args.option
|
||||
* @param {VecIdToIndexes} args.vecIdToIndexes
|
||||
* @param {MetricToIndexes} args.metricToIndexes
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
*/
|
||||
function createIndexSelector({ option, vecIdToIndexes, signals, utils }) {
|
||||
function createIndexSelector({ option, metricToIndexes, signals, utils }) {
|
||||
const choices_ = /** @satisfies {SerializedChartableIndex[]} */ ([
|
||||
"timestamp",
|
||||
"date",
|
||||
@@ -546,13 +547,13 @@ function createIndexSelector({ option, vecIdToIndexes, signals, utils }) {
|
||||
const rawIndexes = new Set(
|
||||
[Object.values(o.top), Object.values(o.bottom)]
|
||||
.flat(2)
|
||||
.filter((blueprint) => !blueprint.key.startsWith("constant_"))
|
||||
.map((blueprint) => vecIdToIndexes[blueprint.key])
|
||||
.filter((blueprint) => !blueprint.metric.startsWith("constant_"))
|
||||
.map((blueprint) => metricToIndexes[blueprint.metric])
|
||||
.flat(),
|
||||
);
|
||||
|
||||
const serializedIndexes = [...rawIndexes].flatMap((index) => {
|
||||
const c = utils.serde.chartableIndex.serialize(index);
|
||||
const c = serdeChartableIndex.serialize(index);
|
||||
return c ? [c] : [];
|
||||
});
|
||||
|
||||
@@ -581,7 +582,7 @@ function createIndexSelector({ option, vecIdToIndexes, signals, utils }) {
|
||||
fieldset.dataset.size = "sm";
|
||||
|
||||
const index = signals.createMemo(() =>
|
||||
utils.serde.chartableIndex.deserialize(selected()),
|
||||
serdeChartableIndex.deserialize(selected()),
|
||||
);
|
||||
|
||||
return { fieldset, index };
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { randomFromArray } from "../core/array";
|
||||
|
||||
/**
|
||||
* @param {Object} args
|
||||
@@ -9,7 +10,7 @@
|
||||
* @param {WebSockets} args.webSockets
|
||||
* @param {Elements} args.elements
|
||||
* @param {VecsResources} args.vecsResources
|
||||
* @param {VecIdToIndexes} args.vecIdToIndexes
|
||||
* @param {MetricToIndexes} args.metricToIndexes
|
||||
*/
|
||||
export function init({
|
||||
colors,
|
||||
@@ -20,7 +21,7 @@ export function init({
|
||||
utils,
|
||||
webSockets,
|
||||
vecsResources,
|
||||
vecIdToIndexes,
|
||||
metricToIndexes,
|
||||
}) {
|
||||
const chain = window.document.createElement("div");
|
||||
chain.id = "chain";
|
||||
@@ -41,7 +42,7 @@ export function init({
|
||||
];
|
||||
|
||||
for (let i = 0; i <= 10; i++) {
|
||||
const { name, color } = utils.array.random(miners);
|
||||
const { name, color } = randomFromArray(miners);
|
||||
const { cubeElement, leftFaceElement, rightFaceElement, topFaceElement } =
|
||||
createCube();
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
import {
|
||||
createDateRange,
|
||||
dateToDateIndex,
|
||||
differenceBetweenDates,
|
||||
} from "../core/date";
|
||||
import {
|
||||
createButtonElement,
|
||||
createFieldElement,
|
||||
createHeader,
|
||||
createSelect,
|
||||
} from "../core/dom";
|
||||
import { serdeDate, serdeOptDate, serdeOptNumber } from "../core/serde";
|
||||
|
||||
/**
|
||||
* @param {Object} args
|
||||
@@ -5,8 +17,6 @@
|
||||
* @param {CreateChartElement} args.createChartElement
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
* @param {Serde} args.serde
|
||||
* @param {Dom} args.dom
|
||||
* @param {Elements} args.elements
|
||||
* @param {VecsResources} args.vecsResources
|
||||
*/
|
||||
@@ -15,8 +25,6 @@ export function init({
|
||||
elements,
|
||||
createChartElement,
|
||||
signals,
|
||||
serde,
|
||||
dom,
|
||||
utils,
|
||||
vecsResources,
|
||||
}) {
|
||||
@@ -126,7 +134,7 @@ export function init({
|
||||
const min = "2011-01-01";
|
||||
const minDate = new Date(min);
|
||||
const maxDate = new Date();
|
||||
const max = utils.date.toString(maxDate);
|
||||
const max = serdeDate.serialize(maxDate);
|
||||
input.min = min;
|
||||
input.max = max;
|
||||
|
||||
@@ -135,7 +143,7 @@ export function init({
|
||||
signals.createEffect(
|
||||
() => {
|
||||
const dateSignal = signal();
|
||||
return dateSignal ? utils.date.toString(dateSignal) : "";
|
||||
return dateSignal ? serdeDate.serialize(dateSignal) : "";
|
||||
},
|
||||
(value) => {
|
||||
if (stateValue !== value) {
|
||||
@@ -169,7 +177,7 @@ export function init({
|
||||
if (!element) throw "createResetableField element missing";
|
||||
div.append(element);
|
||||
|
||||
const button = dom.createButtonElement({
|
||||
const button = createButtonElement({
|
||||
onClick: signal.reset,
|
||||
inside: "Reset",
|
||||
title: "Reset field",
|
||||
@@ -309,7 +317,7 @@ export function init({
|
||||
initial: {
|
||||
amount: signals.createSignal(/** @type {number | null} */ (1000), {
|
||||
save: {
|
||||
...serde.optNumber,
|
||||
...serdeOptNumber,
|
||||
keyPrefix,
|
||||
key: "initial-amount",
|
||||
},
|
||||
@@ -318,7 +326,7 @@ export function init({
|
||||
topUp: {
|
||||
amount: signals.createSignal(/** @type {number | null} */ (150), {
|
||||
save: {
|
||||
...serde.optNumber,
|
||||
...serdeOptNumber,
|
||||
keyPrefix,
|
||||
key: "top-up-amount",
|
||||
},
|
||||
@@ -339,14 +347,14 @@ export function init({
|
||||
investment: {
|
||||
initial: signals.createSignal(/** @type {number | null} */ (1000), {
|
||||
save: {
|
||||
...serde.optNumber,
|
||||
...serdeOptNumber,
|
||||
keyPrefix,
|
||||
key: "initial-swap",
|
||||
},
|
||||
}),
|
||||
recurrent: signals.createSignal(/** @type {number | null} */ (5), {
|
||||
save: {
|
||||
...serde.optNumber,
|
||||
...serdeOptNumber,
|
||||
keyPrefix,
|
||||
key: "recurrent-swap",
|
||||
},
|
||||
@@ -368,7 +376,7 @@ export function init({
|
||||
/** @type {Date | null} */ (new Date("2021-04-15")),
|
||||
{
|
||||
save: {
|
||||
...serde.optDate,
|
||||
...serdeOptDate,
|
||||
keyPrefix,
|
||||
key: "interval-start",
|
||||
},
|
||||
@@ -376,7 +384,7 @@ export function init({
|
||||
),
|
||||
end: signals.createSignal(/** @type {Date | null} */ (new Date()), {
|
||||
save: {
|
||||
...serde.optDate,
|
||||
...serdeOptDate,
|
||||
keyPrefix,
|
||||
key: "interval-end",
|
||||
},
|
||||
@@ -385,7 +393,7 @@ export function init({
|
||||
fees: {
|
||||
percentage: signals.createSignal(/** @type {number | null} */ (0.25), {
|
||||
save: {
|
||||
...serde.optNumber,
|
||||
...serdeOptNumber,
|
||||
keyPrefix,
|
||||
key: "percentage",
|
||||
},
|
||||
@@ -393,7 +401,7 @@ export function init({
|
||||
},
|
||||
};
|
||||
|
||||
parametersElement.append(dom.createHeader("Save in Bitcoin").headerElement);
|
||||
parametersElement.append(createHeader("Save in Bitcoin").headerElement);
|
||||
|
||||
/**
|
||||
* @param {Object} param0
|
||||
@@ -418,7 +426,7 @@ export function init({
|
||||
}
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "green",
|
||||
type: "Dollars",
|
||||
@@ -438,7 +446,7 @@ export function init({
|
||||
);
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "green",
|
||||
type: "Dollars",
|
||||
@@ -447,7 +455,7 @@ export function init({
|
||||
description:
|
||||
"The frequency at which you'll top up your account at the exchange.",
|
||||
input: domExtended.createResetableInput(
|
||||
dom.createSelect({
|
||||
createSelect({
|
||||
id: "top-up-frequency",
|
||||
list: frequencies.list,
|
||||
signal: settings.dollars.topUp.frenquency,
|
||||
@@ -458,7 +466,7 @@ export function init({
|
||||
);
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "green",
|
||||
type: "Dollars",
|
||||
@@ -478,7 +486,7 @@ export function init({
|
||||
);
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "orange",
|
||||
type: "Bitcoin",
|
||||
@@ -498,7 +506,7 @@ export function init({
|
||||
);
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "orange",
|
||||
type: "Bitcoin",
|
||||
@@ -506,7 +514,7 @@ export function init({
|
||||
}),
|
||||
description: "The frequency at which you'll be buying Bitcoin.",
|
||||
input: domExtended.createResetableInput(
|
||||
dom.createSelect({
|
||||
createSelect({
|
||||
id: "investment-frequency",
|
||||
list: frequencies.list,
|
||||
signal: settings.bitcoin.investment.frequency,
|
||||
@@ -517,7 +525,7 @@ export function init({
|
||||
);
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "orange",
|
||||
type: "Bitcoin",
|
||||
@@ -537,7 +545,7 @@ export function init({
|
||||
);
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "sky",
|
||||
type: "Interval",
|
||||
@@ -556,7 +564,7 @@ export function init({
|
||||
);
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "sky",
|
||||
type: "Interval",
|
||||
@@ -575,7 +583,7 @@ export function init({
|
||||
);
|
||||
|
||||
parametersElement.append(
|
||||
dom.createFieldElement({
|
||||
createFieldElement({
|
||||
title: createColoredTypeHTML({
|
||||
color: "red",
|
||||
type: "Fees",
|
||||
@@ -869,7 +877,7 @@ export function init({
|
||||
}) => {
|
||||
if (!start || !end || start > end) return;
|
||||
|
||||
const range = utils.date.getRange(start, end);
|
||||
const range = createDateRange(start, end);
|
||||
|
||||
totalInvestedAmountData().length = 0;
|
||||
bitcoinValueData().length = 0;
|
||||
@@ -916,7 +924,7 @@ export function init({
|
||||
dollars += topUpAmount;
|
||||
}
|
||||
|
||||
const close = closes[utils.date.toDateIndex(date)];
|
||||
const close = closes[dateToDateIndex(date)];
|
||||
|
||||
if (!close) return;
|
||||
|
||||
@@ -1071,7 +1079,7 @@ export function init({
|
||||
p1.innerHTML = `After exchanging ${serInvestedAmount} in the span of ${serDaysCount} days, you would have accumulated ${serSats} Satoshis (${serBitcoin} Bitcoin) worth today ${serBitcoinValue} at an average price of ${serAveragePricePaid} per Bitcoin with a return of investment of ${serRoi}, have ${serDollars} left and paid a total of ${serTotalFeesPaid} in fees.`;
|
||||
|
||||
const dayDiff = Math.floor(
|
||||
utils.date.differenceBetween(new Date(), lastInvestDay),
|
||||
differenceBetweenDates(new Date(), lastInvestDay),
|
||||
);
|
||||
const serDailyInvestment = c("emerald", fd(dailyInvestment));
|
||||
const setLastSatsAdded = c("orange", f(lastSatsAdded));
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { createButtonElement, createSelect } from "../core/dom";
|
||||
import { randomFromArray } from "../core/array";
|
||||
import { createButtonElement, createHeader, createSelect } from "../core/dom";
|
||||
import { serdeMetrics, serdeString, serdeUnit } from "../core/serde";
|
||||
import { resetParams } from "../core/url";
|
||||
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {VecIdToIndexes} args.vecIdToIndexes
|
||||
* @param {MetricToIndexes} args.metricToIndexes
|
||||
* @param {Option} args.option
|
||||
* @param {Utilities} args.utils
|
||||
* @param {Signals} args.signals
|
||||
@@ -10,12 +13,12 @@ import { createButtonElement, createSelect } from "../core/dom";
|
||||
*/
|
||||
function createTable({
|
||||
utils,
|
||||
vecIdToIndexes,
|
||||
metricToIndexes,
|
||||
signals,
|
||||
option,
|
||||
vecsResources,
|
||||
}) {
|
||||
const indexToVecIds = createIndexToVecIds(vecIdToIndexes);
|
||||
const indexToMetrics = createIndexToMetrics(metricToIndexes);
|
||||
|
||||
const serializedIndexes = createSerializedIndexes();
|
||||
/** @type {SerializedIndex} */
|
||||
@@ -25,7 +28,7 @@ function createTable({
|
||||
/** @type {SerializedIndex} */ (defaultSerializedIndex),
|
||||
{
|
||||
save: {
|
||||
...utils.serde.string,
|
||||
...serdeString,
|
||||
keyPrefix: "table",
|
||||
key: "index",
|
||||
},
|
||||
@@ -45,20 +48,20 @@ function createTable({
|
||||
|
||||
signals.createEffect(index, (index, prevIndex) => {
|
||||
if (prevIndex !== undefined) {
|
||||
utils.url.resetParams(option);
|
||||
resetParams(option);
|
||||
}
|
||||
|
||||
const possibleVecIds = indexToVecIds[index];
|
||||
const possibleMetrics = indexToMetrics[index];
|
||||
|
||||
const columns = signals.createSignal(/** @type {VecId[]} */ ([]), {
|
||||
const columns = signals.createSignal(/** @type {Metric[]} */ ([]), {
|
||||
equals: false,
|
||||
save: {
|
||||
...utils.serde.vecIds,
|
||||
...serdeMetrics,
|
||||
keyPrefix: `table-${serializedIndex()}`,
|
||||
key: `columns`,
|
||||
},
|
||||
});
|
||||
columns.set((l) => l.filter((id) => possibleVecIds.includes(id)));
|
||||
columns.set((l) => l.filter((id) => possibleMetrics.includes(id)));
|
||||
|
||||
signals.createEffect(columns, (columns) => {
|
||||
console.log(columns);
|
||||
@@ -174,35 +177,35 @@ function createTable({
|
||||
const owner = signals.getOwner();
|
||||
|
||||
/**
|
||||
* @param {VecId} vecId
|
||||
* @param {Metric} metric
|
||||
* @param {number} [_colIndex]
|
||||
*/
|
||||
function addCol(vecId, _colIndex = columns().length) {
|
||||
function addCol(metric, _colIndex = columns().length) {
|
||||
signals.runWithOwner(owner, () => {
|
||||
/** @type {VoidFunction | undefined} */
|
||||
let dispose;
|
||||
signals.createRoot((_dispose) => {
|
||||
dispose = _dispose;
|
||||
|
||||
const vecIdOption = signals.createSignal({
|
||||
name: vecId,
|
||||
value: vecId,
|
||||
const metricOption = signals.createSignal({
|
||||
name: metric,
|
||||
value: metric,
|
||||
});
|
||||
const { select } = createSelect({
|
||||
list: possibleVecIds.map((vecId) => ({
|
||||
name: vecId,
|
||||
value: vecId,
|
||||
list: possibleMetrics.map((metric) => ({
|
||||
name: metric,
|
||||
value: metric,
|
||||
})),
|
||||
signal: vecIdOption,
|
||||
signal: metricOption,
|
||||
});
|
||||
|
||||
signals.createEffect(vecIdOption, (vecIdOption) => {
|
||||
select.style.width = `${21 + 7.25 * vecIdOption.name.length}px`;
|
||||
signals.createEffect(metricOption, (metricOption) => {
|
||||
select.style.width = `${21 + 7.25 * metricOption.name.length}px`;
|
||||
});
|
||||
|
||||
if (_colIndex === columns().length) {
|
||||
columns.set((l) => {
|
||||
l.push(vecId);
|
||||
l.push(metric);
|
||||
return l;
|
||||
});
|
||||
}
|
||||
@@ -252,7 +255,7 @@ function createTable({
|
||||
|
||||
const th = addThCol({
|
||||
select,
|
||||
unit: utils.vecidToUnit(vecId),
|
||||
unit: serdeUnit.deserialize(metric),
|
||||
onLeft: createMoveColumnFunction(false),
|
||||
onRight: createMoveColumnFunction(true),
|
||||
onRemove: () => {
|
||||
@@ -284,23 +287,23 @@ function createTable({
|
||||
}
|
||||
|
||||
signals.createEffect(
|
||||
() => vecIdOption().name,
|
||||
(vecId, prevVecId) => {
|
||||
const unit = utils.vecidToUnit(vecId);
|
||||
() => metricOption().name,
|
||||
(metric, prevMetric) => {
|
||||
const unit = serdeUnit.deserialize(metric);
|
||||
th.setUnit(unit);
|
||||
|
||||
const vec = vecsResources.getOrCreate(index, vecId);
|
||||
const vec = vecsResources.getOrCreate(index, metric);
|
||||
|
||||
vec.fetch({ from, to });
|
||||
|
||||
const fetchedKey = vecsResources.genFetchedKey({ from, to });
|
||||
|
||||
columns.set((l) => {
|
||||
const i = l.indexOf(prevVecId ?? vecId);
|
||||
const i = l.indexOf(prevMetric ?? metric);
|
||||
if (i === -1) {
|
||||
l.push(vecId);
|
||||
l.push(metric);
|
||||
} else {
|
||||
l[i] = vecId;
|
||||
l[i] = metric;
|
||||
}
|
||||
return l;
|
||||
});
|
||||
@@ -325,7 +328,7 @@ function createTable({
|
||||
},
|
||||
);
|
||||
|
||||
return () => vecId;
|
||||
return () => metric;
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -337,10 +340,10 @@ function createTable({
|
||||
});
|
||||
}
|
||||
|
||||
columns().forEach((vecId, colIndex) => addCol(vecId, colIndex));
|
||||
columns().forEach((metric, colIndex) => addCol(metric, colIndex));
|
||||
|
||||
obj.addRandomCol = function () {
|
||||
addCol(utils.array.random(possibleVecIds));
|
||||
addCol(randomFromArray(possibleMetrics));
|
||||
};
|
||||
|
||||
return () => index;
|
||||
@@ -356,7 +359,7 @@ function createTable({
|
||||
* @param {Option} args.option
|
||||
* @param {Elements} args.elements
|
||||
* @param {VecsResources} args.vecsResources
|
||||
* @param {VecIdToIndexes} args.vecIdToIndexes
|
||||
* @param {MetricToIndexes} args.metricToIndexes
|
||||
*/
|
||||
export function init({
|
||||
elements,
|
||||
@@ -364,7 +367,7 @@ export function init({
|
||||
option,
|
||||
utils,
|
||||
vecsResources,
|
||||
vecIdToIndexes,
|
||||
metricToIndexes,
|
||||
}) {
|
||||
const parent = elements.table;
|
||||
const { headerElement } = createHeader("Table");
|
||||
@@ -376,7 +379,7 @@ export function init({
|
||||
const table = createTable({
|
||||
signals,
|
||||
utils,
|
||||
vecIdToIndexes,
|
||||
metricToIndexes,
|
||||
vecsResources,
|
||||
option,
|
||||
});
|
||||
@@ -397,33 +400,33 @@ export function init({
|
||||
|
||||
function createSerializedIndexes() {
|
||||
return /** @type {const} */ ([
|
||||
/** @satisfies {VecId} */ ("dateindex"),
|
||||
/** @satisfies {VecId} */ ("decadeindex"),
|
||||
/** @satisfies {VecId} */ ("difficultyepoch"),
|
||||
/** @satisfies {VecId} */ ("emptyoutputindex"),
|
||||
/** @satisfies {VecId} */ ("halvingepoch"),
|
||||
/** @satisfies {VecId} */ ("height"),
|
||||
/** @satisfies {VecId} */ ("inputindex"),
|
||||
/** @satisfies {VecId} */ ("monthindex"),
|
||||
/** @satisfies {VecId} */ ("opreturnindex"),
|
||||
/** @satisfies {VecId} */ ("semesterindex"),
|
||||
/** @satisfies {VecId} */ ("outputindex"),
|
||||
/** @satisfies {VecId} */ ("p2aaddressindex"),
|
||||
/** @satisfies {VecId} */ ("p2msoutputindex"),
|
||||
/** @satisfies {VecId} */ ("p2pk33addressindex"),
|
||||
/** @satisfies {VecId} */ ("p2pk65addressindex"),
|
||||
/** @satisfies {VecId} */ ("p2pkhaddressindex"),
|
||||
/** @satisfies {VecId} */ ("p2shaddressindex"),
|
||||
/** @satisfies {VecId} */ ("p2traddressindex"),
|
||||
/** @satisfies {VecId} */ ("p2wpkhaddressindex"),
|
||||
/** @satisfies {VecId} */ ("p2wshaddressindex"),
|
||||
/** @satisfies {VecId} */ ("quarterindex"),
|
||||
/** @satisfies {VecId} */ ("txindex"),
|
||||
/** @satisfies {VecId} */ ("unknownoutputindex"),
|
||||
/** @satisfies {VecId} */ ("weekindex"),
|
||||
/** @satisfies {VecId} */ ("yearindex"),
|
||||
/** @satisfies {VecId} */ ("loadedaddressindex"),
|
||||
/** @satisfies {VecId} */ ("emptyaddressindex"),
|
||||
/** @satisfies {Metric} */ ("dateindex"),
|
||||
/** @satisfies {Metric} */ ("decadeindex"),
|
||||
/** @satisfies {Metric} */ ("difficultyepoch"),
|
||||
/** @satisfies {Metric} */ ("emptyoutputindex"),
|
||||
/** @satisfies {Metric} */ ("halvingepoch"),
|
||||
/** @satisfies {Metric} */ ("height"),
|
||||
/** @satisfies {Metric} */ ("inputindex"),
|
||||
/** @satisfies {Metric} */ ("monthindex"),
|
||||
/** @satisfies {Metric} */ ("opreturnindex"),
|
||||
/** @satisfies {Metric} */ ("semesterindex"),
|
||||
/** @satisfies {Metric} */ ("outputindex"),
|
||||
/** @satisfies {Metric} */ ("p2aaddressindex"),
|
||||
/** @satisfies {Metric} */ ("p2msoutputindex"),
|
||||
/** @satisfies {Metric} */ ("p2pk33addressindex"),
|
||||
/** @satisfies {Metric} */ ("p2pk65addressindex"),
|
||||
/** @satisfies {Metric} */ ("p2pkhaddressindex"),
|
||||
/** @satisfies {Metric} */ ("p2shaddressindex"),
|
||||
/** @satisfies {Metric} */ ("p2traddressindex"),
|
||||
/** @satisfies {Metric} */ ("p2wpkhaddressindex"),
|
||||
/** @satisfies {Metric} */ ("p2wshaddressindex"),
|
||||
/** @satisfies {Metric} */ ("quarterindex"),
|
||||
/** @satisfies {Metric} */ ("txindex"),
|
||||
/** @satisfies {Metric} */ ("unknownoutputindex"),
|
||||
/** @satisfies {Metric} */ ("weekindex"),
|
||||
/** @satisfies {Metric} */ ("yearindex"),
|
||||
/** @satisfies {Metric} */ ("loadedaddressindex"),
|
||||
/** @satisfies {Metric} */ ("emptyaddressindex"),
|
||||
]);
|
||||
}
|
||||
/** @typedef {ReturnType<typeof createSerializedIndexes>} SerializedIndexes */
|
||||
@@ -493,24 +496,24 @@ function serializedIndexToIndex(serializedIndex) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {VecIdToIndexes} vecIdToIndexes
|
||||
* @param {MetricToIndexes} metricToIndexes
|
||||
*/
|
||||
function createIndexToVecIds(vecIdToIndexes) {
|
||||
const indexToVecIds = Object.entries(vecIdToIndexes).reduce(
|
||||
function createIndexToMetrics(metricToIndexes) {
|
||||
const indexToMetrics = Object.entries(metricToIndexes).reduce(
|
||||
(arr, [_id, indexes]) => {
|
||||
const id = /** @type {VecId} */ (_id);
|
||||
const id = /** @type {Metric} */ (_id);
|
||||
indexes.forEach((i) => {
|
||||
arr[i] ??= [];
|
||||
arr[i].push(id);
|
||||
});
|
||||
return arr;
|
||||
},
|
||||
/** @type {VecId[][]} */ (Array.from({ length: 24 })),
|
||||
/** @type {Metric[][]} */ (Array.from({ length: 24 })),
|
||||
);
|
||||
indexToVecIds.forEach((arr) => {
|
||||
indexToMetrics.forEach((arr) => {
|
||||
arr.sort();
|
||||
});
|
||||
return indexToVecIds;
|
||||
return indexToMetrics;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user