UNPKG

@hastearcade/snowglobe

Version:

A TypeScript port of CrystalOrb, a high-level Rust game networking library

53 lines 1.94 kB
import * as csv from 'csv-writer'; export var AnalyticType; (function (AnalyticType) { AnalyticType[AnalyticType["currentworld"] = 0] = "currentworld"; AnalyticType[AnalyticType["recvcommand"] = 1] = "recvcommand"; AnalyticType[AnalyticType["issuecommand"] = 2] = "issuecommand"; AnalyticType[AnalyticType["snapshotapplied"] = 3] = "snapshotapplied"; AnalyticType[AnalyticType["snapshotgenerated"] = 4] = "snapshotgenerated"; AnalyticType[AnalyticType["worldhistory"] = 5] = "worldhistory"; })(AnalyticType || (AnalyticType = {})); export class Analytics { id; data; // tick number, map of analytic to data value // we need to store for every tick // a list of commands to process // any snapshots generated // any snapshots applied // world history at that tick // current world at that tick // Data structure // { tick0: {commands: string, snapshotsapplied: string, snapshotsgenerated: string, worldhistory: string, currentworld: string }} constructor(id) { this.id = id; this.data = new Map(); } store(tickNumber, type, data) { if (!this.data.has(tickNumber)) { this.data.set(tickNumber, ['', '', '', '', '']); } const dataStore = this.data.get(tickNumber); dataStore[type] = data; } async flush() { const csvWriter = csv.createArrayCsvWriter({ path: `${this.id}-${Date.now()}.csv`, header: [ 'tick', 'currentworld', 'recvcommand', 'issuecommand', 'snapshotapplied', 'snapshotgenerated', 'worldhistory' ] }); const data = []; this.data.forEach((val, key) => { data.push([key.toString()].concat(val)); }); await csvWriter.writeRecords(data); } } //# sourceMappingURL=analytics.js.map