volleyballsimtypes 0.0.215 → 0.0.217
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.
- package/dist/cjs/src/data/models/competition-standings.d.ts +2 -0
- package/dist/cjs/src/data/models/competition-standings.js +1 -0
- package/dist/cjs/src/data/models/competition.js +3 -0
- package/dist/cjs/src/service/competition/season.js +1 -1
- package/dist/cjs/src/service/competition/standing.d.ts +1 -1
- package/dist/cjs/src/service/competition/standing.js +26 -15
- package/dist/esm/src/data/models/competition-standings.d.ts +2 -0
- package/dist/esm/src/data/models/competition-standings.js +1 -0
- package/dist/esm/src/data/models/competition.js +4 -1
- package/dist/esm/src/service/competition/season.js +1 -1
- package/dist/esm/src/service/competition/standing.d.ts +1 -1
- package/dist/esm/src/service/competition/standing.js +26 -15
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { CompetitionId, CompetitionModel, TeamId, TeamModel } from '.';
|
|
|
4
4
|
export interface CompetitionStandingsAttributes {
|
|
5
5
|
competition_id: string;
|
|
6
6
|
team_id: string;
|
|
7
|
+
position?: number | null;
|
|
7
8
|
won30: number;
|
|
8
9
|
won31: number;
|
|
9
10
|
won32: number;
|
|
@@ -25,6 +26,7 @@ export type CompetitionStandingsCreationAttributes = CompetitionStandingsAttribu
|
|
|
25
26
|
export declare class CompetitionStandingsModel extends Model<CompetitionStandingsAttributes, CompetitionStandingsCreationAttributes> implements CompetitionStandingsAttributes {
|
|
26
27
|
competition_id: string;
|
|
27
28
|
team_id: string;
|
|
29
|
+
position: number | null;
|
|
28
30
|
won30: number;
|
|
29
31
|
won31: number;
|
|
30
32
|
won32: number;
|
|
@@ -23,6 +23,7 @@ class CompetitionStandingsModel extends sequelize_1.Model {
|
|
|
23
23
|
key: 'team_id'
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
+
position: { type: sequelize_1.DataTypes.INTEGER, allowNull: true },
|
|
26
27
|
won30: { type: sequelize_1.DataTypes.BIGINT, allowNull: false },
|
|
27
28
|
won31: { type: sequelize_1.DataTypes.BIGINT, allowNull: false },
|
|
28
29
|
won32: { type: sequelize_1.DataTypes.BIGINT, allowNull: false },
|
|
@@ -13,7 +13,7 @@ class Season {
|
|
|
13
13
|
this._champion = champion;
|
|
14
14
|
this.standings = standings ?? this.calculateStandings();
|
|
15
15
|
this._status = status;
|
|
16
|
-
this.standings.sort(standing_1.Standing.sortFn);
|
|
16
|
+
this.standings.sort(standing_1.Standing.sortFn(matches));
|
|
17
17
|
}
|
|
18
18
|
calculateStandings() {
|
|
19
19
|
return this.teams.map(team => {
|
|
@@ -35,7 +35,7 @@ export declare class Standing {
|
|
|
35
35
|
matchesLost: number;
|
|
36
36
|
totalMatches: number;
|
|
37
37
|
constructor(opts: StandingOpts);
|
|
38
|
-
static sortFn(
|
|
38
|
+
static sortFn(matches: Match[]): (a: Standing, b: Standing) => number;
|
|
39
39
|
calculateStanding(matches: Match[]): void;
|
|
40
40
|
}
|
|
41
41
|
export {};
|
|
@@ -22,21 +22,32 @@ class Standing {
|
|
|
22
22
|
this.matchesLost = opts.matchesLost ?? 0;
|
|
23
23
|
this.totalMatches = opts.totalMatches ?? 0;
|
|
24
24
|
}
|
|
25
|
-
static sortFn(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
static sortFn(matches) {
|
|
26
|
+
return (standingA, standingB) => {
|
|
27
|
+
if (standingB.points > standingA.points)
|
|
28
|
+
return 1;
|
|
29
|
+
else if (standingA.points > standingB.points)
|
|
30
|
+
return -1;
|
|
31
|
+
else if (standingB.setsRatio > standingA.setsRatio)
|
|
32
|
+
return 1;
|
|
33
|
+
else if (standingA.setsRatio > standingB.setsRatio)
|
|
34
|
+
return -1;
|
|
35
|
+
else if (standingB.pointsRatio > standingA.pointsRatio)
|
|
36
|
+
return 1;
|
|
37
|
+
else if (standingA.pointsRatio > standingB.pointsRatio)
|
|
38
|
+
return -1;
|
|
39
|
+
else if (matches.length > 0) {
|
|
40
|
+
const ab = matches.find((match) => match.homeTeam.id === standingA.teamId && match.awayTeam.id === standingB.teamId);
|
|
41
|
+
const ba = matches.find((match) => match.awayTeam.id === standingA.teamId && match.homeTeam.id === standingB.teamId);
|
|
42
|
+
if (ba == null || ab == null)
|
|
43
|
+
throw new Error(`MATCHES_NOT_FOUND: teamA=${standingA.teamId} teamB=${standingB.teamId}`);
|
|
44
|
+
const a = (ab.homeScore ?? 0) + (ba.awayScore ?? 0);
|
|
45
|
+
const b = (ba.homeScore ?? 0) + (ab.awayScore ?? 0);
|
|
46
|
+
return b - a;
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
return 0;
|
|
50
|
+
};
|
|
40
51
|
}
|
|
41
52
|
calculateStanding(matches) {
|
|
42
53
|
matches = matches.filter(match => match.homeTeam.id === this.teamId || match.awayTeam.id === this.teamId)
|
|
@@ -4,6 +4,7 @@ import { CompetitionId, CompetitionModel, TeamId, TeamModel } from '.';
|
|
|
4
4
|
export interface CompetitionStandingsAttributes {
|
|
5
5
|
competition_id: string;
|
|
6
6
|
team_id: string;
|
|
7
|
+
position?: number | null;
|
|
7
8
|
won30: number;
|
|
8
9
|
won31: number;
|
|
9
10
|
won32: number;
|
|
@@ -25,6 +26,7 @@ export type CompetitionStandingsCreationAttributes = CompetitionStandingsAttribu
|
|
|
25
26
|
export declare class CompetitionStandingsModel extends Model<CompetitionStandingsAttributes, CompetitionStandingsCreationAttributes> implements CompetitionStandingsAttributes {
|
|
26
27
|
competition_id: string;
|
|
27
28
|
team_id: string;
|
|
29
|
+
position: number | null;
|
|
28
30
|
won30: number;
|
|
29
31
|
won31: number;
|
|
30
32
|
won32: number;
|
|
@@ -20,6 +20,7 @@ export class CompetitionStandingsModel extends Model {
|
|
|
20
20
|
key: 'team_id'
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
+
position: { type: DataTypes.INTEGER, allowNull: true },
|
|
23
24
|
won30: { type: DataTypes.BIGINT, allowNull: false },
|
|
24
25
|
won31: { type: DataTypes.BIGINT, allowNull: false },
|
|
25
26
|
won32: { type: DataTypes.BIGINT, allowNull: false },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataTypes, Model } from 'sequelize';
|
|
2
|
-
import { IterationModel } from '.';
|
|
2
|
+
import { DivisionSeasonModel, IterationModel } from '.';
|
|
3
3
|
import { StatusDataType } from '../common';
|
|
4
4
|
export class CompetitionModel extends Model {
|
|
5
5
|
static initModel(sequelize) {
|
|
@@ -35,6 +35,9 @@ export class CompetitionModel extends Model {
|
|
|
35
35
|
include: [{
|
|
36
36
|
model: IterationModel,
|
|
37
37
|
as: 'Iteration'
|
|
38
|
+
}, {
|
|
39
|
+
model: DivisionSeasonModel,
|
|
40
|
+
as: 'DivisionSeason'
|
|
38
41
|
}]
|
|
39
42
|
},
|
|
40
43
|
indexes: [{
|
|
@@ -10,7 +10,7 @@ export class Season {
|
|
|
10
10
|
this._champion = champion;
|
|
11
11
|
this.standings = standings ?? this.calculateStandings();
|
|
12
12
|
this._status = status;
|
|
13
|
-
this.standings.sort(Standing.sortFn);
|
|
13
|
+
this.standings.sort(Standing.sortFn(matches));
|
|
14
14
|
}
|
|
15
15
|
calculateStandings() {
|
|
16
16
|
return this.teams.map(team => {
|
|
@@ -35,7 +35,7 @@ export declare class Standing {
|
|
|
35
35
|
matchesLost: number;
|
|
36
36
|
totalMatches: number;
|
|
37
37
|
constructor(opts: StandingOpts);
|
|
38
|
-
static sortFn(
|
|
38
|
+
static sortFn(matches: Match[]): (a: Standing, b: Standing) => number;
|
|
39
39
|
calculateStanding(matches: Match[]): void;
|
|
40
40
|
}
|
|
41
41
|
export {};
|
|
@@ -19,21 +19,32 @@ export class Standing {
|
|
|
19
19
|
this.matchesLost = opts.matchesLost ?? 0;
|
|
20
20
|
this.totalMatches = opts.totalMatches ?? 0;
|
|
21
21
|
}
|
|
22
|
-
static sortFn(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
static sortFn(matches) {
|
|
23
|
+
return (standingA, standingB) => {
|
|
24
|
+
if (standingB.points > standingA.points)
|
|
25
|
+
return 1;
|
|
26
|
+
else if (standingA.points > standingB.points)
|
|
27
|
+
return -1;
|
|
28
|
+
else if (standingB.setsRatio > standingA.setsRatio)
|
|
29
|
+
return 1;
|
|
30
|
+
else if (standingA.setsRatio > standingB.setsRatio)
|
|
31
|
+
return -1;
|
|
32
|
+
else if (standingB.pointsRatio > standingA.pointsRatio)
|
|
33
|
+
return 1;
|
|
34
|
+
else if (standingA.pointsRatio > standingB.pointsRatio)
|
|
35
|
+
return -1;
|
|
36
|
+
else if (matches.length > 0) {
|
|
37
|
+
const ab = matches.find((match) => match.homeTeam.id === standingA.teamId && match.awayTeam.id === standingB.teamId);
|
|
38
|
+
const ba = matches.find((match) => match.awayTeam.id === standingA.teamId && match.homeTeam.id === standingB.teamId);
|
|
39
|
+
if (ba == null || ab == null)
|
|
40
|
+
throw new Error(`MATCHES_NOT_FOUND: teamA=${standingA.teamId} teamB=${standingB.teamId}`);
|
|
41
|
+
const a = (ab.homeScore ?? 0) + (ba.awayScore ?? 0);
|
|
42
|
+
const b = (ba.homeScore ?? 0) + (ab.awayScore ?? 0);
|
|
43
|
+
return b - a;
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
return 0;
|
|
47
|
+
};
|
|
37
48
|
}
|
|
38
49
|
calculateStanding(matches) {
|
|
39
50
|
matches = matches.filter(match => match.homeTeam.id === this.teamId || match.awayTeam.id === this.teamId)
|