@@ -5,7 +5,7 @@ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
55import { DynamoDBDocumentClient , QueryCommand } from '@aws-sdk/lib-dynamodb' ;
66import { isoToCountryCode } from "../lib/isoToCountryCode" ;
77import { 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" ;
99import { 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