Skip to content

Commit

Permalink
feat: add naive game summarizer for treatment data
Browse files Browse the repository at this point in the history
emits to `dump/raw/games.csv`
  • Loading branch information
alee committed Dec 5, 2023
1 parent f64d0ad commit ee92126
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getRedis, getServices } from "@port-of-mars/server/services";
import {
AccomplishmentSummarizer,
GameSummarizer,
GameEventSummarizer,
GameReplayer,
MarsEventSummarizer,
Expand Down Expand Up @@ -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");
Expand All @@ -104,6 +113,7 @@ async function exportData(
[
marsLogSummarizer,
playerSummarizer,
gameSummarizer,
gameEventSummarizer,
victoryPointSummarizer,
playerInvestmentSummarizer,
Expand Down
16 changes: 16 additions & 0 deletions server/src/services/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
events: Map<number, Array<entity.GameEvent>>;

Expand Down Expand Up @@ -267,6 +270,19 @@ export class AccomplishmentSummarizer {
}
}

export class GameSummarizer {
constructor(public games: Array<entity.Game>, 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"];
Expand Down

0 comments on commit ee92126

Please sign in to comment.