volleyballsimtypes 0.0.10 → 0.0.11

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,7 +1,5 @@
1
1
  import { Season } from './season';
2
2
  import { Country } from '../country';
3
- import { Team } from '../team';
4
- import { Match } from '../match';
5
3
  export interface LeagueOpts {
6
4
  readonly id: string;
7
5
  readonly name: string;
@@ -14,6 +12,4 @@ export declare class League {
14
12
  readonly seasons: Season[];
15
13
  readonly country: Country;
16
14
  constructor({ id, name, country, seasons }: LeagueOpts);
17
- newSeason(teams: Team[]): Season;
18
- static generateMatches(teams: Team[], baseDate: Date): Match[];
19
15
  }
@@ -1,14 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.League = void 0;
7
- const season_1 = require("./season");
8
- const match_1 = require("../match");
9
- const moment_1 = __importDefault(require("moment/moment"));
10
- const utils_1 = require("../utils");
11
- const uuid_1 = require("uuid");
12
4
  class League {
13
5
  constructor({ id, name, country, seasons }) {
14
6
  this.id = id;
@@ -16,72 +8,5 @@ class League {
16
8
  this.country = country;
17
9
  this.seasons = seasons;
18
10
  }
19
- newSeason(teams) {
20
- const matches = League.generateMatches(teams, (0, moment_1.default)().add(4, 'hour').toDate());
21
- const season = new season_1.Season({
22
- id: (0, uuid_1.v4)(),
23
- iteration: this.seasons.length,
24
- teams,
25
- matches
26
- });
27
- this.seasons.push(season);
28
- return season;
29
- }
30
- static generateMatches(teams, baseDate) {
31
- const t = new Set(teams.map(x => x.id));
32
- const date = (0, moment_1.default)(baseDate);
33
- date.startOf('hour');
34
- if (t.size !== teams.length) {
35
- throw new Error('DUPLICATE_TEAMS');
36
- }
37
- let shuffled = (0, utils_1.shuffle)([...teams]);
38
- const l = shuffled.length - 1;
39
- const half = Math.ceil(shuffled.length / 2);
40
- const matches = [];
41
- // We fix the first team
42
- let firstTeam = shuffled.shift();
43
- if (firstTeam == null) {
44
- throw new Error('EMPTY_TEAM_ARRAY');
45
- }
46
- let homeRow;
47
- let awayRow;
48
- for (let i = 0; i < l; i++) {
49
- // split array in 2 halves
50
- const row1 = shuffled.slice(0, half);
51
- const row2 = shuffled.slice(half);
52
- const scheduledDate = date.add(30, 'minutes').toDate();
53
- row2.push(firstTeam);
54
- if (i % 2 === 0) {
55
- homeRow = row1;
56
- awayRow = row2;
57
- }
58
- else {
59
- homeRow = row2;
60
- awayRow = row1;
61
- }
62
- for (let j = 0; j < half; j++) {
63
- matches.push(new match_1.Match({
64
- id: (0, uuid_1.v4)(),
65
- homeTeam: homeRow[j],
66
- awayTeam: awayRow[j],
67
- scheduledDate,
68
- sets: []
69
- }));
70
- }
71
- firstTeam = row2.pop();
72
- row1.unshift(row2.shift());
73
- row2.push(row1.pop());
74
- shuffled = [...row1, ...row2];
75
- }
76
- // Generate Inverted matches for home-away pairings
77
- matches.push(...matches.map(match => new match_1.Match({
78
- id: (0, uuid_1.v4)(),
79
- homeTeam: match.awayTeam,
80
- awayTeam: match.homeTeam,
81
- scheduledDate: date.add(30, 'minutes').toDate(),
82
- sets: []
83
- })));
84
- return matches;
85
- }
86
11
  }
87
12
  exports.League = League;
@@ -1,7 +1,5 @@
1
1
  import { Season } from './season';
2
2
  import { Country } from '../country';
3
- import { Team } from '../team';
4
- import { Match } from '../match';
5
3
  export interface LeagueOpts {
6
4
  readonly id: string;
7
5
  readonly name: string;
@@ -14,6 +12,4 @@ export declare class League {
14
12
  readonly seasons: Season[];
15
13
  readonly country: Country;
16
14
  constructor({ id, name, country, seasons }: LeagueOpts);
17
- newSeason(teams: Team[]): Season;
18
- static generateMatches(teams: Team[], baseDate: Date): Match[];
19
15
  }
@@ -1,8 +1,3 @@
1
- import { Season } from './season';
2
- import { Match } from '../match';
3
- import moment from 'moment/moment';
4
- import { shuffle } from '../utils';
5
- import { v4 as uuidv4 } from 'uuid';
6
1
  export class League {
7
2
  constructor({ id, name, country, seasons }) {
8
3
  this.id = id;
@@ -10,71 +5,4 @@ export class League {
10
5
  this.country = country;
11
6
  this.seasons = seasons;
12
7
  }
13
- newSeason(teams) {
14
- const matches = League.generateMatches(teams, moment().add(4, 'hour').toDate());
15
- const season = new Season({
16
- id: uuidv4(),
17
- iteration: this.seasons.length,
18
- teams,
19
- matches
20
- });
21
- this.seasons.push(season);
22
- return season;
23
- }
24
- static generateMatches(teams, baseDate) {
25
- const t = new Set(teams.map(x => x.id));
26
- const date = moment(baseDate);
27
- date.startOf('hour');
28
- if (t.size !== teams.length) {
29
- throw new Error('DUPLICATE_TEAMS');
30
- }
31
- let shuffled = shuffle([...teams]);
32
- const l = shuffled.length - 1;
33
- const half = Math.ceil(shuffled.length / 2);
34
- const matches = [];
35
- // We fix the first team
36
- let firstTeam = shuffled.shift();
37
- if (firstTeam == null) {
38
- throw new Error('EMPTY_TEAM_ARRAY');
39
- }
40
- let homeRow;
41
- let awayRow;
42
- for (let i = 0; i < l; i++) {
43
- // split array in 2 halves
44
- const row1 = shuffled.slice(0, half);
45
- const row2 = shuffled.slice(half);
46
- const scheduledDate = date.add(30, 'minutes').toDate();
47
- row2.push(firstTeam);
48
- if (i % 2 === 0) {
49
- homeRow = row1;
50
- awayRow = row2;
51
- }
52
- else {
53
- homeRow = row2;
54
- awayRow = row1;
55
- }
56
- for (let j = 0; j < half; j++) {
57
- matches.push(new Match({
58
- id: uuidv4(),
59
- homeTeam: homeRow[j],
60
- awayTeam: awayRow[j],
61
- scheduledDate,
62
- sets: []
63
- }));
64
- }
65
- firstTeam = row2.pop();
66
- row1.unshift(row2.shift());
67
- row2.push(row1.pop());
68
- shuffled = [...row1, ...row2];
69
- }
70
- // Generate Inverted matches for home-away pairings
71
- matches.push(...matches.map(match => new Match({
72
- id: uuidv4(),
73
- homeTeam: match.awayTeam,
74
- awayTeam: match.homeTeam,
75
- scheduledDate: date.add(30, 'minutes').toDate(),
76
- sets: []
77
- })));
78
- return matches;
79
- }
80
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volleyballsimtypes",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "vbsim types",
5
5
  "main": "./dist/cjs/src/index.js",
6
6
  "module": "./dist/esm/src/index.js",