From 446cd5cf4e631bb42a526c678571d82e4c626c55 Mon Sep 17 00:00:00 2001 From: Bitnami Date: Mon, 9 Nov 2015 22:43:11 -0500 Subject: [PATCH] changed env vars to enable, actually fixes #722 --- .env_example | 4 +--- compute.js | 1 - config.js | 11 +++++------ java_parser/src/main/java/yasp/Main.java | 13 ++++++++++--- queries.js | 9 ++------- scanner.js | 2 +- utility.js | 3 ++- views/mixins/ads.jade | 2 +- views/request.jade | 3 +-- web.js | 2 +- workParser.js | 18 +++++++++++------- workServer.js | 1 - worker.js | 2 ++ 13 files changed, 37 insertions(+), 34 deletions(-) diff --git a/.env_example b/.env_example index 01f3f2c01..afd005549 100644 --- a/.env_example +++ b/.env_example @@ -1,5 +1,3 @@ STEAM_USER=REPLACE_THIS STEAM_PASS=REPLACE_THIS -STEAM_API_KEY=REPLACE_THIS -DISABLE_RECAPTCHA=1 -DISABLE_ADS=1 \ No newline at end of file +STEAM_API_KEY=REPLACE_THIS \ No newline at end of file diff --git a/compute.js b/compute.js index 63e24de62..9da3b5173 100644 --- a/compute.js +++ b/compute.js @@ -25,7 +25,6 @@ function computeMatchData(match) { **/ function computePlayerMatchData(player_match) { computeMatchData(player_match); - console.log(player_match.patch); player_match.player_win = (isRadiant(player_match) === player_match.radiant_win); //did the player win? player_match.isRadiant = isRadiant(player_match); player_match.total_gold = ~~(player_match.gold_per_min * player_match.duration / 60); diff --git a/config.js b/config.js index d70e18493..da0e41500 100644 --- a/config.js +++ b/config.js @@ -32,13 +32,12 @@ var defaults = { "PROXY_URLS": "", //comma separated list of proxy urls to use "STEAM_API_HOST": "api.steampowered.com", "ROLE": "", //for specifying a node type - "DISABLE_RECAPTCHA": "", // set to disable the recaptcha on the Request page, - "DISABLE_PRO_PARSING": "", // set to disable parsing pro matches from sequential API - "DISABLE_ADS": "", //disable ads - "PARSER_PARALLELISM": 8, "MMSTATS_DATA_INTERVAL": 3, //minutes between requests for MMStats data - "ENABLE_MATCH_CACHE": "", - "ENABLE_PLAYER_CACHE": "", + "ENABLE_RECAPTCHA": "", // set to disable the recaptcha on the Request page, + "ENABLE_ADS": "", //disable ads + "ENABLE_PRO_PARSING": "", // set to parse pro matches from sequential API + "ENABLE_MATCH_CACHE": "", // set to enable caching matches + "ENABLE_PLAYER_CACHE": "", // set to enable caching players //the following are deprecated "PARSER_HOST": "localhost:5200", "MONGO_URL": "mongodb://localhost/dota", diff --git a/java_parser/src/main/java/yasp/Main.java b/java_parser/src/main/java/yasp/Main.java index c6e2a6927..ed7d108e4 100644 --- a/java_parser/src/main/java/yasp/Main.java +++ b/java_parser/src/main/java/yasp/Main.java @@ -254,10 +254,17 @@ public void onTickStart(Context ctx, boolean synthetic) { while (added < numPlayers && i < 100) { //check each m_vecPlayerData to ensure the player's team is radiant or dire int playerTeam = getEntityProperty(pr, "m_vecPlayerData.%i.m_iPlayerTeam", i); - //Long steamid = getEntityProperty(pr, "m_vecPlayerData.%i.m_iPlayerSteamID", i); - //System.err.format("%s: %s: %s\n", i, playerTeam, steamid); + int teamSlot = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_iTeamSlot", i); + Long steamid = getEntityProperty(pr, "m_vecPlayerData.%i.m_iPlayerSteamID", i); + //System.err.format("%s %s %s: %s\n", i, playerTeam, teamSlot, steamid); if (playerTeam == 2 || playerTeam == 3) { - //if so, add it to validIndices, add 1 to added + //output the player_slot based on team and teamslot + Entry entry = new Entry(time); + entry.type = "player_slot"; + entry.key = String.valueOf(added); + entry.value = (playerTeam == 2 ? 0 : 128) + teamSlot; + es.output(entry); + //add it to validIndices, add 1 to added validIndices[added] = i; added += 1; } diff --git a/queries.js b/queries.js index cdc92a322..52770e994 100644 --- a/queries.js +++ b/queries.js @@ -89,11 +89,6 @@ function getColumnInfo(db, cb) { function insertMatch(db, redis, queue, match, options, cb) { var players = match.players ? JSON.parse(JSON.stringify(match.players)) : undefined; - if (players) { - players.sort(function(a, b) { - return a.player_slot - b.player_slot; - }); - } delete match.players; //options specify api, parse, or skill //we want to insert into matches, then insert into player_matches for each entry in players @@ -265,11 +260,11 @@ function insertMatch(db, redis, queue, match, options, cb) { return cb(); } else { - //slot to id map so after parse we can figure out the player ids for each slot + //slot to id map so after parse we can figure out the player ids for each slot (for caching update without db read) //do this at the end so it doesn't get deleted during match insertion step if (players) { match.slot_to_id = {}; - players.forEach(function(p) { + players.forEach(function(p, i) { match.slot_to_id[p.player_slot] = p.account_id; }); } diff --git a/scanner.js b/scanner.js index 84c8c278a..54ccd4828 100644 --- a/scanner.js +++ b/scanner.js @@ -75,7 +75,7 @@ function scanApi(seq_num) { } logger.info("[API] seq_num:%s, matches:%s", seq_num, resp.length); async.each(resp, function(match, cb) { - if (match.leagueid && !config.DISABLE_PRO_PARSING) { + if (match.leagueid && config.ENABLE_PRO_PARSING) { //parse tournament games match.parse_status = 0; } diff --git a/utility.js b/utility.js index d384cdc2e..0456d0e3c 100644 --- a/utility.js +++ b/utility.js @@ -271,7 +271,7 @@ function mode(array) { function getParseSchema() { return { - "version": 14, + "version": 15, "match_id": 0, "teamfights": [], "objectives": [], @@ -280,6 +280,7 @@ function getParseSchema() { "radiant_xp_adv": [], "players": Array.apply(null, new Array(10)).map(function() { return { + "player_slot": 0, "stuns": 0, "max_hero_hit": { value: 0 diff --git a/views/mixins/ads.jade b/views/mixins/ads.jade index 6d4c55142..5ecf57fb7 100644 --- a/views/mixins/ads.jade +++ b/views/mixins/ads.jade @@ -1,5 +1,5 @@ mixin ad(type) - if !(user && user.cheese) && !config.DISABLE_ADS + if !(user && user.cheese) && config.ENABLE_ADS if type==="banner1" script. //check adblocker diff --git a/views/request.jade b/views/request.jade index b04132c1e..220aa130a 100644 --- a/views/request.jade +++ b/views/request.jade @@ -14,10 +14,9 @@ block content .form-group input#match_id.form-control(type='text' name='match_id' placeholder='Match ID') .form-group - if !config.DISABLE_RECAPTCHA + if config.ENABLE_RECAPTCHA .g-recaptcha#recaptcha(data-sitekey=rc_public, data-theme="dark", data-callback="submit") else - // if the DISABLE_RECAPTCHA env var has been set, bypass the recaptcha button.btn.btn-default(onclick="submit()") Request Parse #progContainer(style="display:none") img(src="/public/images/loading.gif", style="display:none")#loading diff --git a/web.js b/web.js index 93b1d248d..0b5528f33 100644 --- a/web.js +++ b/web.js @@ -326,7 +326,7 @@ app.route('/request_job').post(function(req, res) { } var match_id = req.body.match_id; match_id = Number(match_id); - if (!body.success && !config.DISABLE_RECAPTCHA) { + if (!body.success && config.ENABLE_RECAPTCHA) { console.log('failed recaptcha'); res.json({ error: "Recaptcha Failed!" diff --git a/workParser.js b/workParser.js index 686dc4a2a..0095d8bf8 100644 --- a/workParser.js +++ b/workParser.js @@ -81,10 +81,8 @@ function getJob() { } console.log(job); if (job.jobId && job.data && job.data.payload && job.data.payload.url) { - var payload = job.data.payload; - var url = job.data.payload.url; - console.log("got work from server, jobid: %s, url: %s", job.jobId, url); - runParse(payload, function(err, parsed_data) { + console.log("got work from server, jobid: %s, url: %s", job.jobId, job.data.payload.url); + runParse(job.data.payload, function(err, parsed_data) { if (err) { console.error("error occurred on parse: %s", err); parsed_data = { @@ -118,9 +116,9 @@ function getJob() { }); } -function runParse(data, cb) { +function runParse(match, cb) { var print_multi_kill_streak_debugging = false; - var url = data.url; + var url = match.url; var error = "incomplete"; var inStream; var parseStream; @@ -130,7 +128,7 @@ function runParse(data, cb) { var entries = []; var hero_to_slot = {}; var hero_to_id = {}; - var curr_player_hero = {}; + //var curr_player_hero = {}; var game_zero = 0; var curr_teamfight; var teamfights = []; @@ -153,6 +151,10 @@ function runParse(data, cb) { } }; var types = { + "player_slot": function(e) { + parsed_data.players[e.key].player_slot = e.value; + console.log(e); + }, "match_id": function(e) { parsed_data.match_id = e.value; }, @@ -685,6 +687,8 @@ function runParse(data, cb) { xptotal -= p.xp_t[i]; goldtotal -= p.gold_t[i]; } + //use player slot to id mapping sent from server to fill in account_ids (for determining player cache updates on insert) + p.account_id = match.slot_to_id[p.player_slot]; }); parsed_data.radiant_gold_adv.push(goldtotal); parsed_data.radiant_xp_adv.push(xptotal); diff --git a/workServer.js b/workServer.js index e89310ab3..f7632a69d 100644 --- a/workServer.js +++ b/workServer.js @@ -79,7 +79,6 @@ function start() { match[key] = match[key] || parsed_data[key]; } match.players.forEach(function(p, i) { - p.player_slot = i < match.players.length / 2 ? i : i + (128 - 5); p.account_id = match.slot_to_id[p.player_slot]; }); match.parse_status = 2; diff --git a/worker.js b/worker.js index db33af81b..934c0bce5 100644 --- a/worker.js +++ b/worker.js @@ -71,6 +71,8 @@ function processApi(job, cb) { clearInterval(poll); return cb("failed"); } + }).catch(function(err) { + return cb(err); }); }); }, 2000);