curvefever-stats
Advanced tools
Comparing version 0.0.2 to 0.1.0
33
curve.js
@@ -9,3 +9,3 @@ var async = require('async'); | ||
} | ||
this.league = new League(cachedObj); | ||
this.league = new League(cachedObj || {}); | ||
// TODO: new metricFn needs to wipe this.scores... not ideal | ||
@@ -73,3 +73,32 @@ // how do we know if we changed the metric? | ||
} | ||
cb(null, data); | ||
var res = { | ||
scores: data, | ||
id: id, | ||
maxChange: data.slice().sort(function (x, y) { | ||
return Math.abs(Number(y.rankChange)) - Math.abs(Number(x.rankChange)); | ||
})[0] | ||
}; | ||
if (data[0].teamScore) { | ||
var getTeam = function (forWinners) { | ||
var score = data[forWinners ? 0 : data.length-1].teamScore; | ||
var ps = data.filter(function (s) { | ||
return s.teamScore === score; | ||
}); | ||
return { | ||
score: score, | ||
players: ps, | ||
names: ps.map(function (s) { | ||
return s.name; | ||
}), | ||
sum: ps.reduce(function (acc, s) { | ||
return acc + s.score; | ||
}, 0) | ||
}; | ||
}; | ||
res.teamData = { | ||
winners: getTeam(true), | ||
losers : getTeam(false) | ||
}; | ||
} | ||
cb(null, res); | ||
}); | ||
@@ -76,0 +105,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"author": "Eirik Albrigtsen <analsandblaster@gmail.com>", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -31,7 +31,7 @@ var request = require('request') | ||
try { | ||
lastMatch = $(stats[3]).find('tbody tr td a'); | ||
lastMatch = stats.find('tbody tr td a'); | ||
id = lastMatch.first().attr('href').match(/\match\/(\d*)/)[1] | 0; | ||
} | ||
catch (e) { | ||
cb(e); | ||
cb(new Error('/users/' + player + ' - no matchId found: ' + e.message)); | ||
return; | ||
@@ -38,0 +38,0 @@ } |
@@ -42,2 +42,3 @@ var tap = require('tap') | ||
t.equal(data[5].rankChange, '-4', 'JOSE-PANDA rankchange'); | ||
t.end(); | ||
@@ -44,0 +45,0 @@ }); |
17562
10
414