Skip to content

Commit

Permalink
add leagues endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Jun 19, 2016
1 parent 98fc634 commit a628f58
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
11 changes: 11 additions & 0 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ module.exports = function(db, redis, cassandra)
res.json(result.rows);
});
});
api.get('/leagues', function(req, res, cb)
{
db.raw(`SELECT * FROM leagues ORDER BY leagueid`).asCallback(function(err, result)
{
if (err)
{
return cb(err);
}
res.json(result.rows);
});
});
api.get('/distributions', function(req, res, cb)
{
queries.getDistributions(redis, function(err, result)
Expand Down
4 changes: 2 additions & 2 deletions sql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ CREATE TABLE picks_bans(
is_pick boolean,
hero_id int,
team smallint,
order smallint,
PRIMARY KEY (match_id, order)
ord smallint,
PRIMARY KEY (match_id, ord)
);

CREATE TABLE leagues(
Expand Down
8 changes: 5 additions & 3 deletions store/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ function insertMatch(db, redis, match, options, cb)

function isProMatch(cb)
{
//TODO check redis/postgres for professional/premium league
match.isProMatch = match.leagueid >= 0;
cb();
redis.sismember('pro_leagueids', match.league_id, function(err, result)
{
match.isProMatch = Boolean(Number(result));
cb(err);
});
}

function upsertMatch(cb)
Expand Down
33 changes: 20 additions & 13 deletions svc/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,38 @@ invokeInterval(function notablePlayers(cb)
}, 10 * 60 * 1000);
invokeInterval(function leagues(cb)
{
utility.getData('https://raw.githubusercontent.com/dotabuff/d2vpkr/master/dota/scripts/items/leagues.json', function(err, leagues)
var container = utility.generateJob("api_leagues",
{});
utility.getData(container.url, function(err, api_leagues)
{
if (err)
{
return cb(err);
}
utility.getData('https://raw.githubusercontent.com/dotabuff/d2vpkr/master/dota/scripts/items/items_game.json', function(err, items)
utility.getData('https://raw.githubusercontent.com/dotabuff/d2vpkr/master/dota/scripts/items/leagues.json', function(err, leagues)
{
if (err)
{
return cb(err);
}
var arr = [];
for (var key in leagues)
async.each(api_leagues.result.leagues, function(l, cb)
{
arr.push(
if (leagues[l.leagueid])
{
leagueid: key,
ticket: leagues[key].ticket,
banner: leagues[key].banner,
tier: leagues[key].tier,
name: items.items_game.items[key].name
});
}
db('leagues').insert(arr).asCallback(cb);
l.tier = leagues[l.leagueid].tier;
l.ticket = leagues[l.leagueid].ticket;
l.banner = leagues[l.leagueid].banner;
}
l.name = l.description.substring("#DOTA_Item_Desc_".length).split('_').join(' ');
if (l.tier === "professional" || l.tier === "premium")
{
redis.sadd('pro_leagueids', l.leagueid);
}
queries.upsert(db, 'leagues', l,
{
leagueid: l.league_id
}, cb);
}, cb);
});
});
}, 10 * 60 * 1000);
Expand Down

0 comments on commit a628f58

Please sign in to comment.