global: snapshot

This commit is contained in:
nym21
2026-03-18 21:04:08 +01:00
parent 24f344c0b1
commit 92e1a0ccaf
39 changed files with 819 additions and 1912 deletions
+47 -23
View File
@@ -9,12 +9,12 @@ import { Unit } from "../utils/units.js";
/** @typedef {'_24h' | '_1w' | '_1m' | '_1y'} RollingWindowKey */
/** @type {ReadonlyArray<{key: RollingWindowKey, name: string, color: Color}>} */
/** @type {ReadonlyArray<{key: RollingWindowKey, name: string, title: string, color: Color}>} */
export const ROLLING_WINDOWS = [
{ key: "_24h", name: "24h", color: colors.time._24h },
{ key: "_1w", name: "1w", color: colors.time._1w },
{ key: "_1m", name: "1m", color: colors.time._1m },
{ key: "_1y", name: "1y", color: colors.time._1y },
{ key: "_24h", name: "24h", title: "Daily", color: colors.time._24h },
{ key: "_1w", name: "1w", title: "Weekly", color: colors.time._1w },
{ key: "_1m", name: "1m", title: "Monthly", color: colors.time._1m },
{ key: "_1y", name: "1y", title: "Yearly", color: colors.time._1y },
];
/** @type {ReadonlyArray<{key: '_24h' | '_1w' | '_1m', name: string, color: Color}>} */
@@ -474,19 +474,20 @@ export function statsAtWindow(pattern, window) {
* Create a Rolling folder tree from a _1m1w1y24hPattern (4 rolling windows)
* @param {Object} args
* @param {{ _24h: AnySeriesPattern, _1w: AnySeriesPattern, _1m: AnySeriesPattern, _1y: AnySeriesPattern }} args.windows
* @param {string} args.title
* @param {string} args.title - Compare chart title
* @param {(w: typeof ROLLING_WINDOWS[number]) => string} args.windowTitle - Individual window chart title
* @param {Unit} args.unit
* @param {string} [args.name]
* @param {string} args.name
* @param {(args: {series: AnySeriesPattern, name: string, color: Color, unit: Unit}) => AnyFetchedSeriesBlueprint} [args.series]
* @returns {PartialOptionsGroup}
*/
export function rollingWindowsTree({ windows, title, unit, name = "Sums", series = line }) {
function rollingWindowsTree({ windows, title, windowTitle, unit, name, series = line }) {
return {
name,
tree: [
{
name: "Compare",
title: `${title} Rolling`,
title,
bottom: ROLLING_WINDOWS.map((w) =>
series({
series: windows[w.key],
@@ -498,7 +499,7 @@ export function rollingWindowsTree({ windows, title, unit, name = "Sums", series
},
...ROLLING_WINDOWS.map((w) => ({
name: w.name,
title: `${title} ${w.name}`,
title: windowTitle(w),
bottom: [
series({
series: windows[w.key],
@@ -512,6 +513,32 @@ export function rollingWindowsTree({ windows, title, unit, name = "Sums", series
};
}
/**
* Rolling sums tree
* @param {Object} args
* @param {{ _24h: AnySeriesPattern, _1w: AnySeriesPattern, _1m: AnySeriesPattern, _1y: AnySeriesPattern }} args.windows
* @param {string} args.title
* @param {Unit} args.unit
* @param {(args: {series: AnySeriesPattern, name: string, color: Color, unit: Unit}) => AnyFetchedSeriesBlueprint} [args.series]
* @returns {PartialOptionsGroup}
*/
export function sumsTree({ windows, title, unit, series }) {
return rollingWindowsTree({ windows, title, windowTitle: (w) => `${title} ${w.title} Sum`, unit, name: "Sums", ...(series ? { series } : {}) });
}
/**
* Rolling averages tree
* @param {Object} args
* @param {{ _24h: AnySeriesPattern, _1w: AnySeriesPattern, _1m: AnySeriesPattern, _1y: AnySeriesPattern }} args.windows
* @param {string} args.title
* @param {Unit} args.unit
* @param {string} [args.name]
* @returns {PartialOptionsGroup}
*/
export function averagesTree({ windows, title, unit, name = "Averages" }) {
return rollingWindowsTree({ windows, title, windowTitle: (w) => `${title} ${w.title} Average`, unit, name });
}
/**
* Create a Distribution folder tree with stats at each rolling window (24h/7d/30d/1y)
* @param {Object} args
@@ -819,7 +846,7 @@ export function chartsFromFull({
title,
bottom: [{ series: pattern.base, title: "base", unit }],
},
rollingWindowsTree({ windows: pattern.sum, title, unit }),
sumsTree({ windows: pattern.sum, title, unit }),
distributionWindowsTree({ pattern, title: distTitle, unit }),
{
name: "Cumulative",
@@ -865,7 +892,7 @@ export function chartsFromAggregated({
title,
bottom: [{ series: pattern.sum, title: "base", color: stat.sum, unit }],
},
rollingWindowsTree({ windows: pattern.rolling.sum, title, unit }),
sumsTree({ windows: pattern.rolling.sum, title, unit }),
distributionWindowsTree({ pattern: pattern.rolling, title: distTitle, unit }),
{
name: "Cumulative",
@@ -920,7 +947,7 @@ export function chartsFromBlockAnd6b({ pattern, title, unit }) {
*/
export function chartsFromSumsCumulative({ pattern, title, unit, color }) {
return [
rollingWindowsTree({ windows: pattern.sum, title, unit }),
sumsTree({ windows: pattern.sum, title, unit }),
{
name: "Cumulative",
title: `${title} (Total)`,
@@ -988,16 +1015,13 @@ export function multiSeriesTree({ entries, title, unit }) {
line({ series: e.base, name: e.name, color: e.color, unit }),
),
},
{
name: "Sums",
tree: ROLLING_WINDOWS.map((w) => ({
name: w.name,
title: `${title} (${w.name})`,
bottom: entries.map((e) =>
line({ series: e.rolling[w.key], name: e.name, color: e.color, unit }),
),
})),
},
...ROLLING_WINDOWS.map((w) => ({
name: w.name,
title: `${title} ${w.title} Sum`,
bottom: entries.map((e) =>
line({ series: e.rolling[w.key], name: e.name, color: e.color, unit }),
),
})),
{
name: "Cumulative",
title: `${title} (Total)`,