-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlCancelAccuracy.ts
38 lines (34 loc) · 1 KB
/
lCancelAccuracy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { StatDefinition } from "../types";
export const lCancelAccuracy: StatDefinition = {
name: "L-Cancel Accuracy",
type: "number",
betterDirection: "higher",
recommendedRounding: 0,
calculate(games, playerIndex) {
const lCancelsPerGame = games.map((game) => {
const actionCounts = game.stats.actionCounts.find((counts) => counts.playerIndex === playerIndex);
if (!actionCounts) {
return {
success: 0,
fail: 0,
};
}
return actionCounts.lCancelCount;
});
const totalLCancels = lCancelsPerGame.reduce(
(tally, val) => ({
success: tally.success + val.success,
fail: tally.fail + val.fail,
}),
{ success: 0, fail: 0 }
);
const ratio = totalLCancels.success / (totalLCancels.success + totalLCancels.fail);
return {
result: totalLCancels,
simple: {
text: isNaN(ratio) ? "N/A" : `${(ratio * 100).toFixed(this.recommendedRounding)}%`,
number: ratio,
},
};
},
};