Skip to content

Commit

Permalink
wip esm
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 1, 2023
1 parent 3840b22 commit 6e13fb2
Show file tree
Hide file tree
Showing 163 changed files with 3,864 additions and 4,041 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTORS.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Currently this will cause the /players/:id endpoint to return is_contributor = true for your profile
*/

module.exports = {
export default {
88367253: {}, // howardchung
102344608: {}, // albertcui
9977887: {}, // gu3st
Expand Down
10 changes: 5 additions & 5 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* File managing configuration for the application
* */
const dotenv = require('dotenv');
const fs = require('fs');
import { config } from 'dotenv';
import { existsSync } from 'fs';

if (fs.existsSync('.env')) {
dotenv.config();
if (existsSync('.env')) {
config();
}

const defaults = {
Expand Down Expand Up @@ -97,4 +97,4 @@ if (process.env.NODE_ENV === 'test') {
process.env.PARSER_PORT = 5201;
}
// now processes can use either process.env or config
module.exports = process.env;
export default process.env;
3 changes: 2 additions & 1 deletion dev/checkAccounts.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fs from 'fs';
import Steam from 'steam';
import async from 'async';
import {EOL} from 'os';
const accountData = fs.readFileSync('./STEAM_ACCOUNT_DATA_BAD.txt', 'utf8');
const accountArray = accountData.split(require('os').EOL);
const accountArray = accountData.split(EOL);

let index = Number(process.argv[2]) || -1;
async.whilst(
Expand Down
File renamed without changes.
63 changes: 54 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "21.0.2",
"license": "MIT",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index",
"test": "NODE_ENV=test mocha --exit",
Expand Down Expand Up @@ -62,7 +63,7 @@
"steam-resources": "github:odota/node-steam-resources",
"stripe": "^9.12.0",
"supertest": "^4.0.2",
"uuid": "^3.3.3"
"uuid": "^9.0.1"
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.0.2",
Expand Down
19 changes: 9 additions & 10 deletions processors/createParsedDataBlob.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { Console } = require('console');
const readline = require('readline');
const processAllPlayers = require('./processAllPlayers');
const processTeamfights = require('./processTeamfights');
// const processUploadProps = require('../processors/processUploadProps');
const processParsedData = require('./processParsedData');
const processMetadata = require('./processMetadata');
const processExpand = require('./processExpand');
const processDraftTimings = require('./processDraftTimings');
import { Console } from 'console';
import { createInterface } from 'readline';
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';

function getParseSchema() {
return {
Expand Down Expand Up @@ -118,7 +117,7 @@ function createParsedDataBlob(entries, matchId) {
const entries = [];
let complete = false;
const matchId = process.argv[2];
const parseStream = readline.createInterface({
const parseStream = createInterface({
input: process.stdin,
});
parseStream.on('line', (e) => {
Expand Down
4 changes: 2 additions & 2 deletions processors/populate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const performanceOthers = require('./performanceOthers');
import performanceOthers from './performanceOthers.js';

function populate(e, container, meta) {
let t;
Expand Down Expand Up @@ -134,4 +134,4 @@ function populate(e, container, meta) {
break;
}
}
module.exports = populate;
export default populate;
8 changes: 4 additions & 4 deletions processors/processAllPlayers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const utility = require('../util/utility');
import { isRadiant } from '../util/utility.js';

/**
* Compute data requiring all players in a match for storage in match table
Expand All @@ -13,12 +13,12 @@ function processAllPlayers(entries, meta) {
for (let i = 0; i < entries.length; i += 1) {
const e = entries[i];
if (e.time >= 0 && e.time % 60 === 0 && e.type === 'interval') {
const g = utility.isRadiant({
const g = isRadiant({
player_slot: meta.slot_to_playerslot[e.slot],
})
? e.gold
: -e.gold;
const x = utility.isRadiant({
const x = isRadiant({
player_slot: meta.slot_to_playerslot[e.slot],
})
? e.xp
Expand All @@ -34,4 +34,4 @@ function processAllPlayers(entries, meta) {
});
return res;
}
module.exports = processAllPlayers;
export default processAllPlayers;
4 changes: 2 additions & 2 deletions processors/processParsedData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const populate = require('./populate');
import populate from './populate.js';

function processParsedData(entries, container, meta) {
for (let i = 0; i < entries.length; i += 1) {
Expand All @@ -8,4 +8,4 @@ function processParsedData(entries, container, meta) {
return container;
}

module.exports = processParsedData;
export default processParsedData;
4 changes: 2 additions & 2 deletions processors/processTeamfights.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const populate = require('./populate');
import populate from './populate.js';

/**
* A processor to compute teamfights that occurred given an event stream
Expand Down Expand Up @@ -135,4 +135,4 @@ function processTeamfights(entries, meta) {
}
return teamfights;
}
module.exports = processTeamfights;
export default processTeamfights;
4 changes: 2 additions & 2 deletions processors/processUploadProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function processUploadProps(entries) {
container.radiant_win = dota.gameWinner_ === 2;
// NOTE: following needs some extraction/transformation
// container.picks_bans = dota.picksBans_;
// require('fs').writeFileSync('./outputEpilogue.json', JSON.stringify(JSON.parse(e.key)));
// fs.writeFileSync('./outputEpilogue.json', JSON.stringify(JSON.parse(e.key)));
break;
case 'interval':
if (!container.player_map[e.player_slot]) {
Expand All @@ -39,4 +39,4 @@ function processUploadProps(entries) {
}
return container;
}
module.exports = processUploadProps;
export default processUploadProps;
46 changes: 23 additions & 23 deletions routes/api.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const express = require('express');
const moment = require('moment');
const async = require('async');
const playerFields = require('./playerFields.json');
const filterDeps = require('../util/filterDeps');
const config = require('../config');
const spec = require('./spec');
const cacheFunctions = require('../store/cacheFunctions');
const db = require('../store/db');
const redis = require('../store/redis');
import { Router } from 'express';
import moment from 'moment';
import { parallel } from 'async';
import playerFields from './playerFields.json';
import filterDeps from '../util/filterDeps.js';
import { ADMIN_ACCOUNT_IDS } from '../config.js';
import spec, { paths } from './spec.js';
import { read } from '../store/cacheFunctions.js';
import { raw } from '../store/db.js';
import { zrevrange, zcard } from '../store/redis.js';

const api = new express.Router();
const api = new Router();
const { subkeys } = playerFields;

const admins = config.ADMIN_ACCOUNT_IDS.split(',').map((e) => Number(e));
const admins = ADMIN_ACCOUNT_IDS.split(',').map((e) => Number(e));

// Player caches middleware
api.use('/players/:account_id/:info?', (req, res, cb) => {
// Check cache
if (!Object.keys(req.query).length && req.params.info) {
return cacheFunctions.read(
return read(
{
key: req.params.info,
account_id: req.params.account_id,
Expand Down Expand Up @@ -107,10 +107,10 @@ api.get('/admin/apiMetrics', (req, res) => {
const startTime = moment().startOf('month').format('YYYY-MM-DD');
const endTime = moment().endOf('month').format('YYYY-MM-DD');

async.parallel(
parallel(
{
topAPI: (cb) => {
db.raw(
raw(
`
SELECT
account_id,
Expand All @@ -136,7 +136,7 @@ api.get('/admin/apiMetrics', (req, res) => {
).asCallback((err, res) => cb(err, err ? null : res.rows));
},
topAPIIP: (cb) => {
db.raw(
raw(
`
SELECT
ip,
Expand All @@ -163,7 +163,7 @@ api.get('/admin/apiMetrics', (req, res) => {
).asCallback((err, res) => cb(err, err ? null : res.rows));
},
numAPIUsers: (cb) => {
db.raw(
raw(
`
SELECT
COUNT(DISTINCT account_id)
Expand All @@ -176,10 +176,10 @@ api.get('/admin/apiMetrics', (req, res) => {
).asCallback((err, res) => cb(err, err ? null : res.rows));
},
topUsersIP: (cb) => {
redis.zrevrange('user_usage_count', 0, 24, 'WITHSCORES', cb);
zrevrange('user_usage_count', 0, 24, 'WITHSCORES', cb);
},
numUsersIP: (cb) => {
redis.zcard('user_usage_count', cb);
zcard('user_usage_count', cb);
},
},
(err, result) => {
Expand All @@ -197,9 +197,9 @@ api.get('/', (req, res) => {
});

// API endpoints
Object.keys(spec.paths).forEach((path) => {
Object.keys(spec.paths[path]).forEach((verb) => {
const { route, func } = spec.paths[path][verb];
Object.keys(paths).forEach((path) => {
Object.keys(paths[path]).forEach((verb) => {
const { route, func } = paths[path][verb];
// Use the 'route' function to get the route path if it's available; otherwise, transform the OpenAPI path to the Express format.
const routePath = route
? route()
Expand All @@ -216,4 +216,4 @@ Object.keys(spec.paths).forEach((path) => {
});
});

module.exports = api;
export default api;
Loading

0 comments on commit 6e13fb2

Please sign in to comment.