Skip to content

Commit 09dfab1

Browse files
committed
Summarize: Add per-player timeout histograms
1 parent 2dbe6a2 commit 09dfab1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

utils/summarize.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type StatSummary = {
108108
allPlayers: number[];
109109
meta: GameNumList[];
110110
players: UserNumList[];
111+
playerTimeouts: UserNumList[];
111112
firstTimers: number[];
112113
timeouts: number[];
113114
};
@@ -583,6 +584,24 @@ export const handler: Handler = async (event: any, context?: any) => {
583584
histPlayers.push({user: userid, value: [...lst]});
584585
}
585586

587+
// individual player timeouts
588+
const histPlayerTimeouts: UserNumList[] = [];
589+
for (const userid of (new Set<string>(histListPlayers.map(x => x.user)))) {
590+
const toSubset = timeouts.filter(x => x.user === userid);
591+
const subset: {bucket: number}[] = [];
592+
for (const {value} of toSubset) {
593+
const daysAgo = (baseline - value) / (24 * 60 * 60 * 1000);
594+
const bucket = Math.floor(daysAgo / 7);
595+
subset.push({bucket});
596+
}
597+
const maxBucket = Math.max(...subset.map(x => x.bucket));
598+
const lst: number[] = [];
599+
for (let i = 0; i <= maxBucket; i++) {
600+
lst.push(subset.filter(x => x.bucket === i).length);
601+
}
602+
histPlayerTimeouts.push({user: userid, value: [...lst]});
603+
}
604+
586605
// first timers
587606
const buckets: number[] = [];
588607
for (const userid of (new Set<string>(completedList.map(x => x.user)))) {
@@ -687,6 +706,7 @@ export const handler: Handler = async (event: any, context?: any) => {
687706
histograms: {
688707
all: histAll,
689708
allPlayers: histAllPlayers,
709+
playerTimeouts: histPlayerTimeouts,
690710
meta: histMeta,
691711
players: histPlayers,
692712
firstTimers,

0 commit comments

Comments
 (0)