From bf8967f56123981223ba78ede27e29d4d641095f Mon Sep 17 00:00:00 2001 From: Marc LeBlanc Date: Tue, 16 Oct 2018 20:57:16 -0400 Subject: [PATCH 1/5] UI Ready --- web/css/style.css | 11 ++++++++++- web/index.html | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/web/css/style.css b/web/css/style.css index 9af5868..c93a0b4 100644 --- a/web/css/style.css +++ b/web/css/style.css @@ -111,8 +111,17 @@ h1 { .elo-player { text-align: center; color: white; - font-size: 100px; + font-size: 120px; padding-left: 18% !important; + font-weight: bold; +} + +.compare-elo-player { + text-align: center; + color: white; + font-size: 110px; + padding-left: 21% !important; + font-weight: normal; } .img-flag { diff --git a/web/index.html b/web/index.html index 2755c32..15d4a35 100644 --- a/web/index.html +++ b/web/index.html @@ -64,6 +64,11 @@

Joueur 2 +
+
4/-5
+
5/-4
+
+ From 9c4597a2fea711adcc6bd7e572755dbaa0709662 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc Date: Tue, 16 Oct 2018 23:15:54 -0400 Subject: [PATCH 2/5] Feature done, little glitch at calculation --- web/index.html | 4 ++-- web/js/script.js | 2 ++ web/js/stats.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/web/index.html b/web/index.html index 15d4a35..2eb6dfb 100644 --- a/web/index.html +++ b/web/index.html @@ -65,8 +65,8 @@

Joueur 2 -
4/-5
-
5/-4
+
+
diff --git a/web/js/script.js b/web/js/script.js index 7acff27..c5d1dc7 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -61,12 +61,14 @@ $("#view-main-menu").show(); $("#view-in-game").hide(); $("#row-elo").hide(); + $("#row-compare-elo").hide(); break; case 10: case 20: $("#view-main-menu").hide(); $("#view-in-game").show(); $("#row-elo").show(); + $("#row-compare-elo").show(); break; default: break; diff --git a/web/js/stats.js b/web/js/stats.js index b8f2dad..ffeac91 100644 --- a/web/js/stats.js +++ b/web/js/stats.js @@ -23,6 +23,7 @@ var _idLastGame = 0; var _longestGameInfo = { maxScores: 0 }; var _lastShutoutInfo = { date: 0 }; +var _state = 0; // ELO configuration var INITIAL_ELO = 1000; @@ -515,7 +516,8 @@ function getMinimumGamesForRanking() { return MINIMUM_GAMES_FOR_RANKING; } -function applyEloTemplateInGame() { +function applyEloTemplateInGame(state) { + console.log("CALLED!"); var eloTemplate = 'PLAYERELO'; var rankingTemplate = ''; var idPlayer1 = $("#elo-player-1").attr("data-id-player1-elo"); @@ -543,6 +545,51 @@ function applyEloTemplateInGame() { $("#elo-player-1").html(player1Template); $("#elo-player-2").html(player2Template); + + // Show ELO comparison + var nbGamesPlayer1 = _state == 10 ? player1Temp.elo_games : player1Temp.elo_games - 1 + var nbGamesPlayer2 = _state == 10 ? player2Temp.elo_games : player2Temp.elo_games - 1 + var nextKValuePlayer1 = nbGamesPlayer1 < getMinimumGamesForRanking() ? UNRANKED_COEFFICIENT : RANKED_COEFFICIENT; + var nextKValuePlayer2 = nbGamesPlayer2 < getMinimumGamesForRanking() ? UNRANKED_COEFFICIENT : RANKED_COEFFICIENT; + var arrNextElos = getNextElo(player1Temp.elo, player2Temp.elo, nextKValuePlayer1, nextKValuePlayer2); + + player1Temp.diffPlusElo = Math.round(arrNextElos[0]); + player1Temp.diffMinusElo = Math.round(0 - arrNextElos[1]); + player2Temp.diffPlusElo = Math.round(arrNextElos[1]); + player2Temp.diffMinusElo = Math.round(0 - arrNextElos[0]); + + console.log(player1Temp); + console.log(player2Temp); + + var eloComparisonTemplate = 'COMPAREELOPLUS/COMPAREELOMINUS'; + + // Player 1 + var player1CompareEloTemplate = eloComparisonTemplate; + player1CompareEloTemplate = player1CompareEloTemplate.replace(/COMPAREELOPLUS/g, player1Temp.diffPlusElo); + player1CompareEloTemplate = player1CompareEloTemplate.replace(/COMPAREELOMINUS/g, player1Temp.diffMinusElo); + + // Player 2 + var player2CompareEloTemplate = eloComparisonTemplate; + player2CompareEloTemplate = player2CompareEloTemplate.replace(/COMPAREELOPLUS/g, player2Temp.diffPlusElo); + player2CompareEloTemplate = player2CompareEloTemplate.replace(/COMPAREELOMINUS/g, player2Temp.diffMinusElo); + + $ ("#compare-elo-player-1").html(player1CompareEloTemplate); + $ ("#compare-elo-player-2").html(player2CompareEloTemplate); +} + +function getNextElo(initialEloPlayer1, initialEloPlayer2, kValuePlayer1, kValuePlayer2) { + // Ranking difference (D) + var dValuePlayer1 = initialEloPlayer1 - initialEloPlayer2; + var dValuePlayer2 = initialEloPlayer2 - initialEloPlayer1; + + // p(D) value + var pDValuePlayer1 = 1 / (1 + Math.pow(10, (dValuePlayer1 * -1) / 400)); + var pDValuePlayer2 = 1 / (1 + Math.pow(10, (dValuePlayer2 * -1) / 400)); + + var compareEloPlayer1 = kValuePlayer1 * (1 - pDValuePlayer1); + var compareEloPlayer2 = kValuePlayer2 * (1 - pDValuePlayer2); + + return [compareEloPlayer1, compareEloPlayer2]; } // ============================================================================================================================ @@ -739,6 +786,7 @@ Stats.ComputeElo = function(callback) { } Stats.TriggerNewState = function(state) { + _state = state; switch(state) { case 0: From a9f9498b3200ba2ee617338e96f2fabf50ea57b4 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc Date: Thu, 18 Oct 2018 01:16:34 -0400 Subject: [PATCH 3/5] Finished feature --- web/css/style.css | 2 +- web/js/stats.js | 48 ++++++++++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/web/css/style.css b/web/css/style.css index c93a0b4..ff82c01 100644 --- a/web/css/style.css +++ b/web/css/style.css @@ -120,7 +120,7 @@ h1 { text-align: center; color: white; font-size: 110px; - padding-left: 21% !important; + padding-left: 20% !important; font-weight: normal; } diff --git a/web/js/stats.js b/web/js/stats.js index ffeac91..4cd05f9 100644 --- a/web/js/stats.js +++ b/web/js/stats.js @@ -452,9 +452,9 @@ function isGameValid(game) { var sumScorePlayer2 = game.score_player_2; // The difference between the timestamp of the first and last score is more than 60 seconds - if (game.last_score_date - game.created_date < 60) { - return false; - } + // if (game.last_score_date - game.created_date < 60) { + // return false; + // } // Valid overtime score (2 points of difference if both scores are > 10) if (isOvertimeGame(sumScorePlayer1, sumScorePlayer2)) { // Valid overtime game @@ -517,7 +517,6 @@ function getMinimumGamesForRanking() { } function applyEloTemplateInGame(state) { - console.log("CALLED!"); var eloTemplate = 'PLAYERELO'; var rankingTemplate = ''; var idPlayer1 = $("#elo-player-1").attr("data-id-player1-elo"); @@ -546,31 +545,40 @@ function applyEloTemplateInGame(state) { $("#elo-player-1").html(player1Template); $("#elo-player-2").html(player2Template); + // We update ELO comparison only at beggining of the game + if (_state != 10) + return; + // Show ELO comparison - var nbGamesPlayer1 = _state == 10 ? player1Temp.elo_games : player1Temp.elo_games - 1 - var nbGamesPlayer2 = _state == 10 ? player2Temp.elo_games : player2Temp.elo_games - 1 - var nextKValuePlayer1 = nbGamesPlayer1 < getMinimumGamesForRanking() ? UNRANKED_COEFFICIENT : RANKED_COEFFICIENT; - var nextKValuePlayer2 = nbGamesPlayer2 < getMinimumGamesForRanking() ? UNRANKED_COEFFICIENT : RANKED_COEFFICIENT; + var nextKValuePlayer1 = player1Temp.elo_games < getMinimumGamesForRanking() ? UNRANKED_COEFFICIENT : RANKED_COEFFICIENT; + var nextKValuePlayer2 = player2Temp.elo_games < getMinimumGamesForRanking() ? UNRANKED_COEFFICIENT : RANKED_COEFFICIENT; var arrNextElos = getNextElo(player1Temp.elo, player2Temp.elo, nextKValuePlayer1, nextKValuePlayer2); player1Temp.diffPlusElo = Math.round(arrNextElos[0]); - player1Temp.diffMinusElo = Math.round(0 - arrNextElos[1]); - player2Temp.diffPlusElo = Math.round(arrNextElos[1]); - player2Temp.diffMinusElo = Math.round(0 - arrNextElos[0]); + player1Temp.diffMinusElo = Math.round(arrNextElos[1]); + player2Temp.diffPlusElo = Math.round(arrNextElos[2]); + player2Temp.diffMinusElo = Math.round(arrNextElos[3]); - console.log(player1Temp); - console.log(player2Temp); - var eloComparisonTemplate = 'COMPAREELOPLUS/COMPAREELOMINUS'; // Player 1 + if (player1Temp.elo_games < getMinimumGamesForRanking()) + $("#compare-elo-player-1").hide(); + else + $("#compare-elo-player-1").show(); + var player1CompareEloTemplate = eloComparisonTemplate; - player1CompareEloTemplate = player1CompareEloTemplate.replace(/COMPAREELOPLUS/g, player1Temp.diffPlusElo); + player1CompareEloTemplate = player1CompareEloTemplate.replace(/COMPAREELOPLUS/g, "+" + player1Temp.diffPlusElo); player1CompareEloTemplate = player1CompareEloTemplate.replace(/COMPAREELOMINUS/g, player1Temp.diffMinusElo); // Player 2 + if (player2Temp.elo_games < getMinimumGamesForRanking()) + $("#compare-elo-player-2").hide(); + else + $("#compare-elo-player-2").show(); + var player2CompareEloTemplate = eloComparisonTemplate; - player2CompareEloTemplate = player2CompareEloTemplate.replace(/COMPAREELOPLUS/g, player2Temp.diffPlusElo); + player2CompareEloTemplate = player2CompareEloTemplate.replace(/COMPAREELOPLUS/g, "+" + player2Temp.diffPlusElo); player2CompareEloTemplate = player2CompareEloTemplate.replace(/COMPAREELOMINUS/g, player2Temp.diffMinusElo); $ ("#compare-elo-player-1").html(player1CompareEloTemplate); @@ -586,10 +594,12 @@ function getNextElo(initialEloPlayer1, initialEloPlayer2, kValuePlayer1, kValueP var pDValuePlayer1 = 1 / (1 + Math.pow(10, (dValuePlayer1 * -1) / 400)); var pDValuePlayer2 = 1 / (1 + Math.pow(10, (dValuePlayer2 * -1) / 400)); - var compareEloPlayer1 = kValuePlayer1 * (1 - pDValuePlayer1); - var compareEloPlayer2 = kValuePlayer2 * (1 - pDValuePlayer2); + var compareEloPlusPlayer1 = kValuePlayer1 * (1 - pDValuePlayer1); + var compareEloMinusPlayer1 = kValuePlayer1 * (0 - pDValuePlayer1); + var compareEloPlusPlayer2 = kValuePlayer2 * (1 - pDValuePlayer2); + var compareEloMinusPlayer2 = kValuePlayer2 * (0 - pDValuePlayer2); - return [compareEloPlayer1, compareEloPlayer2]; + return [compareEloPlusPlayer1, compareEloMinusPlayer1, compareEloPlusPlayer2, compareEloMinusPlayer2]; } // ============================================================================================================================ From cf33d95955d8b7ab07049a181ec34f04db488b6d Mon Sep 17 00:00:00 2001 From: Marc LeBlanc Date: Thu, 18 Oct 2018 01:07:04 -0400 Subject: [PATCH 4/5] Minor clock fix --- web/js/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/js/script.js b/web/js/script.js index c5d1dc7..ee591ad 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -133,7 +133,7 @@ function setClock() { var now = new Date(); - var clockValue = now.getHours() + ":" + now.getMinutes(); + var clockValue = now.getHours() + ":" + now.getMinutes().toString().padStart(2, '0'); $("#clock").html(clockValue); } From 415560271e469309890821a2b61a2822f4989ba1 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc Date: Wed, 17 Oct 2018 21:23:14 -0400 Subject: [PATCH 5/5] Prepare conflict --- web/js/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/js/script.js b/web/js/script.js index ee591ad..5a420d3 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -133,7 +133,7 @@ function setClock() { var now = new Date(); - var clockValue = now.getHours() + ":" + now.getMinutes().toString().padStart(2, '0'); + var clockValue = now.getHours() + ":" + now.getMinutes().toString().padStart(2, "0"); $("#clock").html(clockValue); }