Permalink
Browse files

prepareHistory added

  • Loading branch information...
1 parent 05859cc commit d6ffe91347a9639476530308695a91ae8bf82b9e @kimdwkimdw committed Feb 5, 2012
Showing with 22 additions and 3 deletions.
  1. +22 −3 index.html
View
@@ -108,6 +108,7 @@ <h1>History</h1>
function makeUserRecords( records ) {
var ret = '<tbody>';
var r = new Array()
+ var best = 0;
for( i in records ) {
records[i].name = i;
var total = 0;
@@ -116,6 +117,7 @@ <h1>History</h1>
total += new Number(records[i][j]);
}
records[i].total = total;
+ if( best < total ) best = total;
r.push(records[i]);
}
r.sort(function(a, b) {
@@ -158,7 +160,7 @@ <h1>History</h1>
var c = r[i];
ret += '<tr class="record">';
- ret += '<td>' + (c.name + "<br />" + c.last_played) + '</td>';
+ ret += '<td>' + (c.name + ' <span class="pull-right best-diff">(' + (addCommas(c.total - best)) + ')</span><br />' + c.last_played) + '</td>';
var played = 0;
for( j in c ) {
@@ -207,11 +209,27 @@ <h1>History</h1>
return ret;
}
- var scoreExtract = function(cell) {
- return new Number($(cell).find('.score').text().replace(',',''));
+ function prepareHistory( history ) {
+ history.sort(function(a,b){return a.date < b.date ? -1 : 1; });
+ var table = {};
+ for( i in history ) {
+ var c = history[i];
+ var key = c.user + ':' + c.music + ':' + c.difficulty;
+ if( typeof(table[key]) === 'undefined' ) {
+ table[key] = 0;
+ }
+ c.score = new Number(c.score);
+ var diff = c.score - table[key];
+ if( diff > 0 ) {
+ table[key] = c.score;
+ }
+ if( diff >= 0 ) diff = '+' + diff;
+ c.score += (' (' + diff + ')');
+ }
}
$.getJSON('http://laika.redfeel.net:4416/?callback=?',function(data){
+
if( typeof(data) === 'undefined' ) return;
var html = '<table class="records">';
@@ -235,6 +253,7 @@ <h1>History</h1>
html = '';
if( typeof(data.history) !== 'undefined' ) {
+ prepareHistory(data.history);
html += makeHistory(data.history);
}
$('#history').append(html);

0 comments on commit d6ffe91

Please sign in to comment.