Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// paginate through to max 500 games if necessary with start_at_match_id=
const parse = urllib.parse(url, true);
parse.query.start_at_match_id = (startId - 1);
parse.search = null;
url = urllib.format(parse);
return getApiMatchPage(player, url, cb);
});
}
const player = job;
if (Number(player.account_id) === 0) {
return cb();
}
// if test or only want last 100 (no paging), set short_history
const heroArray = job.short_history || config.NODE_ENV === 'test' ? ['0'] : Object.keys(constants.heroes);
// use steamapi via specific player history and specific hero id (up to 500 games per hero)
player.match_ids = {};
return async.eachLimit(heroArray, parallelism, (heroId, cb) => {
// make a request for every possible hero
const container = generateJob('api_history', {
account_id: player.account_id,
hero_id: heroId,
matches_requested: 100,
});
getApiMatchPage(player, container.url, (err) => {
console.log('%s matches found', Object.keys(player.match_ids).length);
cb(err);
});
}, (err) => {
player.fh_unavailable = Boolean(err);
if (err) {
func: (req, res, cb) => {
const heroes = {};
// prefill heroes with every hero
Object.keys(constants.heroes).forEach((heroId) => {
const hero = {
hero_id: heroId,
last_played: 0,
games: 0,
win: 0,
with_games: 0,
with_win: 0,
against_games: 0,
against_win: 0,
};
heroes[heroId] = hero;
});
req.queryObj.project = req.queryObj.project.concat('heroes', 'account_id', 'start_time', 'player_slot', 'radiant_win');
queries.getPlayerMatches(req.params.account_id, req.queryObj, (err, cache) => {
if (err) {
return cb(err);
function computeMatchData(pm) {
const selfHero = constants.heroes[pm.hero_id];
// Compute patch based on start_time
if (pm.start_time) {
pm.patch = utility.getPatchIndex(pm.start_time);
}
if (pm.cluster) {
pm.region = constants.cluster[pm.cluster];
}
if (pm.player_slot !== undefined && pm.radiant_win !== undefined) {
pm.isRadiant = isRadiant(pm);
pm.win = Number(isRadiant(pm) === pm.radiant_win);
pm.lose = Number(isRadiant(pm) === pm.radiant_win) ? 0 : 1;
}
if (pm.duration && pm.gold_per_min) {
pm.total_gold = Math.floor((pm.gold_per_min * pm.duration) / 60);
}
if (pm.duration && pm.xp_per_min) {
const Chance = require('chance');
const express = require('express');
const matches = express.Router();
const constants = require('dotaconstants');
const matchPages = constants.match_pages;
const playerSlots = [0, 1, 2, 3, 4, 128, 129, 130, 131, 132];
const item_ids = Object.keys(constants.items);
const hero_ids = Object.keys(constants.heroes);
module.exports = function (db)
{
matches.get('/:player_id/:match_id/:info?', (req, res, cb) => {
console.time('hyperopia generate match');
db.first('personaname')
.from('players')
.where({
account_id: req.params.player_id,
})
.asCallback((err, p) => {
if (err)
{
return cb(err);
}
/**
* Worker checking the GetMatchHistory endpoint to get skill data for matches
* */
const constants = require('dotaconstants');
const async = require('async');
const config = require('../config.js');
const utility = require('../util/utility');
const queries = require('../store/queries');
const { insertMatchSkillCassandra } = queries;
const apiKeys = config.STEAM_API_KEY.split(',');
const parallelism = Math.min(3, apiKeys.length);
const skills = [1, 2, 3];
const heroes = Object.keys(constants.heroes);
const permute = [];
function getPageData(start, options, cb) {
const container = utility.generateJob('api_skill', {
skill: options.skill,
hero_id: options.hero_id,
start_at_match_id: start,
});
utility.getData({
url: container.url,
}, (err, data) => {
if (err) {
return cb(err);
}
if (!data || !data.result || !data.result.matches) {
return getPageData(start, options, cb);
hero_id: ({ field }) => constants.heroes[field],
radiant_win: ({ field, match }) => {
function isRoshHero(pm)
{
const rosh_heroes = {
npc_dota_hero_lycan: 1,
npc_dota_hero_ursa: 1,
npc_dota_hero_troll_warlord: 1,
};
return constants.heroes[pm.hero_id] && (constants.heroes[pm.hero_id].name in rosh_heroes);
}
const playersWithCosmetics = matchResult.players.map((p) => {
const hero = constants.heroes[p.hero_id] || {};
const playerCosmetics = cosmetics.filter(Boolean).filter(c => match.cosmetics[c.item_id] === p.player_slot
&& (!c.used_by_heroes || c.used_by_heroes === hero.name));
return {
...p,
cosmetics: playerCosmetics,
};
});
matchResult = {