Skip to content

Commit

Permalink
Records: Extract and store time-to-move stats for later processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Dec 25, 2024
1 parent 09dfab1 commit a0ef705
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions utils/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export const handler: Handler = async (event: any, context?: any) => {
const metaRecs = new Map<string, APGameRecord[]>();
const userRecs = new Map<string, APGameRecord[]>();
const eventRecs = new Map<string, APGameRecord[]>();
const ttm = new Map<string, number[]>();
for (const gdata of justGames) {
const g = GameFactory(gdata.metaGame, gdata.state);
if (g === undefined) {
Expand Down Expand Up @@ -222,6 +223,14 @@ export const handler: Handler = async (event: any, context?: any) => {
pushToMap(eventRecs, id, rec);
}
}
// calculate response rates
const times: number[] = [];
for (let i = 0; i < g.stack.length - 1; i++) {
const t1 = new Date(g.stack[i]._timestamp).getTime();
const t2 = new Date(g.stack[i+1]._timestamp).getTime();
times.push(t2 - t1);
}
times.forEach((t, i) => pushToMap(ttm, gdata.players[i % g.numplayers].id, t));
}
console.log(`allRecs: ${allRecs.length}, metaRecs: ${[...metaRecs.keys()].length}, userRecs: ${[...userRecs.keys()].length}, eventRecs: ${[...eventRecs.keys()].length}`);

Expand Down Expand Up @@ -263,6 +272,19 @@ export const handler: Handler = async (event: any, context?: any) => {
}
}
console.log("Player recs done");
// response times
for (const [player, lst] of ttm.entries()) {
cmd = new PutObjectCommand({
Bucket: REC_BUCKET,
Key: `ttm/${player}.json`,
Body: JSON.stringify(lst),
});
response = await s3.send(cmd);
if (response["$metadata"].httpStatusCode !== 200) {
console.log(response);
}
}
console.log("Response times done");
// events
for (const [eventid, recs] of eventRecs.entries()) {
cmd = new PutObjectCommand({
Expand Down

0 comments on commit a0ef705

Please sign in to comment.