Combine analytics and game types (#839)

## Description:

Combine analytics and game types. Simplify and remove redundant player
information.

- Remove ip address.
- Add playerID.
- Combine redundant player tables.
- Move game metadata in to GameEndInfo type, an extension of
GameStartInfo

## 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

---------

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
This commit is contained in:
Scott Anderson
2025-05-22 15:06:30 -04:00
committed by GitHub
parent 373de1a752
commit 9302af868d
14 changed files with 75 additions and 104 deletions
+25 -39
View File
@@ -5,9 +5,9 @@ import { Cell, Team, Unit } from "./game/Game";
import { GameMap, TileRef } from "./game/GameMap";
import {
ClientID,
GameConfig,
GameID,
GameRecord,
GameStartInfo,
PlayerRecord,
Turn,
} from "./Schemas";
@@ -184,53 +184,39 @@ export function onlyImages(html: string) {
}
export function createGameRecord(
id: GameID,
gameStartInfo: GameStartInfo,
gameID: GameID,
config: GameConfig,
// username does not need to be set.
players: PlayerRecord[],
turns: Turn[],
startTimestampMS: number,
endTimestampMS: number,
allTurns: Turn[],
start: number,
end: number,
winner: ClientID | Team | null,
winnerType: "player" | "team" | null,
): GameRecord {
const durationSeconds = Math.floor(
(endTimestampMS - startTimestampMS) / 1000,
);
const date = new Date().toISOString().split("T")[0];
const duration = Math.floor((end - start) / 1000);
const version = "v0.0.2";
const gitCommit = "";
const num_turns = allTurns.length;
const turns = allTurns.filter(
(t) => t.intents.length !== 0 || t.hash !== undefined,
);
const record: GameRecord = {
gitCommit,
id,
gameStartInfo,
players,
startTimestampMS,
endTimestampMS,
durationSeconds,
date,
num_turns: 0,
turns: [],
info: {
gameID,
config,
players,
start,
end,
duration,
num_turns,
winner,
winnerType,
},
version,
winner,
winnerType,
gitCommit,
turns,
};
for (const turn of turns) {
if (turn.intents.length !== 0 || turn.hash !== undefined) {
record.turns.push(turn);
for (const intent of turn.intents) {
if (intent.type === "spawn") {
for (const playerRecord of players) {
if (playerRecord.clientID === intent.clientID) {
playerRecord.username = intent.name;
}
}
}
}
}
}
record.num_turns = turns.length;
return record;
}
@@ -249,7 +235,7 @@ export function decompressGameRecord(gameRecord: GameRecord) {
lastTurnNum = turn.turnNumber;
}
const turnLength = turns.length;
for (let i = turnLength; i < gameRecord.num_turns; i++) {
for (let i = turnLength; i < gameRecord.info.num_turns; i++) {
turns.push({
turnNumber: i,
intents: [],