From 690a2e9e8e3ec8c86e89f793842ebcde1b656d24 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 24 Jun 2016 08:47:22 +0000 Subject: [PATCH] add drafts/pro_players endpoints --- json/navbar_pages.json | 4 ---- routes/api.js | 49 +++++++++++++++++++++++++++++++++++++++++- store/queries.js | 16 ++++---------- svc/web.js | 12 +---------- 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/json/navbar_pages.json b/json/navbar_pages.json index 6ddb4efd9..d57cb79fa 100644 --- a/json/navbar_pages.json +++ b/json/navbar_pages.json @@ -9,10 +9,6 @@ "benchmarks": { "name": "Benchmarks" }, - "top": { - "name": "Top", - "hide": true - }, "distributions": { "name": "Distributions" }, diff --git a/routes/api.js b/routes/api.js index 4a3311210..e901914fd 100644 --- a/routes/api.js +++ b/routes/api.js @@ -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) @@ -145,6 +146,7 @@ module.exports = function(db, redis, cassandra) res.json(result.rows); }); }); + */ api.get('/pro_matches', function(req, res, cb) { db.raw(` @@ -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) { diff --git a/store/queries.js b/store/queries.js index 05ecb64cd..f2f59a8c6 100644 --- a/store/queries.js +++ b/store/queries.js @@ -198,7 +198,7 @@ function insertMatch(db, redis, match, options, cb) { return cb(err, results.dp); }); - + function decideLogParse(cb) { if (match.leagueid) @@ -451,7 +451,6 @@ function insertMatch(db, redis, match, options, cb) }, cb); } - function decideParse(cb) { if (options.skipParse) @@ -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 @@ -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); }); } @@ -964,7 +956,7 @@ module.exports = { insertMatchSkill, getDistributions, getPicks, - getTop, + getProPlayers, getHeroRankings, getBenchmarks, benchmarkMatch, diff --git a/svc/web.js b/svc/web.js index 13ebd837e..e3182328f 100644 --- a/svc/web.js +++ b/svc/web.js @@ -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) @@ -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");