Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training thomasx2 #335

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion public/components/game/details/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions public/components/game/details/details.less
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ game-details {
background-color: red;
color: white;
}

.stat-C {
background: darkred;
color: white;
}
}
26 changes: 22 additions & 4 deletions public/components/game/details/details_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -92,7 +93,9 @@ QUnit.test("correctly sums the current score", function () {
| 0 | 0 | 0 | <initial>
| 20 | 1 | 0 |
| 40 | 3 | 0 |
| 60 | 3 | 1 | <final>
| 60 | 3 | 1 |
| 122 | 2 | 1 | <-1 for cursing>
| 122 | 2 | 1 | <final>

Therefore at time=50, home=3 and away=0.

Expand All @@ -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 }) });
Expand All @@ -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');
});


Expand Down
16 changes: 8 additions & 8 deletions public/components/player/details/details.stache
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
</ul>
{{/ player }}

{{# each(tournaments) }}
{{# if(statsByTournament[id]) }}
<h2>{{ year }} Tournament</h2>
{{# for (tournament of tournaments) }}
{{# if(this.statsByTournament[tournament.id]) }}
<h2>{{ tournament.year }} Tournament</h2>
<ul class="tournament-stats">
{{# each(statsByTournament[id].aggregated) }}
{{# for (stat of statsByTournament[tournament.id].aggregated) }}
<li>
<p>{{ name }}</p>
<div>{{ value }}</div>
<p>{{ stat.name }}</p>
<div>{{ stat.value }}</div>
</li>
{{/ each }}
{{/ for }}
</ul>
{{/ if }}
{{/ each }}
{{/ for }}
16 changes: 8 additions & 8 deletions public/components/tournament/details/details.stache
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,23 @@
<thead>
<tr>
<th>Name</th>
{{# each(statHeaders) }}
{{# each(stats.types) }}
<th>{{ name }}</th>
{{/ each }}
</tr>
</thead>
<tbody>
{{# if(stats.length) }}
{{# each(players) }}
{{# if(stats.byPlayer[id]) }}
{{# for (player of players) }}
{{# if(stats.byPlayer[player.id]) }}
<tr>
<td><a href='{{ routeUrl(playerId=id) }}'>{{ name }}</a></td>
{{# each(stats.byPlayer[id].aggregated) }}
<td>{{ value }}</td>
{{/ each }}
<td><a href='{{ routeUrl(playerId=player.id) }}'>{{ player.name }}</a></td>
{{# for (s of stats.byPlayer[player.id].aggregated) }}
<td>{{ s.value }}</td>
{{/ for }}
</tr>
{{/ if }}
{{/ each }}
{{/ for }}
{{ else }}
<tr><td class="text-center lead">No Stats</td></tr>
{{/ if }}
Expand Down
6 changes: 6 additions & 0 deletions public/models/fixtures/games.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ export const games = {
type: "2P",
playerId: 8,
time: 120
},
{
id: 7,
type: "C",
playerId: 3,
time: 122
}]
};

Expand Down
9 changes: 9 additions & 0 deletions public/models/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
14 changes: 9 additions & 5 deletions public/models/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ var Stat = DefineMap.extend('Stat',
{ name: "Ast"},
{ name: "Stl"},
{ name: "Blk"},
{ name: "To"}
{ name: "To"},
{ name: "C" }
]
},
{
Expand Down Expand Up @@ -102,7 +103,7 @@ var Stat = DefineMap.extend('Stat',
}
},

default: 'any'
value: 'any'
});


Expand All @@ -114,6 +115,9 @@ var Stat = DefineMap.extend('Stat',
*/
Stat.List = DefineList.extend('StatsList', {
"#": Stat,
get types() {
return Stat.statTypes;
},
get byPlayer() {
let players = {};

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down