Skip to content

Commit

Permalink
fix getmatchrating for cacher
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed May 28, 2016
1 parent 436f533 commit 30c1046
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
31 changes: 1 addition & 30 deletions store/buildMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var queries = require('./queries');
var compute = require('../util/compute');
var utility = require('../util/utility');
var benchmarkMatch = queries.benchmarkMatch;
var getMatchRating = queries.getMatchRating;
var computeMatchData = compute.computeMatchData;
var renderMatch = compute.renderMatch;
var deserialize = utility.deserialize;
Expand Down Expand Up @@ -231,34 +232,4 @@ function getMatch(db, redis, match_id, options, cb)
}
}
}

function getMatchRating(redis, match, cb)
{
async.map(match.players, function(player, cb)
{
if (!player.account_id)
{
return cb();
}
redis.zscore('solo_competitive_rank', player.account_id, cb);
}, function(err, result)
{
if (err)
{
return cb(err);
}
var filt = result.filter(function(r)
{
return r;
});
var avg = ~~(filt.map(function(r)
{
return Number(r);
}).reduce(function(a, b)
{
return a + b;
}, 0) / filt.length);
cb(err, avg);
});
}
module.exports = buildMatch;
31 changes: 31 additions & 0 deletions store/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,36 @@ function benchmarkMatch(redis, m, cb)
}, cb);
}

function getMatchRating(redis, match, cb)
{
async.map(match.players, function(player, cb)
{
if (!player.account_id)
{
return cb();
}
redis.zscore('solo_competitive_rank', player.account_id, cb);
}, function(err, result)
{
if (err)
{
return cb(err);
}
var filt = result.filter(function(r)
{
return r;
});
var avg = ~~(filt.map(function(r)
{
return Number(r);
}).reduce(function(a, b)
{
return a + b;
}, 0) / filt.length);
cb(err, avg);
});
}

function getDistributions(redis, cb)
{
var keys = ["distribution:mmr", "distribution:country_mmr"];
Expand Down Expand Up @@ -862,6 +892,7 @@ module.exports = {
getHeroRankings,
getBenchmarks,
benchmarkMatch,
getMatchRating,
upsert,
getLeaderboard,
mmrEstimate,
Expand Down
20 changes: 4 additions & 16 deletions svc/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ var sessOptions = {
app.use(session(sessOptions));
app.use(passport.initialize());
app.use(passport.session());
app.use(function(req, res, next)
{
if (req.headers.host.match(/^www/) !== null)
{
res.redirect(req.protocol + '://' + req.headers.host.replace(/^www\./, '') + req.url);
}
else
{
next();
}
});
app.use(function rateLimit(req, res, cb)
{
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || "";
Expand Down Expand Up @@ -219,11 +208,6 @@ app.use('/api', api(db, redis, cassandra));
//TODO remove these with SPA
app.route('/').get(function(req, res, next)
{
if (config.UI_HOST)
{
return res.redirect(config.UI_HOST);
}
//TODO remove this with SPA
if (req.user)
{
res.redirect('/players/' + req.user.account_id);
Expand Down Expand Up @@ -403,6 +387,10 @@ app.use('/', mmstats(redis));
app.use('/', donate(db, redis));
app.use(function(req, res, next)
{
if (config.UI_HOST)
{
return res.redirect(config.UI_HOST + req.url);
}
var err = new Error("Not Found");
err.status = 404;
return next(err);
Expand Down

0 comments on commit 30c1046

Please sign in to comment.