Skip to content

Commit

Permalink
fix: include full treatment info in tournament/game export
Browse files Browse the repository at this point in the history
* amend export.R preprocessing script to run over all tournament round
  dirs

ref virtualcommons/planning#64
  • Loading branch information
sgfost committed Dec 19, 2023
1 parent 10177d6 commit 21073fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
12 changes: 11 additions & 1 deletion analytics/R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@ run_pipeline <- function(base_dir) {
readr::write_csv(chat_messages, fs::path_join(c(base_dir, "processed/chatMessages.csv")))
}

run_pipeline("/dump")
process_all_rounds <- function(base_path) {
# assumes that all numeric directories contain exported tournament round data
entries <- fs::dir_ls(base_path)
tournament_dirs <- entries[fs::path_ext(entries) == '' & grepl("^[0-9]+$", fs::path_file(entries))]

for (dir in tournament_dirs) {
run_pipeline(dir)
}
}

process_all_rounds("/dump")
1 change: 1 addition & 0 deletions server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async function exportTournamentRound(
const gameQuery = em
.getRepository(Game)
.createQueryBuilder("game")
.leftJoinAndSelect("game.treatment", "treatment")
.where("game.tournamentRound.id = :tournamentRoundId", { tournamentRoundId });
const games = await gameQuery.getMany();

Expand Down
17 changes: 15 additions & 2 deletions server/src/services/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,26 @@ export class AccomplishmentSummarizer {
export class GameSummarizer {
constructor(public games: Array<entity.Game>, public path: string) {}

flattenTreatmentData(game: entity.Game) {
const { treatment, ...rest } = game;
if (!treatment) return game;

return {
...rest,
treatmentName: treatment.name,
treatmentDescription: treatment.description,
treatmentMarsEventOverrides: JSON.stringify(treatment.marsEventOverrides),
};
}

async save() {
const header = Object.keys(this.games[0]).map(name => ({
const flattenedGames = this.games.map(g => this.flattenTreatmentData(g));
const header = Object.keys(flattenedGames[0]).map(name => ({
id: name,
title: name,
}));
const writer = createObjectCsvWriter({ path: this.path, header });
await writer.writeRecords(this.games);
await writer.writeRecords(flattenedGames);
}
}

Expand Down

0 comments on commit 21073fb

Please sign in to comment.