Skip to content

Instantly share code, notes, and snippets.

@tonybruess
Forked from wedtm/gist:1442170
Created December 30, 2011 17:12
Show Gist options
  • Save tonybruess/1540642 to your computer and use it in GitHub Desktop.
Save tonybruess/1540642 to your computer and use it in GitHub Desktop.
r.exists(key, function(err, obj) {
var total;
if (obj !== 1) return;
total = 0;
r.llen(key, function(err, obj) {
return total = parseInt(obj);
});
return r.lrange(key, 1, -1, function(err, checks) {
var check, good, _fn, _i, _len;
good = 0;
_fn = function(check) {
var data;
data = JSON.parse(check);
if (data.result === true) return good = good + 1;
};
for (_i = 0, _len = checks.length; _i < _len; _i++) {
check = checks[_i];
_fn(check);
}
server.percentage = (good / total * 100) / 100;
if (new Date(server.created_at).getTime() > new Date().getTime() - 604800) {
rank = rank - 1;
}
rank = rank * server.percentage;
if (server.votes > 0) rank = rank + (server.votes * 0.015);
if (server.premium) rank = rank * 1.1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment