From ee92126f0a76b3bad33742ec5205575bd207de45 Mon Sep 17 00:00:00 2001 From: Allen Lee Date: Mon, 4 Dec 2023 22:53:34 -0700 Subject: [PATCH] feat: add naive game summarizer for treatment data emits to `dump/raw/games.csv` --- server/src/cli.ts | 10 ++++++++++ server/src/services/replay.ts | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/server/src/cli.ts b/server/src/cli.ts index 987ea0724..9d01ce2f2 100644 --- a/server/src/cli.ts +++ b/server/src/cli.ts @@ -1,6 +1,7 @@ import { getRedis, getServices } from "@port-of-mars/server/services"; import { AccomplishmentSummarizer, + GameSummarizer, GameEventSummarizer, GameReplayer, MarsEventSummarizer, @@ -83,8 +84,16 @@ async function exportData( const playerRaw = await playerQuery.getRawMany(); const events = await eventQuery.getMany(); + const gameQuery = em + .getRepository(Game) + .createQueryBuilder("game") + .where("game.tournamentRound.id = :tournamentRoundId", { tournamentRoundId }); + const games = await gameQuery.getMany(); + await mkdir("/dump/processed", { recursive: true }); await mkdir("/dump/raw", { recursive: true }); + + const gameSummarizer = new GameSummarizer(games, "/dump/raw/games.csv"); const marsLogSummarizer = new MarsLogSummarizer(events, "/dump/processed/marsLog.csv"); const playerSummarizer = new PlayerSummarizer(playerRaw, "/dump/processed/player.csv"); const gameEventSummarizer = new GameEventSummarizer(events, "/dump/processed/gameEvent.csv"); @@ -104,6 +113,7 @@ async function exportData( [ marsLogSummarizer, playerSummarizer, + gameSummarizer, gameEventSummarizer, victoryPointSummarizer, playerInvestmentSummarizer, diff --git a/server/src/services/replay.ts b/server/src/services/replay.ts index 3265cae3e..35944e8d1 100644 --- a/server/src/services/replay.ts +++ b/server/src/services/replay.ts @@ -55,6 +55,9 @@ class ObjColumn { } } +/** + * FIXME: should probably be renamed to GameEventSummarizer since that's what it does. Then GameEventSummarizer turns into AllGameEventsSummarizer, or something + */ export abstract class Summarizer { events: Map>; @@ -267,6 +270,19 @@ export class AccomplishmentSummarizer { } } +export class GameSummarizer { + constructor(public games: Array, public path: string) {} + + async save() { + const header = Object.keys(this.games[0]).map(name => ({ + id: name, + title: name, + })); + const writer = createObjectCsvWriter({ path: this.path, header }); + await writer.writeRecords(this.games); + } +} + interface PlayerRaw { player_id: Player["id"]; player_gameId: Player["gameId"];