]> git.sesse.net Git - remoteglot/blobdiff - www/js/book.js
Let book headings be dynamic.
[remoteglot] / www / js / book.js
index bed05c1de71c8011c197842597c81fa73a27f125..dfbc71fab1cb46064fafd994148d9e826f9c3c1b 100644 (file)
@@ -34,6 +34,11 @@ var add_td = function(tr, value) {
        $(td).text(value);
 }
 
        $(td).text(value);
 }
 
+var headings = [
+       "Move", "Games", "%", "Win%", "WWin", "%WW", "Bwin", "%BW", "Draw", "Draw%",
+       "AvWElo", "AvBElo", "EloVar", "AWin%"
+];
+
 var show_lines = function(data, game) {
        var moves = data['moves'];
        $('#numviewers').text(data['opening']);
 var show_lines = function(data, game) {
        var moves = data['moves'];
        $('#numviewers').text(data['opening']);
@@ -43,7 +48,15 @@ var show_lines = function(data, game) {
                total_num += parseInt(move['white']);
                total_num += parseInt(move['draw']);
                total_num += parseInt(move['black']);
                total_num += parseInt(move['white']);
                total_num += parseInt(move['draw']);
                total_num += parseInt(move['black']);
-       }       
+       }
+
+       var headings_tr = $("#headings");
+       headings_tr.empty();
+       for (var i = 0; i < headings.length; ++i) {
+               var th = document.createElement("th");
+               headings_tr.append(th);
+               $(th).text(headings[i]);
+       }
 
        var tbl = $("#lines");
        tbl.empty();
 
        var tbl = $("#lines");
        tbl.empty();
@@ -66,7 +79,7 @@ var show_lines = function(data, game) {
                move_td.appendChild(move_a);
                $(move_a).text(move['move']);
 
                move_td.appendChild(move_a);
                $(move_a).text(move['move']);
 
-               // #.
+               // N.
                var num = white + draw + black;
                add_td(tr, num);
 
                var num = white + draw + black;
                add_td(tr, num);
 
@@ -78,16 +91,36 @@ var show_lines = function(data, game) {
                var win_ratio = (game.turn() == 'w') ? white_win_ratio : 1.0 - white_win_ratio;
                add_td(tr, ((100.0 * win_ratio).toFixed(1) + "%"));
 
                var win_ratio = (game.turn() == 'w') ? white_win_ratio : 1.0 - white_win_ratio;
                add_td(tr, ((100.0 * win_ratio).toFixed(1) + "%"));
 
-               // Elo.
-               add_td(tr, move['white_avg_elo'].toFixed(1));
-               add_td(tr, move['black_avg_elo'].toFixed(1));
-
-               // Win% corrected for Elo.
-               var win_elo = -400.0 * Math.log(1.0 / white_win_ratio - 1.0) / Math.LN10;
-               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 = (game.turn() == 'w') ? white_win_ratio : 1.0 - white_win_ratio;
-               add_td(tr, ((100.0 * win_ratio).toFixed(1) + "%"));
+               // WWin and %WW.
+               add_td(tr, white);
+               add_td(tr, (100.0 * white / num).toFixed(1) + "%");
+
+               // BWin and %BW.
+               add_td(tr, black);
+               add_td(tr, (100.0 * black / num).toFixed(1) + "%");
+
+               // Draw and %Draw.
+               add_td(tr, draw);
+               add_td(tr, ((100.0 * draw / num).toFixed(1) + "%"));
+
+               if (move['num_elo'] >= 10) {
+                       // Elo.
+                       add_td(tr, move['white_avg_elo'].toFixed(1));
+                       add_td(tr, move['black_avg_elo'].toFixed(1));
+                       add_td(tr, (move['white_avg_elo'] - move['black_avg_elo']).toFixed(1));
+
+                       // Win% corrected for Elo.
+                       var win_elo = -400.0 * Math.log(1.0 / white_win_ratio - 1.0) / Math.LN10;
+                       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 = (game.turn() == 'w') ? white_win_ratio : 1.0 - white_win_ratio;
+                       add_td(tr, ((100.0 * win_ratio).toFixed(1) + "%"));
+               } else {
+                       add_td(tr, "");
+                       add_td(tr, "");
+                       add_td(tr, "");
+                       add_td(tr, "");
+               }
 
                if (false) {
                        // Win bars (W/D/B).
 
                if (false) {
                        // Win bars (W/D/B).