MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / createStatsStore

Function createStatsStore

source code/context/stats.tsx:30–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28 max: number;
29};
30export function createStatsStore(): StatsStore {
31 const metrics = new Map<string, number>();
32 const histograms = new Map<string, Histogram>();
33 const sets = new Map<string, Set<string>>();
34 return {
35 increment(name: string, value = 1) {
36 metrics.set(name, (metrics.get(name) ?? 0) + value);
37 },
38 set(name: string, value: number) {
39 metrics.set(name, value);
40 },
41 observe(name: string, value: number) {
42 let h = histograms.get(name);
43 if (!h) {
44 h = {
45 reservoir: [],
46 count: 0,
47 sum: 0,
48 min: value,
49 max: value
50 };
51 histograms.set(name, h);
52 }
53 h.count++;
54 h.sum += value;
55 if (value < h.min) {
56 h.min = value;
57 }
58 if (value > h.max) {
59 h.max = value;
60 }
61 // Reservoir sampling (Algorithm R)
62 if (h.reservoir.length < RESERVOIR_SIZE) {
63 h.reservoir.push(value);
64 } else {
65 const j = Math.floor(Math.random() * h.count);
66 if (j < RESERVOIR_SIZE) {
67 h.reservoir[j] = value;
68 }
69 }
70 },
71 add(name: string, value: string) {
72 let s = sets.get(name);
73 if (!s) {
74 s = new Set();
75 sets.set(name, s);
76 }
77 s.add(value);
78 },
79 getAll() {
80 const result: Record<string, number> = Object.fromEntries(metrics);
81 for (const [name, h] of histograms) {
82 if (h.count === 0) {
83 continue;
84 }
85 result[`${name}_count`] = h.count;
86 result[`${name}_min`] = h.min;
87 result[`${name}_max`] = h.max;

Callers 2

getRenderContextFunction · 0.85
StatsProviderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected