Skip to content

Commit b113e6d

Browse files
committed
Fix lint issues
1 parent b7352cd commit b113e6d

File tree

3 files changed

+89
-33
lines changed

3 files changed

+89
-33
lines changed

package-lock.json

Lines changed: 63 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"homepage": "https://github.com/AbstractPlay/node-backend#readme",
2626
"dependencies": {
2727
"@abstractplay/gameslib": "^1.0.0-ci-12333004916.0",
28-
"@abstractplay/recranks": "latest",
28+
"@abstractplay/recranks": "^1.0.0-ci-12495117451.0",
2929
"@aws-sdk/client-cloudfront": "^3.445.0",
3030
"@aws-sdk/client-dynamodb": "^3.321.1",
3131
"@aws-sdk/client-s3": "^3.374.0",

utils/summarize.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
55
import { DynamoDBDocumentClient, QueryCommand } from '@aws-sdk/lib-dynamodb';
66
import { isoToCountryCode } from "../lib/isoToCountryCode";
77
import { Handler } from "aws-lambda";
8-
import { type IRating, type IGlickoRating, type APGameRecord, ELOBasic, Glicko2, type ITrueskillRating, Trueskill } from "@abstractplay/recranks";
8+
import { type IRating, type IGlickoRating, APGameRecord, ELOBasic, Glicko2, type ITrueskillRating, Trueskill } from "@abstractplay/recranks";
99
import { replacer } from "@abstractplay/gameslib/build/src/common";
1010
// import { nanoid } from "nanoid";
1111

@@ -80,7 +80,7 @@ interface GeoStats {
8080
n: number;
8181
}
8282

83-
type GameSummary = {
83+
type StatSummary = {
8484
numGames: number;
8585
numPlayers: number;
8686
oldestRec?: string;
@@ -100,6 +100,7 @@ type GameSummary = {
100100
eclectic: UserNumber[];
101101
allPlays: UserNumber[];
102102
h: UserNumber[];
103+
timeouts: UserNumber[];
103104
};
104105
histograms: {
105106
all: number[];
@@ -155,6 +156,7 @@ export const handler: Handler = async (event: any, context?: any) => {
155156
const ratingList: RatingList = [];
156157
let oldest: string|undefined;
157158
let newest: string|undefined;
159+
const timeouts: UserNumber[] = [];
158160

159161
console.log("Segmenting records by meta and player");
160162
for (const rec of recs) {
@@ -181,6 +183,19 @@ export const handler: Handler = async (event: any, context?: any) => {
181183
const sorted = [newest, rec.header["date-end"]].sort((a, b) => b.localeCompare(a));
182184
newest = sorted[0];
183185
}
186+
// find timeouts
187+
const moveStr = JSON.stringify(rec.moves);
188+
// if abandoned, assign timeout to all players
189+
if (moveStr.includes("abandoned")) {
190+
for (const p of rec.header.players) {
191+
const datems = new Date(rec.header["date-end"]).getTime();
192+
timeouts.push({user: p.userid!, value: datems});
193+
}
194+
}
195+
// if timeout, assign timeout to player who timed out
196+
else if (moveStr.includes("timeout")) {
197+
// find the specific move
198+
}
184199
}
185200
const numPlayers = playerIDs.size;
186201

@@ -459,14 +474,14 @@ export const handler: Handler = async (event: any, context?: any) => {
459474
// h-index
460475
const h: UserNumber[] = [];
461476
for (const [user, recs] of player2recs.entries()) {
462-
console.log(`Calculating h-index for user ${user}`);
477+
// console.log(`Calculating h-index for user ${user}`);
463478
const gameNames = new Set<string>(recs.map(r => r.header.game.name));
464-
console.log(JSON.stringify([...gameNames.values()]));
479+
// console.log(JSON.stringify([...gameNames.values()]));
465480
const counts = new Map<string, number>();
466481
for (const name of gameNames) {
467482
counts.set(name, recs.filter(r => r.header.game.name === name).length);
468483
}
469-
console.log(JSON.stringify([...counts.entries()]));
484+
// console.log(JSON.stringify([...counts.entries()]));
470485
const sorted = [...counts.values()].sort((a, b) => b - a);
471486
let index = sorted.length;
472487
for (let i = 0; i < sorted.length; i++) {
@@ -475,7 +490,7 @@ export const handler: Handler = async (event: any, context?: any) => {
475490
break;
476491
}
477492
}
478-
console.log(`h-index is ${index}`);
493+
// console.log(`h-index is ${index}`);
479494
h.push({user, value: index});
480495
}
481496

@@ -492,8 +507,8 @@ export const handler: Handler = async (event: any, context?: any) => {
492507
const bucket = Math.floor(daysAgo / 7);
493508
histList.push({game: rec.header.game.name, bucket});
494509
for (const player of rec.header.players) {
495-
histListPlayers.push({user: player.userid, bucket});
496-
completedList.push({user: player.userid, time: completed})
510+
histListPlayers.push({user: player.userid!, bucket});
511+
completedList.push({user: player.userid!, time: completed})
497512
}
498513
}
499514

@@ -614,7 +629,7 @@ export const handler: Handler = async (event: any, context?: any) => {
614629
}
615630

616631

617-
const summary: GameSummary = {
632+
const summary: StatSummary = {
618633
numGames,
619634
numPlayers,
620635
oldestRec: oldest,
@@ -634,6 +649,7 @@ export const handler: Handler = async (event: any, context?: any) => {
634649
eclectic,
635650
social,
636651
h,
652+
timeouts,
637653
},
638654
histograms: {
639655
all: histAll,

0 commit comments

Comments
 (0)