From 188262a6c40ee07b21f5e80bb20c956130b60e32 Mon Sep 17 00:00:00 2001 From: Thomas Wilburn Date: Fri, 14 Sep 2018 13:21:32 -0500 Subject: [PATCH 1/3] Fix stat display for tournaments and player details With @htmlghozt --- public/components/player/details/details.stache | 16 ++++++++-------- .../components/tournament/details/details.stache | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/public/components/player/details/details.stache b/public/components/player/details/details.stache index f8757e04..22c37514 100644 --- a/public/components/player/details/details.stache +++ b/public/components/player/details/details.stache @@ -16,16 +16,16 @@ {{/ player }} -{{# each(tournaments) }} - {{# if(statsByTournament[id]) }} -

{{ year }} Tournament

+{{# for (tournament of tournaments) }} + {{# if(this.statsByTournament[tournament.id]) }} +

{{ tournament.year }} Tournament

{{/ if }} -{{/ each }} +{{/ for }} diff --git a/public/components/tournament/details/details.stache b/public/components/tournament/details/details.stache index fe0204e3..be398c54 100644 --- a/public/components/tournament/details/details.stache +++ b/public/components/tournament/details/details.stache @@ -207,23 +207,23 @@ Name - {{# each(statHeaders) }} + {{# each(stats.types) }} {{ name }} {{/ each }} {{# if(stats.length) }} - {{# each(players) }} - {{# if(stats.byPlayer[id]) }} + {{# for (player of players) }} + {{# if(stats.byPlayer[player.id]) }} - {{ name }} - {{# each(stats.byPlayer[id].aggregated) }} - {{ value }} - {{/ each }} + {{ player.name }} + {{# for (s of stats.byPlayer[player.id].aggregated) }} + {{ s.value }} + {{/ for }} {{/ if }} - {{/ each }} + {{/ for }} {{ else }} No Stats {{/ if }} From ea637eb989a553c557963fcf8e3d61ecb5d4b9db Mon Sep 17 00:00:00 2001 From: Thomas Wilburn Date: Fri, 14 Sep 2018 13:22:33 -0500 Subject: [PATCH 2/3] Add cursing penalties Cursing costs a team 1 point per infraction in the final score --- public/components/game/details/details.js | 8 +++++- public/components/game/details/details.less | 5 ++++ .../components/game/details/details_test.js | 26 ++++++++++++++++--- public/models/fixtures/games.js | 6 +++++ public/models/stat.js | 14 ++++++---- 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/public/components/game/details/details.js b/public/components/game/details/details.js index 3d97f57c..e09a0262 100644 --- a/public/components/game/details/details.js +++ b/public/components/game/details/details.js @@ -156,6 +156,9 @@ exports.ViewModel = DefineMap.extend('GameDetailsVM', if(stat.type === "2P") { scores[playerMap[ stat.playerId ]] += 2; } + if(stat.type === "C") { + scores[playerMap[ stat.playerId]]--; + } }); return scores; } @@ -181,6 +184,9 @@ exports.ViewModel = DefineMap.extend('GameDetailsVM', if(stat.type === "2P") { scores[playerMap[ stat.playerId]] += 2; } + if(stat.type === "C") { + scores[playerMap[ stat.playerId]]--; + } } }); return scores; @@ -382,7 +388,7 @@ exports.ViewModel = DefineMap.extend('GameDetailsVM', * ``` */ statPercent: function(time){ - var duration = this.youtubePlayerDuration; + var duration = this.youtubePlayerDuration || this.game.lastTime * 1.1; if(duration) { return time / duration * 100; } else { diff --git a/public/components/game/details/details.less b/public/components/game/details/details.less index a7dbdd94..a0134896 100644 --- a/public/components/game/details/details.less +++ b/public/components/game/details/details.less @@ -105,4 +105,9 @@ game-details { background-color: red; color: white; } + + .stat-C { + background: darkred; + color: white; + } } diff --git a/public/components/game/details/details_test.js b/public/components/game/details/details_test.js index 6e55e8e0..7ba949d6 100644 --- a/public/components/game/details/details_test.js +++ b/public/components/game/details/details_test.js @@ -9,6 +9,7 @@ import fixture from 'can-fixture'; import $ from 'jquery'; import canViewModel from 'can-view-model'; import User from "~/models/user"; +import Stat from "~/models/stat"; var deepEqual = QUnit.deepEqual, ok = QUnit.ok, @@ -50,7 +51,7 @@ QUnit.test("correctly sums score", function() { var vm = this.vm; vm.on("game", function(ev, game) { deepEqual(vm.finalScore, { - home: 3, + home: 2, away: 5 }); QUnit.start(); @@ -92,7 +93,9 @@ QUnit.test("correctly sums the current score", function () { | 0 | 0 | 0 | | 20 | 1 | 0 | | 40 | 3 | 0 | - | 60 | 3 | 1 | + | 60 | 3 | 1 | + | 122 | 2 | 1 | <-1 for cursing> + | 122 | 2 | 1 | Therefore at time=50, home=3 and away=0. @@ -110,6 +113,21 @@ QUnit.test("correctly sums the current score", function () { }); }); +QUnit.test('Game lastTime uses stat events as a fallback', function () { + QUnit.stop(); + var vm = this.vm; + + // last stat time is 122 + vm.on("game", function() { + vm.youtubePlayerTime = 0; + QUnit.notEqual(vm.game.lastTime, 0); + + QUnit.start(); + }); + + +}); + QUnit.test('A stat can only be deleted by an admin', function () { var session = new Session({user: new User({ isAdmin: false }) }); @@ -128,9 +146,9 @@ QUnit.test('A stat can only be deleted by an admin', function () { vm.session.user.isAdmin = true; ok(true, 'The user is given admin privileges'); }) - .size(6, 'Destroy buttons are inserted') + .size(7, 'Destroy buttons are inserted') .click() - .size(5, 'Clicking the destroy button removed a stat'); + .size(6, 'Clicking the destroy button removed a stat'); }); diff --git a/public/models/fixtures/games.js b/public/models/fixtures/games.js index b806ec8f..2fb7253f 100644 --- a/public/models/fixtures/games.js +++ b/public/models/fixtures/games.js @@ -144,6 +144,12 @@ export const games = { type: "2P", playerId: 8, time: 120 + }, + { + id: 7, + type: "C", + playerId: 3, + time: 122 }] }; diff --git a/public/models/stat.js b/public/models/stat.js index 247af5e5..df006ab4 100644 --- a/public/models/stat.js +++ b/public/models/stat.js @@ -49,7 +49,8 @@ var Stat = DefineMap.extend('Stat', { name: "Ast"}, { name: "Stl"}, { name: "Blk"}, - { name: "To"} + { name: "To"}, + { name: "C" } ] }, { @@ -102,7 +103,7 @@ var Stat = DefineMap.extend('Stat', } }, - default: 'any' + value: 'any' }); @@ -114,6 +115,9 @@ var Stat = DefineMap.extend('Stat', */ Stat.List = DefineList.extend('StatsList', { "#": Stat, + get types() { + return Stat.statTypes; + }, get byPlayer() { let players = {}; @@ -160,11 +164,11 @@ Stat.List = DefineList.extend('StatsList', { return [ ...Stat.statTypes.map(({ name }) => ({ name, - default: (aggregated[name] || 0).toFixed(0), + value: (aggregated[name] || 0).toFixed(0), })), { name: 'TP', - default: (function() { + value: (function() { let onePointers = aggregated['1P'] || 0; let twoPointers = aggregated['2P'] || 0; @@ -173,7 +177,7 @@ Stat.List = DefineList.extend('StatsList', { }, { name: 'FG%', - default: (function() { + value: (function() { let onePointers = aggregated['1P'] || 0; let twoPointers = aggregated['2P'] || 0; let onePointAttempts = aggregated['1PA'] || 0; From 5a8ccd61f2ece5c5f3108abb80a0165d7217d545 Mon Sep 17 00:00:00 2001 From: Thomas Wilburn Date: Fri, 14 Sep 2018 13:23:07 -0500 Subject: [PATCH 3/3] Add a lastTime for games If there's no YouTube video, we should get the duration from the last stat event on the game With @htmlghozt --- public/models/game.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/public/models/game.js b/public/models/game.js index 3b34ba64..de2107ba 100644 --- a/public/models/game.js +++ b/public/models/game.js @@ -175,6 +175,15 @@ var Game = DefineMap.extend('Game', }); return playerIds; } + }, + + /** + * @property {Number} + * Gives the last time for a stat event during this game. + **/ + get lastTime() { + if (!this.stats) return 0; + return this.stats.reduce((time, s) => s.time > time ? s.time : time, 0); } });