Skip to content

Commit 663ab10

Browse files
committed
Revert "Try aggregate ratings"
This reverts commit 7d38a9b.
1 parent e1c5ae0 commit 663ab10

File tree

1 file changed

+0
-93
lines changed

1 file changed

+0
-93
lines changed

utils/summarize.ts

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ type StatSummary = {
8989
highest: UserGameRating[];
9090
avg: UserRating[];
9191
weighted: UserRating[];
92-
aggregate: UserGameRating[];
9392
};
9493
topPlayers: UserGameRating[];
9594
plays: {
@@ -438,97 +437,6 @@ export const handler: Handler = async (event: any, context?: any) => {
438437
const ratedGames = new Set<string>(ratingList.map(r => r.game));
439438
const ratedPlayers = new Set<string>(ratingList.map(r => r.user));
440439

441-
// AGGREGATE RATINGS
442-
// rate all records for a given player in a single pool
443-
console.log("Doing aggregated ratings");
444-
const aggRater = new ELOBasic();
445-
const aggRatingList: RatingList = [];
446-
// collate list of raw ratings right here and now
447-
const aggList: UserGameRating[] = [];
448-
for (const [player, recs] of player2recs.entries()) {
449-
console.log(`Aggregating all game records for ${player}`);
450-
// Elo ratings first
451-
const results = aggRater.runProcessed(recs);
452-
console.log(`Elo rater:\nTotal records: ${results.recsReceived}, Num rated: ${results.recsRated}\n${results.warnings !== undefined ? results.warnings.join("\n") + "\n" : ""}${results.errors !== undefined ? results.errors.join("\n") + "\n" : ""}`);
453-
for (const rating of results.ratings.values()) {
454-
rating.gamename = "AGGREGATE";
455-
const [,userid] = rating.userid.split("|");
456-
rating.userid = userid;
457-
aggRatingList.push({user: userid, game: "AGGREGATE", rating});
458-
}
459-
460-
// now Trueskill
461-
console.log(`Running Trueskill ratings`);
462-
const ts = new Trueskill({betaStart: 25/9});
463-
const tsResults = ts.runProcessed(recs);
464-
const tsRatings = new Map(tsResults.ratings) as Map<string, ITrueskillRating>;
465-
if (aggRatingList.filter(r => r.user === player).length !== tsRatings.size) {
466-
const elo = new Set<string>(aggRatingList.map(r => r.user));
467-
const tsVals = new Set<string>([...tsRatings.values()].map(r => {const [,u] = r.userid.split("|"); return u;}))
468-
const inElo = [...elo.values()].filter(u => ! tsVals.has(u));
469-
const inTS = [...tsVals.values()].filter(u => ! elo.has(u));
470-
throw new Error(`The list of Elo ratings is not the same length as the list of Trueskill ratings.\nList of Elo ratings not in Trueskill: ${JSON.stringify(inElo, null, 2)}\nList of Trueskill ratings not in Elo: ${JSON.stringify(inTS, null, 2)}\nTrueskill ratings: ${JSON.stringify(tsRatings, replacer, 2)}`);
471-
}
472-
console.log(`Final Trueskill ratings:\n${JSON.stringify([...tsRatings.values()])}`)
473-
474-
// now Glicko
475-
console.log(`Running Glicko2 ratings`);
476-
const glicko = new Glicko2();
477-
// get earliest and latest dates for subset
478-
const oldest = new Date(recs.map(r => r.header["date-end"]).sort((a, b) => a.localeCompare(b))[0]);
479-
const newest = new Date(recs.map(r => r.header["date-end"]).sort((a, b) => b.localeCompare(a))[0]);
480-
console.log(`Oldest: ${oldest}, Newest: ${newest}`);
481-
const delta = newest.getTime() - oldest.getTime();
482-
const period = 60 * 24 * 60 * 60 * 1000;
483-
let numPeriods = Math.ceil(delta / period);
484-
if (numPeriods === 0) { numPeriods++; }
485-
console.log(`Number of periods: ${numPeriods}`);
486-
let toDate = new Map<string, IGlickoRating>();
487-
let ratedRecs = 0;
488-
for (let p = 0; p < numPeriods; p++) {
489-
glicko.knownRatings = new Map(toDate);
490-
const pMin = oldest.getTime() + (p * period);
491-
const pMax = oldest.getTime() + ((p + 1) * period)
492-
const recs: APGameRecord[] = [];
493-
for (const rec of recs) {
494-
const secs = new Date(rec.header["date-end"]).getTime();
495-
if ( (secs >= pMin) && (secs < pMax) ) {
496-
recs.push(rec);
497-
}
498-
}
499-
ratedRecs += recs.length;
500-
const results = glicko.runProcessed(recs);
501-
toDate = new Map(results.ratings as Map<string, IGlickoRating>);
502-
}
503-
if (ratedRecs !== recs.length) {
504-
throw new Error(`The record subset had ${recs.length} records, but only ${ratedRecs} were handed to the rater.`);
505-
}
506-
// toDate now has the final rating results
507-
if (recs.length !== toDate.size) {
508-
const elo = new Set<string>(aggList.map(r => r.user));
509-
const glicko = new Set<string>([...toDate.values()].map(r => {const [,u] = r.userid.split("|"); return u;}))
510-
const inElo = [...elo.values()].filter(u => ! glicko.has(u));
511-
const inGlicko = [...glicko.values()].filter(u => ! elo.has(u));
512-
throw new Error(`The list of Elo ratings is not the same length as the list of Glicko ratings.\nList of Elo ratings not in Glicko: ${JSON.stringify(inElo, null, 2)}\nList of Glicko ratings not in Elo: ${JSON.stringify(inGlicko, null, 2)}\nGlicko ratings: ${JSON.stringify(toDate, replacer, 2)}`);
513-
}
514-
console.log(`Final glicko rating results: ${JSON.stringify(toDate, replacer)}`)
515-
516-
// Save Elo, Glicko2, and Trueskill ratings into rawList
517-
for (const userStr of toDate.keys()) {
518-
const [,user] = userStr.split("|");
519-
const elo = aggRatingList.find(r => r.user === user)?.rating;
520-
if (elo === undefined) {
521-
throw new Error(`Could not find a matching Elo rating for ${user}.`);
522-
}
523-
const ts = tsRatings.get(userStr);
524-
if (ts === undefined) {
525-
throw new Error(`Could not find a matching Trueskill rating for ${user}.`);
526-
}
527-
const glicko = toDate.get(userStr)!;
528-
aggList.push({user, game: "AGGREGATE", rating: Math.round(elo.rating), wld: [elo.wins, elo.losses, elo.draws], glicko: {rating: glicko.rating, rd: glicko.rd}, trueskill: {mu: ts.rating, sigma: ts.sigma}});
529-
}
530-
}
531-
532440
// LISTS OF RATINGS
533441
console.log("Summarizing ratings");
534442
// raw [see `rawList` above]
@@ -843,7 +751,6 @@ export const handler: Handler = async (event: any, context?: any) => {
843751
highest: rawList,
844752
avg: avgRatings,
845753
weighted: weightedRatings,
846-
aggregate: aggList,
847754
},
848755
topPlayers,
849756
plays: {

0 commit comments

Comments
 (0)