]> git.sesse.net Git - remoteglot-book/blobdiff - www/js/book.js
Add the derived move data in-place; easier this way.
[remoteglot-book] / www / js / book.js
index c0227d4646665b8a548e602504e50156c3f30043..95f423abf944dd34aa1226a2046c87f3740d22e0 100644 (file)
@@ -163,7 +163,7 @@ var show_lines = function(data, game) {
                var move = moves[i];
                var line = [];
 
-               var derived = calc_move_derived_data(move, total_num, data, (move_override % 2 == 0));
+               calc_move_derived_data(move, total_num, data, (move_override % 2 == 0));
 
                var white = move['white'];
                var draw = move['draw'];
@@ -172,18 +172,18 @@ var show_lines = function(data, game) {
 
                line.push(move['move']);  // Move.
                transpose_only.push(move['transpose_only']);
-               line.push(derived['num']);  // N.
-               line.push(derived['fraction']);  // %.
+               line.push(move['num']);  // N.
+               line.push(move['fraction']);  // %.
                line.push(computer);  // CGames.
-               line.push(derived['human_index']);  // Hum.
-               line.push(derived['win_ratio']);  // Win%.
+               line.push(move['human_index']);  // Hum.
+               line.push(move['win_ratio']);  // Win%.
 
-               line.push(white);                   // WWin.
-               line.push(white / derived['num']);  // %WW.
-               line.push(black);                   // BWin.
-               line.push(black / derived['num']);  // %BW.
-               line.push(draw);                    // Draw.
-               line.push(draw / derived['num']);   // %Draw.
+               line.push(white);                // WWin.
+               line.push(white / move['num']);  // %WW.
+               line.push(black);                // BWin.
+               line.push(black / move['num']);  // %BW.
+               line.push(draw);                 // Draw.
+               line.push(draw / move['num']);   // %Draw.
 
                if (move['num_elo'] >= 10) {
                        // Elo.
@@ -196,7 +196,7 @@ var show_lines = function(data, game) {
                        line.push(null);
                }
 
-               line.push(derived['corrected_win_ratio'] || null);
+               line.push(move['corrected_win_ratio'] || null);
                lines.push(line);
        }
 
@@ -273,24 +273,23 @@ var find_total_games = function(moves) {
 }
 
 var calc_move_derived_data = function(move, total_num, data, is_white) {
-       var derived = {};
        var white = move['white'];
        var draw = move['draw'];
        var black = move['black'];
        var computer = move['computer'];
 
        var num = white + draw + black;
-       derived['num'] = num;
-       derived['fraction'] = num / total_num;
+       move['num'] = num;
+       move['fraction'] = num / total_num;
 
        // Adjust so that the human index is 50% overall.
        var exp = Math.log(0.5) / Math.log(data['computer_games'] / data['total_games']);
-       derived['human_index'] = 1.0 - Math.pow(computer / num, exp);
+       move['human_index'] = 1.0 - Math.pow(computer / num, exp);
 
        // Win%.
        var white_win_ratio = (white + 0.5 * draw) / num;
        var win_ratio = is_white ? white_win_ratio : 1.0 - white_win_ratio;
-       derived['win_ratio'] = win_ratio;
+       move['win_ratio'] = win_ratio;
 
        if (move['num_elo'] >= 10) {
                // Win% corrected for Elo.
@@ -298,10 +297,8 @@ var calc_move_derived_data = function(move, total_num, data, is_white) {
                win_elo -= (move['white_avg_elo'] - move['black_avg_elo']);
                white_win_ratio = 1.0 / (1.0 + Math.pow(10, win_elo / -400.0));
                win_ratio = is_white ? white_win_ratio : 1.0 - white_win_ratio;
-               derived['corrected_win_ratio'] = win_ratio;
+               move['corrected_win_ratio'] = win_ratio;
        }
-
-       return derived;
 };
 
 var set_includetransp = function(value) {