mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-18 06:28:11 -07:00
website: redesign part 25
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import { createCohortSeries } from "./cohort-series.js";
|
||||
import { createRollingWindowSeries } from "./rolling-windows.js";
|
||||
import { colors } from "../../utils/colors.js";
|
||||
import { brk } from "../../utils/client.js";
|
||||
|
||||
const poolNames = brk.POOL_ID_TO_POOL_NAME;
|
||||
|
||||
/**
|
||||
* @template {keyof typeof poolNames} Key
|
||||
* @template Pool
|
||||
* @param {Record<Key, Pool>} pools
|
||||
*/
|
||||
function createPools(pools) {
|
||||
const entries = [];
|
||||
|
||||
for (const key in pools) {
|
||||
entries.push({
|
||||
name: poolNames[key],
|
||||
pool: pools[key],
|
||||
});
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(window: WindowKey) => TimeframeMetric} createMetric
|
||||
*/
|
||||
function createWindowSeries(createMetric) {
|
||||
return createRollingWindowSeries((window) => () => createMetric(window));
|
||||
}
|
||||
|
||||
export const majorPools = createPools(brk.series.pools.major);
|
||||
|
||||
export const minorPools = createPools(brk.series.pools.minor);
|
||||
|
||||
export const majorPoolDominanceSeries = createCohortSeries(
|
||||
majorPools.map(({ name, pool }) => ({
|
||||
label: name,
|
||||
metric: () => pool.dominance._1m.percent,
|
||||
})),
|
||||
);
|
||||
|
||||
export const majorPoolBlocksMinedSeries = createCohortSeries(
|
||||
majorPools.map(({ name, pool }) => ({
|
||||
label: name,
|
||||
metric: () => pool.blocksMined.sum._1m,
|
||||
})),
|
||||
);
|
||||
|
||||
export const majorPoolRewardsSeries = createCohortSeries(
|
||||
majorPools.map(({ name, pool }) => ({
|
||||
label: name,
|
||||
metric: () => pool.rewards.sum._1m.btc,
|
||||
})),
|
||||
);
|
||||
|
||||
/** @param {MajorPool} pool */
|
||||
export function createMajorPoolDominanceSeries(pool) {
|
||||
const series = createWindowSeries(
|
||||
(window) => pool.dominance[window].percent,
|
||||
);
|
||||
|
||||
series.push({
|
||||
label: "All time",
|
||||
color: colors.orange,
|
||||
metric: () => pool.dominance.percent,
|
||||
});
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
/** @param {MajorPool} pool */
|
||||
export function createMajorPoolBlocksMinedSeries(pool) {
|
||||
return createWindowSeries(
|
||||
(window) => pool.blocksMined.sum[window],
|
||||
);
|
||||
}
|
||||
|
||||
/** @param {MajorPool} pool */
|
||||
export function createMajorPoolRewardsSeries(pool) {
|
||||
return createWindowSeries(
|
||||
(window) => pool.rewards.sum[window].btc,
|
||||
);
|
||||
}
|
||||
|
||||
/** @param {MinorPool} pool */
|
||||
export function createMinorPoolDominanceSeries(pool) {
|
||||
return createCohortSeries([
|
||||
{
|
||||
label: "All time",
|
||||
color: colors.orange,
|
||||
metric: () => pool.dominance.percent,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
/** @param {MinorPool} pool */
|
||||
export function createMinorPoolBlocksMinedSeries(pool) {
|
||||
return createWindowSeries(
|
||||
(window) => pool.blocksMined.sum[window],
|
||||
);
|
||||
}
|
||||
|
||||
/** @typedef {import("./rolling-windows.js").RollingWindowKey} WindowKey */
|
||||
/** @typedef {typeof brk.series.pools.major.unknown} MajorPool */
|
||||
/** @typedef {typeof brk.series.pools.minor.blockfills} MinorPool */
|
||||
/** @typedef {import("../charts/timeframes.js").TimeframeMetric} TimeframeMetric */
|
||||
Reference in New Issue
Block a user