volleyballsimtypes 0.0.66 → 0.0.67

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.
@@ -1,4 +1,4 @@
1
1
  import { MatchRatingAttributes } from '../models';
2
- import { Match, MatchRating } from '../../service';
3
- declare function transformToAttributes(match: Match, teamId: string, rating: MatchRating): MatchRatingAttributes;
2
+ import { MatchRating, MatchTeam } from '../../service';
3
+ declare function transformToAttributes(team: MatchTeam, rating: MatchRating): MatchRatingAttributes;
4
4
  export { transformToAttributes as transformFromMatchRating };
@@ -2,16 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformFromMatchRating = void 0;
4
4
  const service_1 = require("../../service");
5
- function transformToAttributes(match, teamId, rating) {
6
- const team = match.homeTeam.id === teamId ? service_1.MatchTeam.HOME :
7
- match.awayTeam.id === teamId ? service_1.MatchTeam.AWAY : undefined;
5
+ function transformToAttributes(team, rating) {
6
+ const teamId = team === service_1.MatchTeam.HOME ? rating.home.id : rating.away.id;
8
7
  if (team == null)
9
8
  throw new Error(`INVALID_TEAM: ${teamId}`);
10
9
  return {
11
- match_id: match.id,
10
+ match_id: rating.match.id,
12
11
  team_id: teamId,
13
12
  p: rating.getWinProbability(team),
14
- dR: rating.getRatingChange(team, match)
13
+ dR: rating.getRatingChange(team)
15
14
  };
16
15
  }
17
16
  exports.transformFromMatchRating = transformToAttributes;
@@ -1,14 +1,17 @@
1
1
  import { Match, MatchTeam } from '.';
2
+ import { Team } from '../team';
2
3
  interface MatchRatingOpts {
3
- readonly homeRating: number;
4
- readonly awayRating: number;
4
+ readonly home: Team;
5
+ readonly away: Team;
6
+ readonly match: Match;
5
7
  }
6
8
  export declare class MatchRating {
7
9
  static K: number;
8
- readonly homeRating: number;
9
- readonly awayRating: number;
10
- constructor({ homeRating, awayRating }: MatchRatingOpts);
10
+ readonly home: Team;
11
+ readonly away: Team;
12
+ readonly match: Match;
13
+ constructor({ home, away, match }: MatchRatingOpts);
11
14
  getWinProbability(team: MatchTeam): number;
12
- getRatingChange(team: MatchTeam, match: Match): number;
15
+ getRatingChange(team: MatchTeam): number;
13
16
  }
14
17
  export {};
@@ -3,26 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MatchRating = void 0;
4
4
  const _1 = require(".");
5
5
  class MatchRating {
6
- constructor({ homeRating, awayRating }) {
7
- this.homeRating = homeRating;
8
- this.awayRating = awayRating;
6
+ constructor({ home, away, match }) {
7
+ this.home = home;
8
+ this.away = away;
9
+ this.match = match;
9
10
  }
10
11
  getWinProbability(team) {
11
12
  let rA;
12
13
  let rB;
13
14
  if (team === _1.MatchTeam.HOME) {
14
- rA = this.homeRating;
15
- rB = this.awayRating;
15
+ rA = this.home.rating;
16
+ rB = this.away.rating;
16
17
  }
17
18
  else {
18
- rA = this.awayRating;
19
- rB = this.homeRating;
19
+ rA = this.away.rating;
20
+ rB = this.home.rating;
20
21
  }
21
22
  return 1 / (1 + Math.pow(10, ((rB - rA) / 400)));
22
23
  }
23
- getRatingChange(team, match) {
24
- const t = match[team === _1.MatchTeam.HOME ? 'homeTeam' : 'awayTeam'];
25
- const score = match.getWinner().id === t.id ? 1 : 0;
24
+ getRatingChange(team) {
25
+ const t = this.match[team === _1.MatchTeam.HOME ? 'homeTeam' : 'awayTeam'];
26
+ const score = this.match.getWinner().id === t.id ? 1 : 0;
26
27
  return MatchRating.K * (score - this.getWinProbability(team));
27
28
  }
28
29
  }
@@ -1,4 +1,4 @@
1
1
  import { MatchRatingAttributes } from '../models';
2
- import { Match, MatchRating } from '../../service';
3
- declare function transformToAttributes(match: Match, teamId: string, rating: MatchRating): MatchRatingAttributes;
2
+ import { MatchRating, MatchTeam } from '../../service';
3
+ declare function transformToAttributes(team: MatchTeam, rating: MatchRating): MatchRatingAttributes;
4
4
  export { transformToAttributes as transformFromMatchRating };
@@ -1,14 +1,13 @@
1
1
  import { MatchTeam } from '../../service';
2
- function transformToAttributes(match, teamId, rating) {
3
- const team = match.homeTeam.id === teamId ? MatchTeam.HOME :
4
- match.awayTeam.id === teamId ? MatchTeam.AWAY : undefined;
2
+ function transformToAttributes(team, rating) {
3
+ const teamId = team === MatchTeam.HOME ? rating.home.id : rating.away.id;
5
4
  if (team == null)
6
5
  throw new Error(`INVALID_TEAM: ${teamId}`);
7
6
  return {
8
- match_id: match.id,
7
+ match_id: rating.match.id,
9
8
  team_id: teamId,
10
9
  p: rating.getWinProbability(team),
11
- dR: rating.getRatingChange(team, match)
10
+ dR: rating.getRatingChange(team)
12
11
  };
13
12
  }
14
13
  export { transformToAttributes as transformFromMatchRating };
@@ -1,14 +1,17 @@
1
1
  import { Match, MatchTeam } from '.';
2
+ import { Team } from '../team';
2
3
  interface MatchRatingOpts {
3
- readonly homeRating: number;
4
- readonly awayRating: number;
4
+ readonly home: Team;
5
+ readonly away: Team;
6
+ readonly match: Match;
5
7
  }
6
8
  export declare class MatchRating {
7
9
  static K: number;
8
- readonly homeRating: number;
9
- readonly awayRating: number;
10
- constructor({ homeRating, awayRating }: MatchRatingOpts);
10
+ readonly home: Team;
11
+ readonly away: Team;
12
+ readonly match: Match;
13
+ constructor({ home, away, match }: MatchRatingOpts);
11
14
  getWinProbability(team: MatchTeam): number;
12
- getRatingChange(team: MatchTeam, match: Match): number;
15
+ getRatingChange(team: MatchTeam): number;
13
16
  }
14
17
  export {};
@@ -1,25 +1,26 @@
1
1
  import { MatchTeam } from '.';
2
2
  export class MatchRating {
3
- constructor({ homeRating, awayRating }) {
4
- this.homeRating = homeRating;
5
- this.awayRating = awayRating;
3
+ constructor({ home, away, match }) {
4
+ this.home = home;
5
+ this.away = away;
6
+ this.match = match;
6
7
  }
7
8
  getWinProbability(team) {
8
9
  let rA;
9
10
  let rB;
10
11
  if (team === MatchTeam.HOME) {
11
- rA = this.homeRating;
12
- rB = this.awayRating;
12
+ rA = this.home.rating;
13
+ rB = this.away.rating;
13
14
  }
14
15
  else {
15
- rA = this.awayRating;
16
- rB = this.homeRating;
16
+ rA = this.away.rating;
17
+ rB = this.home.rating;
17
18
  }
18
19
  return 1 / (1 + Math.pow(10, ((rB - rA) / 400)));
19
20
  }
20
- getRatingChange(team, match) {
21
- const t = match[team === MatchTeam.HOME ? 'homeTeam' : 'awayTeam'];
22
- const score = match.getWinner().id === t.id ? 1 : 0;
21
+ getRatingChange(team) {
22
+ const t = this.match[team === MatchTeam.HOME ? 'homeTeam' : 'awayTeam'];
23
+ const score = this.match.getWinner().id === t.id ? 1 : 0;
23
24
  return MatchRating.K * (score - this.getWinProbability(team));
24
25
  }
25
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volleyballsimtypes",
3
- "version": "0.0.66",
3
+ "version": "0.0.67",
4
4
  "description": "vbsim types",
5
5
  "main": "./dist/cjs/src/index.js",
6
6
  "module": "./dist/esm/src/index.js",