Skip to content

Commit

Permalink
wip convert processors to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 28, 2023
1 parent 9bea40d commit ff7862c
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Console } from 'console';
import readline from 'readline';
import processAllPlayers from './processAllPlayers.mjs';
import processTeamfights from './processTeamfights.mjs';
import processParsedData from './processParsedData.mjs';
import processMetadata from './processMetadata.mjs';
import processExpand from './processExpand.mjs';
import processDraftTimings from './processDraftTimings.mjs';
import parseSchema from './parseSchema.mjs';
import processAllPlayers from './processAllPlayers.js';
import processTeamfights from './processTeamfights.js';
import processParsedData from './processParsedData.js';
import processMetadata from './processMetadata.js';
import processExpand from './processExpand.js';
import processDraftTimings from './processDraftTimings.js';
import parseSchema from './parseSchema.js';

function createParsedDataBlob(entries, matchId) {
function createParsedDataBlob(entries: any[], matchId: string) {
const logConsole = new Console(process.stderr);
logConsole.time('metadata');
const meta = processMetadata(entries);
Expand All @@ -33,13 +33,13 @@ function createParsedDataBlob(entries, matchId) {
parsedData.radiant_xp_adv = ap.radiant_xp_adv;
return parsedData;
}
const entries = [];
const entries: any[] = [];
let complete = false;
const matchId = process.argv[2];
const parseStream = readline.createInterface({
input: process.stdin,
});
parseStream.on('line', (e) => {
parseStream.on('line', (e: any) => {
e = JSON.parse(e);
entries.push(e);
if (e.type === 'epilogue') {
Expand All @@ -49,7 +49,7 @@ parseStream.on('line', (e) => {
parseStream.on('close', () => {
if (complete) {
const parsedData = createParsedDataBlob(entries, matchId);
process.stdout.write(JSON.stringify(parsedData), null, (err) => {
process.stdout.write(JSON.stringify(parsedData), undefined, (err) => {
process.exit(Number(err));
});
} else {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion processors/populate.mjs → processors/populate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import performanceOthers from './performanceOthers.mjs';
import performanceOthers from './performanceOthers.js';
function populate(e, container, meta) {
let t;
switch (e.type) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Given an event stream, extracts metadata such as game zero time and hero to slot/ID mappings.
* */
function processMetadata(entries) {
function processMetadata(entries: any[]) {
const heroToSlot = {};
const slotToPlayerslot = {};
const heroIdToSlot = {};
Expand Down Expand Up @@ -47,6 +47,7 @@ function processMetadata(entries) {
slot_to_playerslot: slotToPlayerslot,
hero_id_to_slot: heroIdToSlot,
ability_levels: abilityLevels,
match_id: '',
};
}
export default processMetadata;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import populate from './populate.mjs';
import populate from './populate.js';
function processParsedData(entries, container, meta) {
for (let i = 0; i < entries.length; i += 1) {
const e = entries[i];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import populate from './populate.mjs';
import populate from './populate.js';
/**
* A processor to compute teamfights that occurred given an event stream
* */
Expand Down
File renamed without changes.

0 comments on commit ff7862c

Please sign in to comment.