Record player stats during the game (#784)

## Description:

Record player stats for the analytics worker to import in to to
postgres. This changes defines a new Analytics schema version, `v0.0.2`,
containing additional metadata about each player.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors
This commit is contained in:
Scott Anderson
2025-05-21 00:10:29 -04:00
committed by GitHub
parent 228f5b13af
commit 5aa8356513
27 changed files with 581 additions and 161 deletions
+4 -17
View File
@@ -1,5 +1,6 @@
import { z } from "zod";
import quickChatData from "../../resources/QuickChat.json" with { type: "json" };
import { PlayerStatsSchema } from "./ArchiveSchemas";
import {
AllPlayers,
Difficulty,
@@ -91,7 +92,6 @@ export type PlayerRecord = z.infer<typeof PlayerRecordSchema>;
export type GameRecord = z.infer<typeof GameRecordSchema>;
export type AllPlayersStats = z.infer<typeof AllPlayersStatsSchema>;
export type PlayerStats = z.infer<typeof PlayerStatsSchema>;
export type Player = z.infer<typeof PlayerSchema>;
export type GameStartInfo = z.infer<typeof GameStartInfoSchema>;
const PlayerTypeSchema = z.nativeEnum(PlayerType);
@@ -176,19 +176,6 @@ const ID = z
.regex(/^[a-zA-Z0-9]+$/)
.length(8);
const NukesEnum = z.enum([
"Atom Bomb",
"Hydrogen Bomb",
"MIRV",
"MIRV Warhead",
]);
const NukeStatsSchema = z.record(NukesEnum, z.number());
export const PlayerStatsSchema = z.object({
sentNukes: z.record(ID, NukeStatsSchema),
});
export const AllPlayersStatsSchema = z.record(ID, PlayerStatsSchema);
// Zod schemas
@@ -460,6 +447,7 @@ export const PlayerRecordSchema = z.object({
username: SafeString,
ip: SafeString.nullable(), // WARNING: PII
persistentID: PersistentIdSchema, // WARNING: PII
stats: PlayerStatsSchema,
});
export const GameRecordSchema = z.object({
@@ -474,7 +462,6 @@ export const GameRecordSchema = z.object({
turns: z.array(TurnSchema),
winner: z.union([ID, SafeString]).nullable().optional(),
winnerType: z.enum(["player", "team"]).nullable().optional(),
allPlayersStats: z.record(ID, PlayerStatsSchema),
version: z.enum(["v0.0.1"]),
gitCommit: z.string().nullable().optional(),
version: z.literal("v0.0.2"),
gitCommit: z.string(),
});