Skip to content

Commit

Permalink
Merge pull request odota#108 from albertcui/ardm
Browse files Browse the repository at this point in the history
Ardm

Former-commit-id: 9905ea2
  • Loading branch information
albertcui committed Jan 8, 2015
2 parents 93d0c04 + ca5025f commit 27b1d92
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 169 deletions.
48 changes: 40 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ var playerPages = {
name: "Teammates"
}
}
utility.constants.findOne({}, function(err, doc) {
app.locals.constants = doc
})
app.listen(port, function() {
logger.info("[WEB] listening on port %s", port)
})
Expand Down Expand Up @@ -121,12 +124,6 @@ app.use(session({
}))
app.use(passport.initialize())
app.use(passport.session()) // persistent login
app.use(function(req, res, next) {
utility.constants.findOne({}, function(err, doc) {
app.locals.constants = doc
next()
})
})
app.param('match_id', function(req, res, next, id) {
cache.get(req.url, function(err, reply) {
if (err || !reply || process.env.NODE_ENV != "production") {
Expand Down Expand Up @@ -202,7 +199,42 @@ app.route('/matches/:match_id/:info?').get(function(req, res, next) {
if (!matchPages[info]) {
return next()
}
if (info == "graphs") {
if (match.parsed_data) {
//loop through all heroes
//look up corresponding hero_id
//find player slot associated with that unit(hero_to_slot)
//merge into player's primary hero
for (var key in match.parsed_data.heroes) {
var val = match.parsed_data.heroes[key]
if (app.locals.constants.hero_names[key]) {
var hero_id = app.locals.constants.hero_names[key].id;
var slot = match.parsed_data.hero_to_slot[hero_id]
if (slot) {
var primary = match.players[slot].hero_id
var primary_name = app.locals.constants.heroes[primary].name
var merge = match.parsed_data.heroes[primary_name]
if (key !== primary_name) {
for (var attr in val) {
if (val[attr].constructor === Array) {
merge[attr]=merge[attr].concat(val[attr])
}
else {
for (var attr2 in val[attr]) {
if (!merge[attr][attr2]) {
merge[attr][attr2] = val[attr][attr2]
}
else {
merge[attr][attr2] += val[attr][attr2]
}
}
}
}
}
}
}
}
}
if (info === "graphs") {
if (match.parsed_data) {
//compute graphs
var goldDifference = ['Gold']
Expand Down Expand Up @@ -380,4 +412,4 @@ app.use(function(req, res) {
if (process.env.NODE_ENV == "production") {
res.status(404).render('404.jade');
}
});
});
45 changes: 25 additions & 20 deletions backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var async = require("async"),
cheerio = require('cheerio'),
winston = require('winston'),
reds = require('reds');
var kue = utility.kue;
var jobs = utility.jobs;
var api_url = "https://api.steampowered.com/IDOTA2Match_570"
var summaries_url = "http://api.steampowered.com/ISteamUser"
Expand Down Expand Up @@ -148,6 +147,8 @@ function updateConstants(cb) {
for (var key in abilities) {
abilities[key].img = "http://cdn.dota2.com/apps/dota2/images/abilities/" + key + "_md.png"
}
abilities["nevermore_shadowraze2"] = abilities["nevermore_shadowraze1"];
abilities["nevermore_shadowraze3"] = abilities["nevermore_shadowraze1"];
abilities["stats"] = {
dname: "Stats",
img: '../../public/images/Stats.png',
Expand Down Expand Up @@ -256,7 +257,7 @@ function requestDetails(match, cb) {
queueReq("api", match)
}
cb(null)
})
});
}

function getMatchPage(url, cb) {
Expand Down Expand Up @@ -285,6 +286,10 @@ function getMatchPage(url, cb) {

function apiRequest(job, cb) {
var payload = job.data.payload;
if (!job.data.url) {
logger.info(job);
cb("no url")
}
getData(job.data.url, function(err, data) {
if (data.response) {
//summaries response
Expand All @@ -293,42 +298,42 @@ function apiRequest(job, cb) {
});
}
else if (data.result.error || data.result.status == 2) {
//error response from dota api
logger.info(data);
return cb(data);
}
else if (payload.match_id) {
var match = data.result
//response for single match details
var match = data.result;
insertMatch(match, function(err) {
cb(err);
})
});
}
else {
var resp = data.result.matches
if (payload.account_id) {
async.map(resp, function(match, cb) {
requestDetails(match, function(err) {
cb(err)
})
}, function(err) {
cb(err)
})
}
else if (payload.account_id) {
//response for match history for single player
var resp = data.result.matches;
async.map(resp, function(match, cb2) {
requestDetails(match, function(err) {
cb2(err);
});
}, function(err) {
cb(err);
});
}
})
});
}

function insertMatch(match, cb) {
var track = match.players.some(function(element) {
return (element.account_id in trackedPlayers)
return (element.account_id in trackedPlayers);
})
match.parse_status = (track ? 0 : 3)
if (process.env.SAVE_ALL_MATCHES || track) {
matches.insert(match);
}
if (track) {
//todo get player summaries separately
var summaries = {
summaries_id: 1
summaries_id: new Date()
}
var steamids = []
match.players.forEach(function(player) {
Expand Down Expand Up @@ -370,4 +375,4 @@ function getData(url, cb) {
cb(null, JSON.parse(body))
}
})
}
}
3 changes: 0 additions & 3 deletions parser/src/main/java/albert/stats/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,6 @@ else if (name.equals("CUserMsg_SayText2")){
doc.getJSONArray("chat").put(entry);
continue;
}
if (type.equals("kills")){
doc.getJSONArray("kills").put(entry);
}
JSONObject heroes = doc.getJSONObject("heroes");
String unit = entry.getString("unit");
if (!heroes.has(unit)){
Expand Down
131 changes: 131 additions & 0 deletions public/js/map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
$(document).on('ready', function() {

var buildingData = [{
id: "t4br",
style: "position: absolute; top: 78%; left: 17%;"
}, {
id: "t4tr",
style: "position: absolute; top: 77%; left: 15%;"
}, {
id: "t3br",
style: "position: absolute; top: 86%; left: 26%;"
}, {
id: "t2br",
style: "position: absolute; top: 86%; left: 43%;"
}, {
id: "t1br",
style: "position: absolute; top: 86%; left: 80%;"
}, {
id: "t3mr",
style: "position: absolute; top: 72%; left: 22%;"
}, {
id: "t2mr",
style: "position: absolute; top: 64%; left: 30%;"
}, {
id: "t1mr",
style: "position: absolute; top: 56%; left: 38%;"
}, {
id: "t3tr",
style: "position: absolute; top: 67%; left: 9%;"
}, {
id: "t2tr",
style: "position: absolute; top: 50%; left: 9%;"
}, {
id: "t1tr",
style: "position: absolute; top: 40%; left: 9%;"
}, {
id: "brbr",
style: "position: absolute; top: 85%; left: 24%;"
}, {
id: "bmbr",
style: "position: absolute; top: 87%; left: 24%;"
}, {
id: "brmr",
style: "position: absolute; top: 73%; left: 18%;"
}, {
id: "bmmr",
style: "position: absolute; top: 74%; left: 20%;"
}, {
id: "brtr",
style: "position: absolute; top: 69%; left: 8%;"
}, {
id: "bmtr",
style: "position: absolute; top: 69%; left: 10%;"
}, {
id: "t4bd",
style: "position: absolute; top: 19%; left: 83%;"
}, {
id: "t4td",
style: "position: absolute; top: 18%; left: 81%;"
}, {
id: "t3bd",
style: "position: absolute; top: 31%; left: 87%;"
}, {
id: "t2bd",
style: "position: absolute; top: 45%; left: 87%;"
}, {
id: "t1bd",
style: "position: absolute; top: 60%; left: 87%;"
}, {
id: "t3md",
style: "position: absolute; top: 27%; left: 73%;"
}, {
id: "t2md",
style: "position: absolute; top: 37%; left: 63%;"
}, {
id: "t1md",
style: "position: absolute; top: 47%; left: 53%;"
}, {
id: "t3td",
style: "position: absolute; top: 13%; left: 70%;"
}, {
id: "t2td",
style: "position: absolute; top: 13%; left: 50%;"
}, {
id: "t1td",
style: "position: absolute; top: 13%; left: 20%;"
}, {
id: "brbd",
style: "position: absolute; top: 29%; left: 86%;"
}, {
id: "bmbd",
style: "position: absolute; top: 29%; left: 88%;"
}, {
id: "brmd",
style: "position: absolute; top: 25%; left: 74%;"
}, {
id: "bmmd",
style: "position: absolute; top: 26%; left: 76%;"
}, {
id: "brtd",
style: "position: absolute; top: 12%; left: 72%;"
}, {
id: "bmtd",
style: "position: absolute; top: 14%; left: 72%;"
}, {
id: "ar",
style: "position: absolute; top: 79%; left: 12%;"
}, {
id: "ad",
style: "position: absolute; top: 14%; left: 83%;"
}]
var bits = pad(Number($('#map').attr('data-tower-radiant')).toString(2), 11)
bits += pad(Number($('#map').attr('data-barracks-radiant')).toString(2), 6)
bits += pad(Number($('#map').attr('data-tower-dire')).toString(2), 11)
bits += pad(Number($('#map').attr('data-barracks-dire')).toString(2), 6)
bits += $('#map').attr('data-radiant-win') === "1" ? "10" : "01"
console.log(bits)
//concat, iterate through bits of all four status values
//if 1, create image
//building data in correct order
//determine ancient display by match winner
for (var i = 0; i < bits.length; i++) {
var d = buildingData[i]
d.src = 'https://raw.githubusercontent.com/kronusme/dota2-api/master/images/map/'
d.src += buildingData[i].id.slice(0, 1) === "t" ? 'tower' : 'racks'
d.src += buildingData[i].id.slice(-1) === "r" ? '_radiant.png' : '_dire.png'
d.class = buildingData[i].id.slice(0, 1) === "a" ? "" : "icon"
d.style += bits[i] === "1" ? "" : "-webkit-filter: grayscale(100%);"
$('#map').append(($('<img>', d)))
}
})
Loading

0 comments on commit 27b1d92

Please sign in to comment.