X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=www%2Fjs%2Fbook.js;h=dfbc71fab1cb46064fafd994148d9e826f9c3c1b;hp=bed05c1de71c8011c197842597c81fa73a27f125;hb=b4caee4c2fc467bbfb8263987ff19e7553fe6a3b;hpb=7dfa8135cabec7261a2a255e7b5edd679e75da0b diff --git a/www/js/book.js b/www/js/book.js index bed05c1..dfbc71f 100644 --- a/www/js/book.js +++ b/www/js/book.js @@ -34,6 +34,11 @@ var add_td = function(tr, 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']); @@ -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']); - } + } + + 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(); @@ -66,7 +79,7 @@ var show_lines = function(data, game) { move_td.appendChild(move_a); $(move_a).text(move['move']); - // #. + // N. 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) + "%")); - // 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).