Skip to content

Commit

Permalink
add drafts/pro_players endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Jun 24, 2016
1 parent 0165e1e commit 690a2e9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
4 changes: 0 additions & 4 deletions json/navbar_pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"benchmarks": {
"name": "Benchmarks"
},
"top": {
"name": "Top",
"hide": true
},
"distributions": {
"name": "Distributions"
},
Expand Down
49 changes: 48 additions & 1 deletion routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ module.exports = function(db, redis, cassandra)
});
});
*/
/*
api.get('/match_logs/:match_id', function(req, res, cb)
{
db.raw(`SELECT * FROM match_logs WHERE match_id = ? ORDER BY time ASC`, [req.params.match_id]).asCallback(function(err, result)
Expand All @@ -145,6 +146,7 @@ module.exports = function(db, redis, cassandra)
res.json(result.rows);
});
});
*/
api.get('/pro_matches', function(req, res, cb)
{
db.raw(`
Expand All @@ -163,9 +165,54 @@ module.exports = function(db, redis, cassandra)
res.json(result.rows);
});
});
api.get('/pro_players', function(req, res, cb)
{
queries.getProPlayers(db, redis, function(err, result)
{
if (err)
{
return cb(err);
}
res.json(result);
});
});
api.get('/drafts', function(req, res, cb)
{
db.raw(`
SELECT pb.hero_id,
sum(case when ((pm.player_slot < 128) = m.radiant_win) then 1 else 0 end) wins,
sum(case when is_pick is true then 1 else 0 end) picks,
sum(case when is_pick is false then 1 else 0 end) bans
FROM picks_bans pb
LEFT JOIN matches m
ON pb.match_id = m.match_id
LEFT JOIN player_matches pm
ON pb.hero_id = pm.hero_id
AND pm.match_id = m.match_id
GROUP BY pb.hero_id;
`).asCallback(function(err, result)
{
if (err)
{
return cb(err);
}
res.json(result.rows);
});
});
api.get('/pick_order', function(req, res, cb)
{
db.raw(`SELECT hero_id, ord, count( * ) FROM picks_bans WHERE is_pick is true GROUP BY hero_id, ord;`).asCallback(function(err, result)
{
if (err)
{
return cb(err);
}
res.json(result.rows);
});
});
api.get('/leagues', function(req, res, cb)
{
db.raw(`SELECT * FROM leagues ORDER BY leagueid`).asCallback(function(err, result)
db.raw(`SELECT * FROM leagues ORDER BY leagueid DESC`).asCallback(function(err, result)
{
if (err)
{
Expand Down
16 changes: 4 additions & 12 deletions store/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function insertMatch(db, redis, match, options, cb)
{
return cb(err, results.dp);
});

function decideLogParse(cb)
{
if (match.leagueid)
Expand Down Expand Up @@ -451,7 +451,6 @@ function insertMatch(db, redis, match, options, cb)
}, cb);
}


function decideParse(cb)
{
if (options.skipParse)
Expand Down Expand Up @@ -725,7 +724,7 @@ function expectedWin(rates)
return 1 - rates.reduce((prev, curr) => (100 - curr * 100) * prev, 1) / (Math.pow(50, rates.length - 1) * 100);
}

function getTop(db, redis, cb)
function getProPlayers(db, redis, cb)
{
db.raw(`
SELECT * from notable_players
Expand All @@ -735,14 +734,7 @@ function getTop(db, redis, cb)
{
return cb(err);
}
getLeaderboard(db, redis, 'solo_competitive_rank', 500, function(err, result2)
{
return cb(err,
{
notables: result.rows,
leaderboard: result2
});
});
return cb(err, result.rows);
});
}

Expand Down Expand Up @@ -964,7 +956,7 @@ module.exports = {
insertMatchSkill,
getDistributions,
getPicks,
getTop,
getProPlayers,
getHeroRankings,
getBenchmarks,
benchmarkMatch,
Expand Down
12 changes: 1 addition & 11 deletions svc/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,6 @@ app.get('/picks/:n?', function(req, res, cb)
});
});
});
app.get('/top', function(req, res, cb)
{
queries.getTop(db, redis, function(err, result)
{
if (err)
{
return cb(err);
}
res.render('top', result);
});
});
app.get('/rankings/:hero_id?', function(req, res, cb)
{
if (!req.params.hero_id)
Expand Down Expand Up @@ -388,6 +377,7 @@ app.use(function(req, res, next)
{
if (config.UI_HOST)
{
//route not found, redirect to SPA
return res.redirect(config.UI_HOST + req.url);
}
var err = new Error("Not Found");
Expand Down

0 comments on commit 690a2e9

Please sign in to comment.