From f959fb01dd352412a484a0e473e048fa8e01624d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 29 May 2016 18:40:20 +0200 Subject: [PATCH] Add the derived move data in-place; easier this way. --- www/js/book.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/www/js/book.js b/www/js/book.js index c0227d4..95f423a 100644 --- a/www/js/book.js +++ b/www/js/book.js @@ -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) { -- 2.39.2