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 constants = require('dotaconstants');
const utility = require('./utility');
const playerWon = utility.playerWon;
// all items that cost at least 2000
const itemCost = 2000;
const dotaItems = Object.keys(constants.items).map(k => [constants.items[k], k]).filter(x => x[0].cost >= itemCost).map(x => x[1]);
const timings = [7.5, 10, 12, 15, 20, 25, 30].map(x => x * 60);
const gameDurationBucket = [15, 30, 45, 60, 90].map(x => x * 60);
const negativeWords = ['ff', 'report', 'gg', 'end', 'noob'];
const positiveWords = ['gl', 'glhf', 'hf', 'good luck', 'have fun'];
const teamScenariosQueryParams = [
'pos_chat_1min',
'neg_chat_1min',
'courier_kill',
'first_blood',
];
function buildTeamScenario(scenario, isRadiant, match) {
return [{
scenario,
unused_item(m, pm)
{
const result = [];
if (pm.purchase)
{
for (const key in pm.purchase)
{
if (pm.purchase[key] && getGroupedItemUses(key) < 1 && constants.items[key] && isActiveItem(key))
{
// if item has cooldown, consider it usable
result.push(`<img src="${constants.items[key].img}" class="item img-sm" title="${key}">`);
}
}
}
function getGroupedItemUses(key)
{
let total = 0;
for (const key2 in pm.item_uses)
{
if (key === key2 || constants.item_groups.some((g) => {
return (key in g) && (key2 in g);
}))
{
unused_item(m, pm)
{
const result = [];
if (pm.purchase)
{
for (const key in pm.purchase)
{
if (pm.purchase[key] && getGroupedItemUses(key) < 1 && constants.items[key] && isActiveItem(key))
{
// if item has cooldown, consider it usable
result.push(`<img src="${constants.items[key].img}" class="item img-sm" title="${key}">`);
}
}
}
function getGroupedItemUses(key)
{
let total = 0;
for (const key2 in pm.item_uses)
{
if (key === key2 || constants.item_groups.some((g) => {
return (key in g) && (key2 in g);
}))
{
total += pm.item_uses[key];
}
}
function getPatchIndex(startTime) {
const date = new Date(startTime * 1000);
let i;
for (i = 1; i < constants.patch.length; i += 1) {
const pd = new Date(constants.patch[i].date);
// stop when patch date is past the start time
if (pd > date) {
break;
}
}
// use the value of i before the break, started at 1 to avoid negative index
return i - 1;
}
function getPatchIndex(startTime) {
const date = new Date(startTime * 1000);
let i;
for (i = 1; i < constants.patch.length; i += 1) {
const pd = new Date(constants.patch[i].date);
// stop when patch date is past the start time
if (pd > date) {
break;
}
}
// use the value of i before the break, started at 1 to avoid negative index
return i - 1;
}
import patch from 'dotaconstants/build/patch.json';
import region from 'dotaconstants/build/region.json';
import { getPercentWin } from 'utility';
import strings from 'lang';
const patchLookup = {};
patch.forEach((patchElement, index) => {
patchLookup[index] = patchElement.name;
});
const countTypes = {
patch: patchLookup,
region,
is_radiant: {
0: strings.general_dire,
1: strings.general_radiant,
},
};
export default function transformCounts(data) {
const result = {};
Object.keys(data).forEach((key) => {
// Translate each ID to a string
const startTime = mChance.date();
startTime.setFullYear(2017);
const match = {};
match.match_id = req.params.match_id;
match.skill = mChance.weighted([null, 1, 2, 3], [0.1, 0.3, 0.3, 0.3]);
match.radiant_win = mChance.bool();
match.start_time = startTime.getTime() / 1000;
match.duration = mChance.natural({ min: 15, max: 10000 });
match.tower_status_dire = 0; // generateTowers(0, match.radiant_win);
match.tower_status_radiant = 0; // generateTowers(1, match.radiant_win);
match.tower_status_dire = 0;
match.tower_status_radiant = 0;
match.region = mChance.pickone(Object.keys(constants.region).splice(1));
match.lobby_type = mChance.pickone(Object.keys(constants.lobby_type));
match.leagueid = 0;
match.game_mode = mChance.pickone(['1', '2', '3', '4', '5', '12', '13', '22']);
match.picks_bans = null;
match.parse_status = 0;
match.chat = generateChat(mChance.natural({ max: 200 }));
match.teamfights = [];
match.objectives = [];
match.version = 0;
const times = [];
let time = 0;
while (time < match.duration) {
times.push(time);
time += 60;
}