Skip to content

Commit aebc2e9

Browse files
committed
Added totals per group overview to tournaments
1 parent df86cd6 commit aebc2e9

File tree

7 files changed

+112
-32
lines changed

7 files changed

+112
-32
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ A preview of major changes can be found in the Wiki ([Latest Changes](https://gi
66
- Option to see `All` or `Unique` tournament statistics per player
77
- Ability to "Remote Start" matches on a selected venue
88
- Split tournaments into "Tournaments" and "Seasons"
9+
- Persist "Enable Voice Announcements" on spectate page
10+
- Added totals view per group to Tournament Overview
911

1012
#### Changed
1113
- Updated to latest version of dependencies

src/components/tournament-overview-table/tournament-overview-table.component.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,50 @@ const _ = require("underscore");
22

33
module.exports = {
44
onCreate(input) {
5+
const keysToSum = [
6+
"played", "matches_won", "matches_draw", "matches_lost",
7+
"legs_for", "legs_against", "legs_difference", "points",
8+
"scores_60s_plus", "scores_100s_plus", "scores_140s_plus",
9+
"scores_180s", "checkout_attempts", "darts_thrown",
10+
"darts_per_leg", "three_dart_avg_score", "first_nine_three_dart_avg_score",
11+
"accuracy_20", "accuracy_19", "accuracy_overall"
12+
];
13+
14+
let dplCount = 0;
15+
let acc20Count = 0;
16+
let acc19Count = 0;
17+
const total = _.reduce(input.overview, (totals, player) => {
18+
_.each(keysToSum, (key) => {
19+
if (player[key] !== -1) {
20+
totals[key] += player[key];
21+
}
22+
});
23+
if (player.darts_per_leg !== -1) {
24+
dplCount++;
25+
}
26+
if (player.accuracy_20 !== -1) {
27+
acc20Count++;
28+
}
29+
if (player.accuracy_19 !== -1) {
30+
acc19Count++;
31+
}
32+
33+
return totals;
34+
}, _.object(keysToSum, _.map(keysToSum, () => 0)));
35+
36+
if (dplCount > 0) {
37+
total.checkout_percentage = (total.legs_for / total.checkout_attempts) * 100.0;
38+
total.three_dart_avg = total.three_dart_avg_score / total.darts_thrown;
39+
total.first_nine_three_dart_avg = total.first_nine_three_dart_avg_score / ((total.legs_for + total.legs_against) * 9);
40+
total.darts_per_leg = total.darts_per_leg / dplCount;
41+
total.accuracy_20 = total.accuracy_20 / acc20Count;
42+
total.accuracy_19 = total.accuracy_19 / acc19Count;
43+
total.accuracy_overall = total.accuracy_overall / dplCount;
44+
}
45+
546
this.state = {
647
overview: input.overview,
7-
hasStatistics: !_.isEmpty(input.statistics)
48+
total: total
849
}
950
},
1051
onMount() {

src/components/tournament-overview-table/tournament-overview-table.marko

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
<table class="table-tournament-overview">
44
<thead>
55
<tr>
6-
<th class="pl-10">Pos</th>
7-
<th>Player</th>
8-
<th class="text-right" title="Played">P</th>
9-
<th class="text-right pl-20" title="Won">W</th>
10-
<th class="text-right" title="Draw">D</th>
11-
<th class="text-right" title="Lost">L</th>
12-
<th class="text-center pl-10" title="For - Against">F - A</th>
13-
<th class="text-right pl-10" title="Difference">+/-</th>
14-
<th class="text-right" title="Points">PTS</th>
15-
<if(state.hasStatistics)>
6+
<th class="pl-10">Pos</th>
7+
<th>Player</th>
8+
<th class="text-right" title="Played">P</th>
9+
<th class="text-right pl-20" title="Won">W</th>
10+
<th class="text-right" title="Draw">D</th>
11+
<th class="text-right" title="Lost">L</th>
12+
<th class="text-center pl-10" title="For - Against">F - A</th>
13+
<th class="text-right pl-10" title="Difference">+/-</th>
14+
<th class="text-right" title="Points">PTS</th>
1615
<th class="text-center" title="3 Dart Avg. / First 9 Three Dart Avg.">3 Dart Avg.</th>
1716
<th class="text-center" title="Checkout Percentage">Checkout %</th>
1817
<th class="text-right" title="60+ scores">60s+</th>
@@ -25,7 +24,6 @@
2524
<th class="text-center" title="Accuracy Overall">Overall</th>
2625
<th class="text-center" title="Accuracy 20s">20s</th>
2726
<th class="text-center" title="Accuracy 19s">19s</th>
28-
</if>
2927
</tr>
3028
</thead>
3129
<tbody>
@@ -47,31 +45,51 @@
4745
</else-if>
4846
</div>
4947
</td>
50-
<td style='width: 15%;'>
51-
<a style='white-space: nowrap; overflow: hidden; text-overflow: ellipsis;' href=`/tournaments/${input.tournament.id}/player/${player.player_id}`>${input.players[player.player_id].name}</a>
48+
<td style='max-width: 2em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;'>
49+
<a href=`/tournaments/${input.tournament.id}/player/${player.player_id}`>${input.players[player.player_id].name}</a>
5250
</td>
5351
<td class="text-right">${player.played}</td>
54-
<td class="text-right pl-20">${player.matches_won}</td>
52+
<td class="text-right">${player.matches_won}</td>
5553
<td class="text-right">${player.matches_draw}</td>
5654
<td class="text-right">${player.matches_lost}</td>
57-
<td class="text-center pl-10">${player.legs_for + " - " + player.legs_against}</td>
55+
<td class="text-center" style="min-width: 64px;">${player.legs_for + " - " + player.legs_against}</td>
5856
<td class="text-right pl-10">${player.legs_difference > 0 ? "+" + player.legs_difference : player.legs_difference}</td>
5957
<td class="text-right">${player.points}</td>
60-
<if(state.hasStatistics)>
61-
<td class="text-center">${player.three_dart_avg === -1 ? "- / -" : player.three_dart_avg.toFixed(2) + " / " + player.first_nine_three_dart_avg.toFixed(2)}</td>
62-
<td class="text-center">${player.checkout_percentage === -1 ? "-" : player.checkout_percentage.toFixed(2) + "%"}</td>
63-
<td class="text-right">${player.scores_60s_plus}</td>
64-
<td class="text-right">${player.scores_100s_plus}</td>
65-
<td class="text-right">${player.scores_140s_plus}</td>
66-
<td class="text-right">${player.scores_180s}</td>
67-
<td class="text-center">${player.darts_per_leg === -1 ? "-" : player.darts_per_leg.toFixed(2)}</td>
68-
<td class="text-center">${player.accuracy_overall === -1 ? "-" : player.accuracy_overall.toFixed(2)}</td>
69-
<td class="text-center">${player.accuracy_20 === -1 ? "-" : player.accuracy_20.toFixed(2)}</td>
70-
<td class="text-center">${player.accuracy_19 === -1 ? "-" : player.accuracy_19.toFixed(2)}</td>
71-
</if>
58+
<td class="text-center">${player.three_dart_avg === -1 ? "- / -" : player.three_dart_avg.toFixed(2) + " / " + player.first_nine_three_dart_avg.toFixed(2)}</td>
59+
<td class="text-center">${player.checkout_percentage === -1 ? "-" : player.checkout_percentage.toFixed(2) + "%"}</td>
60+
<td class="text-right td-multi-value">${input.showPerLeg ? (player.played === 0 ? 0 : player.scores_60s_plus / (player.legs_for + player.legs_against)).toFixed(2) : player.scores_60s_plus}</td>
61+
<td class="text-right td-multi-value">${input.showPerLeg ? (player.played === 0 ? 0 : player.scores_100s_plus / (player.legs_for + player.legs_against)).toFixed(2) : player.scores_100s_plus}</td>
62+
<td class="text-right td-multi-value">${input.showPerLeg ? (player.played === 0 ? 0 : player.scores_140s_plus / (player.legs_for + player.legs_against)).toFixed(2) : player.scores_140s_plus}</td>
63+
<td class="text-right td-multi-value">${input.showPerLeg ? (player.played === 0 ? 0 : player.scores_180s / (player.legs_for + player.legs_against)).toFixed(2) : player.scores_180s}</td>
64+
<td class="text-center">${player.darts_per_leg === -1 ? "-" : player.darts_per_leg.toFixed(2)}</td>
65+
<td class="text-center">${player.accuracy_overall === -1 ? "-" : player.accuracy_overall.toFixed(2)}</td>
66+
<td class="text-center">${player.accuracy_20 === -1 ? "-" : player.accuracy_20.toFixed(2)}</td>
67+
<td class="text-center">${player.accuracy_19 === -1 ? "-" : player.accuracy_19.toFixed(2)}</td>
7268
</tr>
7369
</if>
7470
</for>
71+
<tr>
72+
$ let total = state.total;
73+
<td class="pl-10"></td>
74+
<td style='width: 15%;'>TOTAL</td>
75+
<td class="text-right">${total.played}</td>
76+
<td class="text-right">${total.matches_won}</td>
77+
<td class="text-right">${total.matches_draw}</td>
78+
<td class="text-right">${total.matches_lost}</td>
79+
<td class="text-center"></td>
80+
<td class="text-right pl-10"></td>
81+
<td class="text-right">${total.points}</td>
82+
<td class="text-center">${!total.three_dart_avg ? "- / -" : total.three_dart_avg.toFixed(2) + " / " + total.first_nine_three_dart_avg.toFixed(2)}</td>
83+
<td class="text-center">${!total.checkout_percentage ? "-" : total.checkout_percentage.toFixed(2) + "%"}</td>
84+
<td class="text-right td-multi-value">${input.showPerLeg ? (total.played === 0 ? 0 : total.scores_60s_plus / (total.legs_for + total.legs_against)).toFixed(2) : total.scores_60s_plus}</td>
85+
<td class="text-right td-multi-value">${input.showPerLeg ? (total.played === 0 ? 0 : total.scores_100s_plus / (total.legs_for + total.legs_against)).toFixed(2) : total.scores_100s_plus}</td>
86+
<td class="text-right td-multi-value">${input.showPerLeg ? (total.played === 0 ? 0 : total.scores_140s_plus / (total.legs_for + total.legs_against)).toFixed(2) : total.scores_140s_plus}</td>
87+
<td class="text-right td-multi-value">${input.showPerLeg ? (total.played === 0 ? 0 : total.scores_180s / (total.legs_for + total.legs_against)).toFixed(2) : total.scores_180s}</td>
88+
<td class="text-center">${total.darts_per_leg === 0 ? "-" : total.darts_per_leg.toFixed(2)}</td>
89+
<td class="text-center">${total.accuracy_overall === 0 ? "-" : total.accuracy_overall.toFixed(2)}</td>
90+
<td class="text-center">${total.accuracy_20 === 0 ? "-" : total.accuracy_20.toFixed(2)}</td>
91+
<td class="text-center">${total.accuracy_19 === 0 ? "-" : total.accuracy_19.toFixed(2)}</td>
92+
</tr>
7593
</tbody>
7694
</table>
7795
</div>

src/components/tournament-overview-table/tournament-overview-table.style.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
border-bottom: 1px solid #e9e9e9;
2020
padding: 10px;
2121
}
22+
tr:last-child {
23+
font-weight: bold;
24+
background-color: #1ABC9C;
25+
color: white;
26+
}
2227
.text-right {
2328
text-align: right;
2429
padding-right: 10px;
@@ -40,6 +45,11 @@
4045
font-size: 18px;
4146
padding-left: 2px;
4247
}
48+
.td-multi-value {
49+
min-width: 40px;
50+
max-width: 40px;
51+
width: 40px;
52+
}
4353
}
4454

4555
.tournament-playoffs {

src/pages/tournament/components/tournament/tournament.component.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ module.exports = {
4040
overview: overview,
4141
unq_statistics: {},
4242
statistics: input.statistics,
43-
showAllStats: true
43+
showAllStats: true,
44+
showPerLeg: true
4445
}
4546
if (this.state.hasStatistics) {
4647
// Create unique statistics
@@ -100,5 +101,8 @@ module.exports = {
100101
this.state.showAllStats = value;
101102
this.state.statistics = value ? this.input.statistics : this.state.unq_statistics;
102103
this.setStateDirty("statistics");
104+
},
105+
onTogglePerLeg(value, event) {
106+
this.state.showPerLeg = value;
103107
}
104108
}

src/pages/tournament/components/tournament/tournament.marko

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $ {
2626
<options-panel tournament=input.tournament/>
2727
</if>
2828
<for|id, group| in=state.overview>
29-
<div class="block-container p-10" style='margin-bottom: 0;'>
29+
<div class="block-container" style='margin-bottom: 0; padding-bottom: 0; padding-right: 0;'>
3030
<div class="float-left" style="font-size: 30px;">${group[0].tournament_group.name}</div>
3131
<div style="float: right; padding-top: 4px;">
3232
<ul class="nav nav-pills">
@@ -43,11 +43,15 @@ $ {
4343
<a href=`#predictor-${group[0].tournament_group.id}` data-toggle="tab" class="tournament-group-predictor">Predictor</a>
4444
</li>
4545
</ul>
46+
<div class="float-right btn-group btn-toggle" style="padding-top: 1em;">
47+
<button class=`btn ${state.showPerLeg ? "btn-primary" : "btn-default"}` style="font-size: 0.8em;" on-click("onTogglePerLeg", true)>Per Leg</button>
48+
<button class=`btn ${state.showPerLeg ? "btn-default" : "btn-primary"}` style="font-size: 0.8em;" on-click("onTogglePerLeg", false)>Total</button>
49+
</div>
4650
</div>
4751
</div>
4852
<div class="tab-content">
4953
<div role="tabpanel" id=`standings-${group[0].tournament_group.id}` class="tab-pane active">
50-
<tournament-overview-table tournament=input.tournament players=input.players statistics=input.statistics overview=group/>
54+
<tournament-overview-table tournament=input.tournament players=input.players statistics=input.statistics overview=group showPerLeg=state.showPerLeg/>
5155
</div>
5256
$ {
5357
let columns = ["start_time", "status", "players", "results", "options"];

src/util/speaker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports.getUtterance = function (data, callback) {
1212
}
1313
};
1414
msg.play = () => {
15+
console.log(`getUtterance: speechSynthesis.speak - pending: ${speechSynthesis.pending}, speaking: ${speechSynthesis.speaking} paused: ${speechSynthesis.paused}`);
1516
// Adding custom play method to allow easier chaining with audio elements
1617
speechSynthesis.cancel(); // Sometimes it gets stuck and refuses to speak any more, so cancel any existing before speaking again
1718
speechSynthesis.speak(msg);
@@ -31,7 +32,7 @@ exports.getUtteranceWithVoice = function (data, voiceName, readyCallback, endCal
3132
}
3233
};
3334
msg.play = () => {
34-
// Adding custom play method to allow easier chaining with audio elements
35+
console.log(`getUtteranceWithVoice: speechSynthesis.speak - pending: ${speechSynthesis.pending}, speaking: ${speechSynthesis.speaking} paused: ${speechSynthesis.paused}`); // Adding custom play method to allow easier chaining with audio elements
3536
speechSynthesis.cancel(); // Sometimes it gets stuck and refuses to speak any more, so cancel any existing before speaking again
3637
speechSynthesis.speak(msg);
3738
}

0 commit comments

Comments
 (0)