volleyballsimtypes 0.0.417 → 0.0.419

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ export * from './match-generator';
4
4
  export * from './match-rating';
5
5
  export * from './match-set';
6
6
  export * from './rally';
7
+ export * from './point-breakdown';
7
8
  export * from './court-position';
8
9
  export * from './match-team';
9
10
  export * from './vper';
@@ -20,6 +20,7 @@ __exportStar(require("./match-generator"), exports);
20
20
  __exportStar(require("./match-rating"), exports);
21
21
  __exportStar(require("./match-set"), exports);
22
22
  __exportStar(require("./rally"), exports);
23
+ __exportStar(require("./point-breakdown"), exports);
23
24
  __exportStar(require("./court-position"), exports);
24
25
  __exportStar(require("./match-team"), exports);
25
26
  __exportStar(require("./vper"), exports);
@@ -0,0 +1,36 @@
1
+ export interface RallyEventLike {
2
+ readonly eventType: number;
3
+ readonly playerId: string;
4
+ }
5
+ export interface RallyLike {
6
+ readonly events: readonly RallyEventLike[];
7
+ }
8
+ export interface TeamBlockTally {
9
+ blockPoints: number;
10
+ blockSolo: number;
11
+ blockAssists: number;
12
+ }
13
+ export declare function tallyBlockPoints(rallies: readonly RallyLike[], teamOf: (playerId: string) => string | null): Map<string, TeamBlockTally>;
14
+ export interface TeamPointBreakdown {
15
+ kills: number;
16
+ aces: number;
17
+ blockPoints: number;
18
+ opponentErrors: number;
19
+ }
20
+ export interface PointBreakdown {
21
+ home: TeamPointBreakdown;
22
+ away: TeamPointBreakdown;
23
+ }
24
+ export interface PointBreakdownInput {
25
+ rallies: readonly RallyLike[];
26
+ homeTeamId: string;
27
+ awayTeamId: string;
28
+ teamOf: (playerId: string) => string | null;
29
+ homeKills: number;
30
+ awayKills: number;
31
+ homeAces: number;
32
+ awayAces: number;
33
+ homeTotalPoints: number;
34
+ awayTotalPoints: number;
35
+ }
36
+ export declare function computePointBreakdown(input: PointBreakdownInput): PointBreakdown;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tallyBlockPoints = tallyBlockPoints;
4
+ exports.computePointBreakdown = computePointBreakdown;
5
+ const event_1 = require("../event");
6
+ // A block scores a point in exactly ONE place in the sim (reception-simulator: a dig of a block fails
7
+ // and the block landed in-court, i.e. target >= 7). Each such rally is ONE block point regardless of how
8
+ // many blockers were on it; the box score records it as one `block_assists` per blocker (or one
9
+ // `block_solo`), which is why summing solo+assists over-counts block points. We rebuild the true count
10
+ // from the rallies. blockSolo / blockAssists must reconstruct box.block.solo and box.block.assists
11
+ // exactly (the correctness gate). `teamOf(playerId)` returns a player's team id (or null); the scoring
12
+ // team is the blockers' team.
13
+ function tallyBlockPoints(rallies, teamOf) {
14
+ const out = new Map();
15
+ const tallyFor = (team) => {
16
+ let t = out.get(team);
17
+ if (t == null) {
18
+ t = { blockPoints: 0, blockSolo: 0, blockAssists: 0 };
19
+ out.set(team, t);
20
+ }
21
+ return t;
22
+ };
23
+ for (const rally of rallies) {
24
+ // Ignore substitutions / libero replacements (eventType < SERVE) when locating the terminal action.
25
+ const inPlay = rally.events.filter(e => e.eventType >= event_1.EventTypeEnum.SERVE);
26
+ const last = inPlay[inPlay.length - 1];
27
+ const prev = inPlay[inPlay.length - 2];
28
+ if (last == null || prev == null)
29
+ continue;
30
+ // Block point signature: the rally ends on a failed RECEPTION (dig) whose previous event is a BLOCK
31
+ // that landed in-court (target >= 7). target < 7 is a deflection -> the ATTACKER's kill, not a block.
32
+ if (last.eventType !== event_1.EventTypeEnum.RECEPTION || last.failure <= 0)
33
+ continue;
34
+ if (prev.eventType !== event_1.EventTypeEnum.BLOCK)
35
+ continue;
36
+ const block = prev;
37
+ if (block.target < 7)
38
+ continue;
39
+ const team = teamOf(block.blockers[0] ?? block.playerId);
40
+ if (team == null)
41
+ continue;
42
+ const t = tallyFor(team);
43
+ t.blockPoints++;
44
+ if (block.blockers.length < 2)
45
+ t.blockSolo++;
46
+ else
47
+ t.blockAssists += block.blockers.length;
48
+ }
49
+ return out;
50
+ }
51
+ // Kills/aces come straight from the box score; block points are derived from rallies; opponent errors
52
+ // are the remainder (>= 0 by construction). The four reconcile to the team's total points.
53
+ function computePointBreakdown(input) {
54
+ const tally = tallyBlockPoints(input.rallies, input.teamOf);
55
+ const homeBlocks = tally.get(input.homeTeamId)?.blockPoints ?? 0;
56
+ const awayBlocks = tally.get(input.awayTeamId)?.blockPoints ?? 0;
57
+ return {
58
+ home: {
59
+ kills: input.homeKills,
60
+ aces: input.homeAces,
61
+ blockPoints: homeBlocks,
62
+ opponentErrors: input.homeTotalPoints - input.homeKills - input.homeAces - homeBlocks
63
+ },
64
+ away: {
65
+ kills: input.awayKills,
66
+ aces: input.awayAces,
67
+ blockPoints: awayBlocks,
68
+ opponentErrors: input.awayTotalPoints - input.awayKills - input.awayAces - awayBlocks
69
+ }
70
+ };
71
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const globals_1 = require("@jest/globals");
4
+ const event_1 = require("../event");
5
+ const point_breakdown_1 = require("./point-breakdown");
6
+ const blockEvent = (playerId, target, blockers) => ({ eventType: event_1.EventTypeEnum.BLOCK, playerId, target, blockers });
7
+ const receptionEvent = (playerId, failure) => ({ eventType: event_1.EventTypeEnum.RECEPTION, playerId, failure });
8
+ const serveEvent = (playerId) => ({ eventType: event_1.EventTypeEnum.SERVE, playerId });
9
+ const spikeEvent = (playerId) => ({ eventType: event_1.EventTypeEnum.SPIKE, playerId });
10
+ const rally = (events) => ({ events });
11
+ const teamOf = (id) => id.startsWith('h') ? 'HOME' : id.startsWith('a') ? 'AWAY' : null;
12
+ (0, globals_1.describe)('tallyBlockPoints', () => {
13
+ (0, globals_1.it)('counts an assisted block point once, recording each blocker as an assist', () => {
14
+ const t = (0, point_breakdown_1.tallyBlockPoints)([rally([blockEvent('h1', 8, ['h1', 'h2']), receptionEvent('a3', 1)])], teamOf);
15
+ (0, globals_1.expect)(t.get('HOME')).toEqual({ blockPoints: 1, blockSolo: 0, blockAssists: 2 });
16
+ });
17
+ (0, globals_1.it)('counts a solo block point', () => {
18
+ const t = (0, point_breakdown_1.tallyBlockPoints)([rally([blockEvent('h1', 9, ['h1']), receptionEvent('a3', 2)])], teamOf);
19
+ (0, globals_1.expect)(t.get('HOME')).toEqual({ blockPoints: 1, blockSolo: 1, blockAssists: 0 });
20
+ });
21
+ (0, globals_1.it)('does NOT count a deflection (target < 7) - that is the attacker\'s kill', () => {
22
+ const t = (0, point_breakdown_1.tallyBlockPoints)([rally([blockEvent('h1', 4, ['h1', 'h2']), receptionEvent('a3', 1)])], teamOf);
23
+ (0, globals_1.expect)(t.size).toBe(0);
24
+ });
25
+ (0, globals_1.it)('does NOT count an ace (reception fail after serve)', () => {
26
+ const t = (0, point_breakdown_1.tallyBlockPoints)([rally([serveEvent('h1'), receptionEvent('a3', 1)])], teamOf);
27
+ (0, globals_1.expect)(t.size).toBe(0);
28
+ });
29
+ (0, globals_1.it)('does NOT count a successful dig (reception failure 0)', () => {
30
+ const t = (0, point_breakdown_1.tallyBlockPoints)([rally([blockEvent('h1', 8, ['h1', 'h2']), receptionEvent('a3', 0), spikeEvent('a3')])], teamOf);
31
+ (0, globals_1.expect)(t.size).toBe(0);
32
+ });
33
+ (0, globals_1.it)('reconstructs box block.solo and block.assists across a mix (incl. a triple block)', () => {
34
+ const t = (0, point_breakdown_1.tallyBlockPoints)([
35
+ rally([blockEvent('h1', 8, ['h1', 'h2']), receptionEvent('a3', 1)]), // double: +2 assists
36
+ rally([blockEvent('h3', 8, ['h3', 'h4', 'h5']), receptionEvent('a1', 1)]), // triple: +3 assists
37
+ rally([blockEvent('h1', 9, ['h1']), receptionEvent('a2', 1)]), // solo: +1 solo
38
+ rally([blockEvent('a1', 8, ['a1', 'a2']), receptionEvent('h2', 1)]) // away double
39
+ ], teamOf);
40
+ (0, globals_1.expect)(t.get('HOME')).toEqual({ blockPoints: 3, blockSolo: 1, blockAssists: 5 });
41
+ (0, globals_1.expect)(t.get('AWAY')).toEqual({ blockPoints: 1, blockSolo: 0, blockAssists: 2 });
42
+ });
43
+ });
44
+ (0, globals_1.describe)('computePointBreakdown', () => {
45
+ (0, globals_1.it)('reproduces the prod bug scenario as a positive number (was -3)', () => {
46
+ // AWAY scored 99 (54 kills, 0 aces) and 28 block points (8 solo + 20 doubles). Old formula did
47
+ // 99 - 54 - (8 + 40) - 0 = -3; correct is 99 - 54 - 0 - 28 = 17.
48
+ const rallies = [];
49
+ for (let i = 0; i < 20; i++)
50
+ rallies.push(rally([blockEvent('a1', 8, ['a1', 'a2']), receptionEvent(`h${i}`, 1)]));
51
+ for (let i = 0; i < 8; i++)
52
+ rallies.push(rally([blockEvent('a3', 9, ['a3']), receptionEvent(`h${i + 20}`, 1)]));
53
+ const out = (0, point_breakdown_1.computePointBreakdown)({
54
+ rallies,
55
+ homeTeamId: 'HOME',
56
+ awayTeamId: 'AWAY',
57
+ teamOf,
58
+ homeKills: 51,
59
+ awayKills: 54,
60
+ homeAces: 3,
61
+ awayAces: 0,
62
+ homeTotalPoints: 108,
63
+ awayTotalPoints: 99
64
+ });
65
+ (0, globals_1.expect)(out.away.blockPoints).toBe(28);
66
+ (0, globals_1.expect)(out.away.opponentErrors).toBe(17);
67
+ (0, globals_1.expect)(out.away.opponentErrors).toBeGreaterThanOrEqual(0);
68
+ // The four categories reconcile to the team's total points.
69
+ (0, globals_1.expect)(out.away.kills + out.away.aces + out.away.blockPoints + out.away.opponentErrors).toBe(99);
70
+ (0, globals_1.expect)(out.home.kills + out.home.aces + out.home.blockPoints + out.home.opponentErrors).toBe(108);
71
+ });
72
+ });
@@ -4,6 +4,7 @@ export * from './match-generator';
4
4
  export * from './match-rating';
5
5
  export * from './match-set';
6
6
  export * from './rally';
7
+ export * from './point-breakdown';
7
8
  export * from './court-position';
8
9
  export * from './match-team';
9
10
  export * from './vper';
@@ -4,6 +4,7 @@ export * from './match-generator';
4
4
  export * from './match-rating';
5
5
  export * from './match-set';
6
6
  export * from './rally';
7
+ export * from './point-breakdown';
7
8
  export * from './court-position';
8
9
  export * from './match-team';
9
10
  export * from './vper';
@@ -0,0 +1,36 @@
1
+ export interface RallyEventLike {
2
+ readonly eventType: number;
3
+ readonly playerId: string;
4
+ }
5
+ export interface RallyLike {
6
+ readonly events: readonly RallyEventLike[];
7
+ }
8
+ export interface TeamBlockTally {
9
+ blockPoints: number;
10
+ blockSolo: number;
11
+ blockAssists: number;
12
+ }
13
+ export declare function tallyBlockPoints(rallies: readonly RallyLike[], teamOf: (playerId: string) => string | null): Map<string, TeamBlockTally>;
14
+ export interface TeamPointBreakdown {
15
+ kills: number;
16
+ aces: number;
17
+ blockPoints: number;
18
+ opponentErrors: number;
19
+ }
20
+ export interface PointBreakdown {
21
+ home: TeamPointBreakdown;
22
+ away: TeamPointBreakdown;
23
+ }
24
+ export interface PointBreakdownInput {
25
+ rallies: readonly RallyLike[];
26
+ homeTeamId: string;
27
+ awayTeamId: string;
28
+ teamOf: (playerId: string) => string | null;
29
+ homeKills: number;
30
+ awayKills: number;
31
+ homeAces: number;
32
+ awayAces: number;
33
+ homeTotalPoints: number;
34
+ awayTotalPoints: number;
35
+ }
36
+ export declare function computePointBreakdown(input: PointBreakdownInput): PointBreakdown;
@@ -0,0 +1,67 @@
1
+ import { EventTypeEnum } from '../event';
2
+ // A block scores a point in exactly ONE place in the sim (reception-simulator: a dig of a block fails
3
+ // and the block landed in-court, i.e. target >= 7). Each such rally is ONE block point regardless of how
4
+ // many blockers were on it; the box score records it as one `block_assists` per blocker (or one
5
+ // `block_solo`), which is why summing solo+assists over-counts block points. We rebuild the true count
6
+ // from the rallies. blockSolo / blockAssists must reconstruct box.block.solo and box.block.assists
7
+ // exactly (the correctness gate). `teamOf(playerId)` returns a player's team id (or null); the scoring
8
+ // team is the blockers' team.
9
+ export function tallyBlockPoints(rallies, teamOf) {
10
+ const out = new Map();
11
+ const tallyFor = (team) => {
12
+ let t = out.get(team);
13
+ if (t == null) {
14
+ t = { blockPoints: 0, blockSolo: 0, blockAssists: 0 };
15
+ out.set(team, t);
16
+ }
17
+ return t;
18
+ };
19
+ for (const rally of rallies) {
20
+ // Ignore substitutions / libero replacements (eventType < SERVE) when locating the terminal action.
21
+ const inPlay = rally.events.filter(e => e.eventType >= EventTypeEnum.SERVE);
22
+ const last = inPlay[inPlay.length - 1];
23
+ const prev = inPlay[inPlay.length - 2];
24
+ if (last == null || prev == null)
25
+ continue;
26
+ // Block point signature: the rally ends on a failed RECEPTION (dig) whose previous event is a BLOCK
27
+ // that landed in-court (target >= 7). target < 7 is a deflection -> the ATTACKER's kill, not a block.
28
+ if (last.eventType !== EventTypeEnum.RECEPTION || last.failure <= 0)
29
+ continue;
30
+ if (prev.eventType !== EventTypeEnum.BLOCK)
31
+ continue;
32
+ const block = prev;
33
+ if (block.target < 7)
34
+ continue;
35
+ const team = teamOf(block.blockers[0] ?? block.playerId);
36
+ if (team == null)
37
+ continue;
38
+ const t = tallyFor(team);
39
+ t.blockPoints++;
40
+ if (block.blockers.length < 2)
41
+ t.blockSolo++;
42
+ else
43
+ t.blockAssists += block.blockers.length;
44
+ }
45
+ return out;
46
+ }
47
+ // Kills/aces come straight from the box score; block points are derived from rallies; opponent errors
48
+ // are the remainder (>= 0 by construction). The four reconcile to the team's total points.
49
+ export function computePointBreakdown(input) {
50
+ const tally = tallyBlockPoints(input.rallies, input.teamOf);
51
+ const homeBlocks = tally.get(input.homeTeamId)?.blockPoints ?? 0;
52
+ const awayBlocks = tally.get(input.awayTeamId)?.blockPoints ?? 0;
53
+ return {
54
+ home: {
55
+ kills: input.homeKills,
56
+ aces: input.homeAces,
57
+ blockPoints: homeBlocks,
58
+ opponentErrors: input.homeTotalPoints - input.homeKills - input.homeAces - homeBlocks
59
+ },
60
+ away: {
61
+ kills: input.awayKills,
62
+ aces: input.awayAces,
63
+ blockPoints: awayBlocks,
64
+ opponentErrors: input.awayTotalPoints - input.awayKills - input.awayAces - awayBlocks
65
+ }
66
+ };
67
+ }
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it } from '@jest/globals';
2
+ import { EventTypeEnum } from '../event';
3
+ import { computePointBreakdown, tallyBlockPoints } from './point-breakdown';
4
+ const blockEvent = (playerId, target, blockers) => ({ eventType: EventTypeEnum.BLOCK, playerId, target, blockers });
5
+ const receptionEvent = (playerId, failure) => ({ eventType: EventTypeEnum.RECEPTION, playerId, failure });
6
+ const serveEvent = (playerId) => ({ eventType: EventTypeEnum.SERVE, playerId });
7
+ const spikeEvent = (playerId) => ({ eventType: EventTypeEnum.SPIKE, playerId });
8
+ const rally = (events) => ({ events });
9
+ const teamOf = (id) => id.startsWith('h') ? 'HOME' : id.startsWith('a') ? 'AWAY' : null;
10
+ describe('tallyBlockPoints', () => {
11
+ it('counts an assisted block point once, recording each blocker as an assist', () => {
12
+ const t = tallyBlockPoints([rally([blockEvent('h1', 8, ['h1', 'h2']), receptionEvent('a3', 1)])], teamOf);
13
+ expect(t.get('HOME')).toEqual({ blockPoints: 1, blockSolo: 0, blockAssists: 2 });
14
+ });
15
+ it('counts a solo block point', () => {
16
+ const t = tallyBlockPoints([rally([blockEvent('h1', 9, ['h1']), receptionEvent('a3', 2)])], teamOf);
17
+ expect(t.get('HOME')).toEqual({ blockPoints: 1, blockSolo: 1, blockAssists: 0 });
18
+ });
19
+ it('does NOT count a deflection (target < 7) - that is the attacker\'s kill', () => {
20
+ const t = tallyBlockPoints([rally([blockEvent('h1', 4, ['h1', 'h2']), receptionEvent('a3', 1)])], teamOf);
21
+ expect(t.size).toBe(0);
22
+ });
23
+ it('does NOT count an ace (reception fail after serve)', () => {
24
+ const t = tallyBlockPoints([rally([serveEvent('h1'), receptionEvent('a3', 1)])], teamOf);
25
+ expect(t.size).toBe(0);
26
+ });
27
+ it('does NOT count a successful dig (reception failure 0)', () => {
28
+ const t = tallyBlockPoints([rally([blockEvent('h1', 8, ['h1', 'h2']), receptionEvent('a3', 0), spikeEvent('a3')])], teamOf);
29
+ expect(t.size).toBe(0);
30
+ });
31
+ it('reconstructs box block.solo and block.assists across a mix (incl. a triple block)', () => {
32
+ const t = tallyBlockPoints([
33
+ rally([blockEvent('h1', 8, ['h1', 'h2']), receptionEvent('a3', 1)]), // double: +2 assists
34
+ rally([blockEvent('h3', 8, ['h3', 'h4', 'h5']), receptionEvent('a1', 1)]), // triple: +3 assists
35
+ rally([blockEvent('h1', 9, ['h1']), receptionEvent('a2', 1)]), // solo: +1 solo
36
+ rally([blockEvent('a1', 8, ['a1', 'a2']), receptionEvent('h2', 1)]) // away double
37
+ ], teamOf);
38
+ expect(t.get('HOME')).toEqual({ blockPoints: 3, blockSolo: 1, blockAssists: 5 });
39
+ expect(t.get('AWAY')).toEqual({ blockPoints: 1, blockSolo: 0, blockAssists: 2 });
40
+ });
41
+ });
42
+ describe('computePointBreakdown', () => {
43
+ it('reproduces the prod bug scenario as a positive number (was -3)', () => {
44
+ // AWAY scored 99 (54 kills, 0 aces) and 28 block points (8 solo + 20 doubles). Old formula did
45
+ // 99 - 54 - (8 + 40) - 0 = -3; correct is 99 - 54 - 0 - 28 = 17.
46
+ const rallies = [];
47
+ for (let i = 0; i < 20; i++)
48
+ rallies.push(rally([blockEvent('a1', 8, ['a1', 'a2']), receptionEvent(`h${i}`, 1)]));
49
+ for (let i = 0; i < 8; i++)
50
+ rallies.push(rally([blockEvent('a3', 9, ['a3']), receptionEvent(`h${i + 20}`, 1)]));
51
+ const out = computePointBreakdown({
52
+ rallies,
53
+ homeTeamId: 'HOME',
54
+ awayTeamId: 'AWAY',
55
+ teamOf,
56
+ homeKills: 51,
57
+ awayKills: 54,
58
+ homeAces: 3,
59
+ awayAces: 0,
60
+ homeTotalPoints: 108,
61
+ awayTotalPoints: 99
62
+ });
63
+ expect(out.away.blockPoints).toBe(28);
64
+ expect(out.away.opponentErrors).toBe(17);
65
+ expect(out.away.opponentErrors).toBeGreaterThanOrEqual(0);
66
+ // The four categories reconcile to the team's total points.
67
+ expect(out.away.kills + out.away.aces + out.away.blockPoints + out.away.opponentErrors).toBe(99);
68
+ expect(out.home.kills + out.home.aces + out.home.blockPoints + out.home.opponentErrors).toBe(108);
69
+ });
70
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volleyballsimtypes",
3
- "version": "0.0.417",
3
+ "version": "0.0.419",
4
4
  "description": "vbsim types",
5
5
  "main": "./dist/cjs/src/index.js",
6
6
  "module": "./dist/esm/src/index.js",