basketball 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -7
- data/README.md +26 -24
- data/basketball.gemspec +2 -2
- data/exe/basketball-draft +1 -1
- data/exe/{basketball-schedule → basketball-season-scheduling} +1 -1
- data/lib/basketball/{drafting → draft}/cli.rb +34 -34
- data/lib/basketball/{drafting → draft}/event.rb +1 -1
- data/lib/basketball/{drafting → draft}/front_office.rb +1 -1
- data/lib/basketball/{drafting → draft}/league.rb +1 -1
- data/lib/basketball/{drafting → draft}/pick_event.rb +1 -1
- data/lib/basketball/{drafting → draft}/player.rb +1 -1
- data/lib/basketball/{drafting → draft}/player_search.rb +1 -1
- data/lib/basketball/{drafting → draft}/position.rb +1 -1
- data/lib/basketball/{drafting/engine.rb → draft/room.rb} +2 -2
- data/lib/basketball/{drafting/engine_serializer.rb → draft/room_serializer.rb} +33 -33
- data/lib/basketball/{drafting → draft}/roster.rb +1 -1
- data/lib/basketball/{drafting → draft}/sim_event.rb +1 -1
- data/lib/basketball/{drafting → draft}/skip_event.rb +1 -1
- data/lib/basketball/{drafting.rb → draft.rb} +2 -2
- data/lib/basketball/{scheduling → season}/calendar.rb +1 -1
- data/lib/basketball/{scheduling → season}/calendar_serializer.rb +1 -1
- data/lib/basketball/{scheduling → season}/conference.rb +1 -1
- data/lib/basketball/{scheduling → season}/coordinator.rb +2 -2
- data/lib/basketball/{scheduling → season}/division.rb +1 -1
- data/lib/basketball/{scheduling → season}/game.rb +1 -1
- data/lib/basketball/{scheduling → season}/league.rb +1 -1
- data/lib/basketball/{scheduling → season}/league_serializer.rb +1 -1
- data/lib/basketball/{scheduling → season}/preseason_game.rb +1 -1
- data/lib/basketball/{scheduling/cli.rb → season/scheduling_cli.rb} +9 -9
- data/lib/basketball/{scheduling → season}/season_game.rb +1 -1
- data/lib/basketball/{scheduling → season}/team.rb +1 -1
- data/lib/basketball/{scheduling.rb → season.rb} +2 -2
- data/lib/basketball/version.rb +1 -1
- data/lib/basketball.rb +2 -2
- metadata +32 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6417577ab066cf68ac376551774f538e5ba1d018139e2d2e99af4a607acf10e
|
4
|
+
data.tar.gz: 2bf491b44bfb3591e411e105c33353f20044933662dc8f4a64999144f943bd3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbc69e448e39af4cb2a1df48d2e1fa729cc3eb85868b15eb8127aaac32ed57672c3c16cc1afa38cc147b2e9770e06bf89df9325a737ee1ea4f067afb253ced92
|
7
|
+
data.tar.gz: 1b0046ce516d37e5d1b86f818213b2e0dd1197be910338bc380a653aecb9158bdb85f5647452f2889ebba4fe2dc7b02b85ce2df4d32bae814d7ea10563bb1204
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
|
2
|
+
#### 0.0.8 - May 15th, 2023
|
3
|
+
|
4
|
+
* Renamed Drafting to Draft to match bounded context word form.
|
5
|
+
* Renamed Drafting::Engine to Draft::Room for better language.
|
6
|
+
* Renamed Scheduling to Season to include more things other than scheduling.
|
7
|
+
* Issued README warning for 0.0.X releases not having stable APIs.
|
8
|
+
|
1
9
|
#### 0.0.7 - May 14th, 2023
|
2
10
|
|
3
11
|
* Added #to_hash and #from_hash serializer methods to allow larger consumer json constructions more directly.
|
@@ -5,22 +13,22 @@
|
|
5
13
|
|
6
14
|
#### 0.0.6 - May 11th, 2023
|
7
15
|
|
8
|
-
* Added
|
9
|
-
*
|
16
|
+
* Added Season module that can generate full schedules for entire league.
|
17
|
+
* Draft::Event does not have identity anymore (no current tangible benefit).
|
10
18
|
|
11
19
|
#### 0.0.5 - May 5th, 2023
|
12
20
|
|
13
21
|
* Remove the notion of Team in favor of a flat front office.
|
14
22
|
#### 0.0.4 - May 5th, 2023
|
15
23
|
|
16
|
-
* Add ability to skip draft picks using `Basketball::
|
17
|
-
* Add ability to output event full
|
24
|
+
* Add ability to skip draft picks using `Basketball::Draft::Room#skip!`
|
25
|
+
* Add ability to output event full draft event log using CLI: `basketball-draft -i tmp/draft-wip.json -l`
|
18
26
|
* Add ability to skip draft picks using CLI: `basketball-draft -i tmp/draft-wip.json -x 1`
|
19
27
|
|
20
28
|
#### 0.0.3 - May 5th, 2023
|
21
29
|
|
22
|
-
* `
|
23
|
-
* Added `
|
30
|
+
* `Draft::Room#sim!` should return events
|
31
|
+
* Added `Draft::Room#undrafted_player_search`
|
24
32
|
|
25
33
|
#### 0.0.2 - May 4th, 2023
|
26
34
|
|
@@ -28,4 +36,4 @@
|
|
28
36
|
|
29
37
|
#### 0.0.1 - May 4th, 2023
|
30
38
|
|
31
|
-
* Initial release with
|
39
|
+
* Initial release with Draft module only
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/basketball.svg)](https://badge.fury.io/rb/basketball) [![CI](https://github.com/mattruggio/basketball/actions/workflows/ci.yaml/badge.svg)](https://github.com/mattruggio/basketball/actions/workflows/ci.yaml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
4
4
|
|
5
|
-
|
5
|
+
:warning: **Note:** This is currently in the early phases of initial development. Consider all 0.0.X releases as having unstable APIs between versions. A formal 0.1 minor release will be eventually releases which will honor [Semver](https://semver.org/).
|
6
|
+
|
7
|
+
#### Basketball League Game Room
|
6
8
|
|
7
9
|
This library is meant to serve as the domain for a basketball league/season simulator/turn-based game. It models core ideas such as: players, general managers, draft strategy, drafting, season generation, season simultation, playoff generation, playoff simulation, and more.
|
8
10
|
|
@@ -30,24 +32,24 @@ bundle binstubs basketball
|
|
30
32
|
|
31
33
|
This library is broken down into several bounded contexts that can be consumed either via its Ruby API's or CLI through provided executable scripts:
|
32
34
|
|
33
|
-
![Basketball Architecture - Overview](/docs/architecture/
|
35
|
+
![Basketball Architecture - Overview](/docs/architecture/Basketball%20Architecture%20-%20Overview.png)
|
34
36
|
|
35
37
|
#### Command Line Interfaces
|
36
38
|
|
37
39
|
Each module is meant to be interfaced with using its Ruby API by consuming applications. Each module also ships with a CLI script (backed by a module service) which a user can interact with to emulate different portions of the league management process. Technically speaking, the CLI provides an example application built on top of the each individual core module. Each module section below should contain with it example CLI calls.
|
38
40
|
|
39
|
-
##
|
41
|
+
## Draft Module
|
40
42
|
|
41
|
-
The
|
43
|
+
The draft module is responsible for providing a turn-based iterator allowing the consumer to either manually pick or simulate picks. Here is a cartoon showing the major components:
|
42
44
|
|
43
|
-
![Basketball Architecture -
|
45
|
+
![Basketball Architecture - Draft](/docs/architecture/Basketball%20Architecture%20-%20Draft.png)
|
44
46
|
|
45
47
|
Element | Description
|
46
48
|
:------------ | :-----------
|
47
|
-
**
|
48
|
-
**
|
49
|
-
**Event** | Represents one cycle execution result from the
|
50
|
-
**External Ruby App** | An example consumer for the
|
49
|
+
**Draft** | Bounded context (sub-module) dealing with executing an asynchronous draft.
|
50
|
+
**Room** | Aggregate root responsible for providing an iterable interface capable of executing a draft, pick by pick.
|
51
|
+
**Event** | Represents one cycle execution result from the Room.
|
52
|
+
**External Ruby App** | An example consumer for the Draft context.
|
51
53
|
**Front Office** | Identifiable as a team, contains configuration for how to auto-pick draft selections.
|
52
54
|
**League** | Set of rosters that together form a cohesive league.
|
53
55
|
**Pick Event** | Result event emitted when a player is manually selected.
|
@@ -57,9 +59,9 @@ Element | Description
|
|
57
59
|
**Sim Event** | Result event emitted when a player is automatically selected by a front office.
|
58
60
|
**Skip Event** | Result event emitted when a front office decides to skip a round.
|
59
61
|
|
60
|
-
#### The
|
62
|
+
#### The Draft CLI
|
61
63
|
|
62
|
-
The
|
64
|
+
The draft module's main object: `Basketball::Draft::Room` is a stateful iterator. Each time a CLI command is executed, it's results will be re-saved to disk so the output file can then be used as the next command's input file to string together commands.
|
63
65
|
|
64
66
|
###### Generate a Fresh Draft
|
65
67
|
|
@@ -121,11 +123,11 @@ basketball-draft -i tmp/draft.json -a
|
|
121
123
|
basketball-draft -h
|
122
124
|
```
|
123
125
|
|
124
|
-
##
|
126
|
+
## Season Module
|
125
127
|
|
126
|
-
The
|
128
|
+
The Season module is meant to take a League (conferences/divisions/teams) and turn it into a Calendar. This Calendar creation is atomic - the full calendar will be generated completely all in one call. Here is a cartoon showing the major components:
|
127
129
|
|
128
|
-
![Basketball Architecture -
|
130
|
+
![Basketball Architecture - Season](/docs/architecture/Basketball%20Architecture%20-%20Season.png)
|
129
131
|
|
130
132
|
Element | Description
|
131
133
|
:------------ | :-----------
|
@@ -139,57 +141,57 @@ Element | Description
|
|
139
141
|
**Home Team** | Team object designated as the home team for a Game.
|
140
142
|
**League Serializer** | Understands how to serialize and deserialize a League object.
|
141
143
|
**League** | Describes a league in terms of structure; composed of an array conferences (there can only be 2).
|
142
|
-
**
|
144
|
+
**Season** | Bounded context (sub-module) dealing with calendar and matchup generation.
|
143
145
|
**Team** | Identified by an ID and described by a name: represents a basketball team that can be scheduled.
|
144
146
|
|
145
|
-
#### The
|
147
|
+
#### The Season CLI
|
146
148
|
|
147
149
|
###### Generate League
|
148
150
|
|
149
151
|
```zsh
|
150
|
-
basketball-
|
152
|
+
basketball-season-scheduling -o tmp/league.json
|
151
153
|
```
|
152
154
|
|
153
155
|
###### Generate Calendar From League
|
154
156
|
|
155
157
|
```zsh
|
156
|
-
basketball-
|
158
|
+
basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json
|
157
159
|
```
|
158
160
|
|
159
161
|
###### Generate Calendar From League For a Specific Year
|
160
162
|
|
161
163
|
```zsh
|
162
|
-
basketball-
|
164
|
+
basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json -y 2005
|
163
165
|
```
|
164
166
|
|
165
167
|
###### Output a Generated Calendar's Matchups
|
166
168
|
|
167
169
|
```zsh
|
168
|
-
basketball-
|
170
|
+
basketball-season-scheduling -c tmp/calendar.json
|
169
171
|
```
|
170
172
|
|
171
173
|
###### Output a Generated Calendar's Matchups For a Specific Team
|
172
174
|
|
173
175
|
```zsh
|
174
|
-
basketball-
|
176
|
+
basketball-season-scheduling -c tmp/calendar.json -t C0-D0-T0
|
175
177
|
```
|
176
178
|
|
177
179
|
###### Output a Generated Calendar's Matchups For a Specific Date
|
178
180
|
|
179
181
|
```zsh
|
180
|
-
basketball-
|
182
|
+
basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03
|
181
183
|
```
|
182
184
|
|
183
185
|
###### Output a Generated Calendar's Matchups For a Specific Team and Date
|
184
186
|
|
185
187
|
```zsh
|
186
|
-
basketball-
|
188
|
+
basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03 -t C0-D0-T0
|
187
189
|
```
|
188
190
|
|
189
191
|
###### Help Menu
|
190
192
|
|
191
193
|
```zsh
|
192
|
-
basketball-
|
194
|
+
basketball-season-scheduling -h
|
193
195
|
```
|
194
196
|
|
195
197
|
## Contributing
|
data/basketball.gemspec
CHANGED
@@ -5,7 +5,7 @@ require './lib/basketball/version'
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'basketball'
|
7
7
|
s.version = Basketball::VERSION
|
8
|
-
s.summary = 'Basketball League Game
|
8
|
+
s.summary = 'Basketball League Game Room'
|
9
9
|
|
10
10
|
s.description = <<-DESC
|
11
11
|
This library is meant to serve as the domain for a basketball league/season simulator/turn-based game.
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.email = ['mattruggio@icloud.com']
|
18
18
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(.github|bin|docs|spec)/}) }
|
19
19
|
s.bindir = 'exe'
|
20
|
-
s.executables = %w[basketball-draft basketball-
|
20
|
+
s.executables = %w[basketball-draft basketball-season-scheduling]
|
21
21
|
s.homepage = 'https://github.com/mattruggio/basketball'
|
22
22
|
s.license = 'MIT'
|
23
23
|
s.metadata = {
|
data/exe/basketball-draft
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
4
|
-
require_relative '
|
3
|
+
require_relative 'room'
|
4
|
+
require_relative 'room_serializer'
|
5
5
|
require_relative 'player_search'
|
6
6
|
require_relative 'position'
|
7
7
|
|
8
8
|
module Basketball
|
9
|
-
module
|
9
|
+
module Draft
|
10
10
|
# Examples:
|
11
11
|
# exe/basketball-draft -o tmp/draft.json
|
12
12
|
# exe/basketball-draft -i tmp/draft.json -o tmp/draft-wip.json -s 26 -p P-5,P-10 -t 10 -q PG
|
@@ -23,7 +23,7 @@ module Basketball
|
|
23
23
|
|
24
24
|
def initialize(args:, io: $stdout)
|
25
25
|
@io = io
|
26
|
-
@serializer =
|
26
|
+
@serializer = RoomSerializer.new
|
27
27
|
@opts = slop_parse(args)
|
28
28
|
|
29
29
|
if opts[:input].to_s.empty? && opts[:output].to_s.empty?
|
@@ -36,31 +36,31 @@ module Basketball
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def invoke!
|
39
|
-
|
39
|
+
room = load_room
|
40
40
|
|
41
|
-
execute(
|
41
|
+
execute(room)
|
42
42
|
|
43
43
|
io.puts
|
44
44
|
io.puts('Status')
|
45
45
|
|
46
|
-
if
|
46
|
+
if room.done?
|
47
47
|
io.puts('Draft is complete!')
|
48
48
|
else
|
49
|
-
current_round =
|
50
|
-
current_round_pick =
|
51
|
-
current_front_office =
|
49
|
+
current_round = room.current_round
|
50
|
+
current_round_pick = room.current_round_pick
|
51
|
+
current_front_office = room.current_front_office
|
52
52
|
|
53
|
-
io.puts("#{
|
53
|
+
io.puts("#{room.remaining_picks} Remaining pick(s)")
|
54
54
|
io.puts("Up Next: Round #{current_round} pick #{current_round_pick} for #{current_front_office}")
|
55
55
|
end
|
56
56
|
|
57
|
-
write(
|
57
|
+
write(room)
|
58
58
|
|
59
|
-
log(
|
59
|
+
log(room)
|
60
60
|
|
61
|
-
league(
|
61
|
+
league(room)
|
62
62
|
|
63
|
-
query(
|
63
|
+
query(room)
|
64
64
|
|
65
65
|
self
|
66
66
|
end
|
@@ -72,8 +72,8 @@ module Basketball
|
|
72
72
|
o.banner = 'Usage: basketball-draft [options] ...'
|
73
73
|
|
74
74
|
o.string '-i', '--input',
|
75
|
-
'Path to load the
|
76
|
-
o.string '-o', '--output', 'Path to write the
|
75
|
+
'Path to load the room from. If omitted then a new draft will be generated.'
|
76
|
+
o.string '-o', '--output', 'Path to write the room to (if omitted then input path will be used)'
|
77
77
|
o.integer '-s', '--simulate', 'Number of picks to simulate (default is 0).', default: 0
|
78
78
|
o.bool '-a', '--simulate-all', 'Simulate the rest of the draft', default: false
|
79
79
|
o.array '-p', '--picks', 'Comma-separated list of ordered player IDs to pick.', delimiter: ','
|
@@ -90,7 +90,7 @@ module Basketball
|
|
90
90
|
end.to_h
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
93
|
+
def load_room
|
94
94
|
if opts[:input].to_s.empty?
|
95
95
|
io.puts('Input path was not provided, generating fresh front_offices and players')
|
96
96
|
|
@@ -119,32 +119,32 @@ module Basketball
|
|
119
119
|
)
|
120
120
|
end
|
121
121
|
|
122
|
-
|
122
|
+
Room.new(players:, front_offices:)
|
123
123
|
end
|
124
124
|
|
125
|
-
def league(
|
125
|
+
def league(room)
|
126
126
|
return unless opts[:rosters]
|
127
127
|
|
128
128
|
io.puts
|
129
|
-
io.puts(
|
129
|
+
io.puts(room.to_league)
|
130
130
|
end
|
131
131
|
|
132
|
-
def log(
|
132
|
+
def log(room)
|
133
133
|
return unless opts[:log]
|
134
134
|
|
135
135
|
io.puts
|
136
136
|
io.puts('Event Log')
|
137
137
|
|
138
|
-
puts
|
138
|
+
puts room.events
|
139
139
|
end
|
140
140
|
|
141
141
|
# rubocop:disable Metrics/AbcSize
|
142
|
-
def query(
|
142
|
+
def query(room)
|
143
143
|
top = opts[:top]
|
144
144
|
|
145
145
|
return if top <= 0
|
146
146
|
|
147
|
-
search = PlayerSearch.new(
|
147
|
+
search = PlayerSearch.new(room.undrafted_players)
|
148
148
|
position = opts[:query].to_s.empty? ? nil : Position.new(opts[:query])
|
149
149
|
players = search.query(position:).take(opts[:top])
|
150
150
|
|
@@ -167,20 +167,20 @@ module Basketball
|
|
167
167
|
end
|
168
168
|
|
169
169
|
# rubocop:disable Metrics/AbcSize
|
170
|
-
def execute(
|
170
|
+
def execute(room)
|
171
171
|
event_count = 0
|
172
172
|
|
173
173
|
io.puts
|
174
174
|
io.puts('New Events')
|
175
175
|
|
176
176
|
(opts[:picks] || []).each do |id|
|
177
|
-
break if
|
177
|
+
break if room.done?
|
178
178
|
|
179
|
-
player =
|
179
|
+
player = room.players.find { |p| p.id == id.to_s.upcase }
|
180
180
|
|
181
181
|
raise PlayerNotFound, "player not found by id: #{id}" unless player
|
182
182
|
|
183
|
-
event =
|
183
|
+
event = room.pick!(player)
|
184
184
|
|
185
185
|
io.puts(event)
|
186
186
|
|
@@ -188,21 +188,21 @@ module Basketball
|
|
188
188
|
end
|
189
189
|
|
190
190
|
opts[:skip].times do
|
191
|
-
event =
|
191
|
+
event = room.skip!
|
192
192
|
|
193
193
|
io.puts(event)
|
194
194
|
|
195
195
|
event_count += 1
|
196
196
|
end
|
197
197
|
|
198
|
-
|
198
|
+
room.sim!(opts[:simulate]) do |event|
|
199
199
|
io.puts(event)
|
200
200
|
|
201
201
|
event_count += 1
|
202
202
|
end
|
203
203
|
|
204
204
|
if opts[:simulate_all]
|
205
|
-
|
205
|
+
room.sim! do |event|
|
206
206
|
io.puts(event)
|
207
207
|
|
208
208
|
event_count += 1
|
@@ -215,10 +215,10 @@ module Basketball
|
|
215
215
|
end
|
216
216
|
# rubocop:enable Metrics/AbcSize
|
217
217
|
|
218
|
-
def write(
|
218
|
+
def write(room)
|
219
219
|
output = opts[:output].to_s.empty? ? opts[:input] : opts[:output]
|
220
220
|
|
221
|
-
contents = serializer.serialize(
|
221
|
+
contents = serializer.serialize(room)
|
222
222
|
out_dir = File.dirname(output)
|
223
223
|
|
224
224
|
FileUtils.mkdir_p(out_dir)
|
@@ -7,8 +7,8 @@ require_relative 'sim_event'
|
|
7
7
|
require_relative 'skip_event'
|
8
8
|
|
9
9
|
module Basketball
|
10
|
-
module
|
11
|
-
class
|
10
|
+
module Draft
|
11
|
+
class RoomSerializer
|
12
12
|
EVENT_CLASSES = {
|
13
13
|
'PickEvent' => PickEvent,
|
14
14
|
'SimEvent' => SimEvent,
|
@@ -17,11 +17,11 @@ module Basketball
|
|
17
17
|
|
18
18
|
private_constant :EVENT_CLASSES
|
19
19
|
|
20
|
-
def to_hash(
|
20
|
+
def to_hash(room)
|
21
21
|
{
|
22
|
-
'info' => serialize_info(
|
23
|
-
'
|
24
|
-
'league' => serialize_league(
|
22
|
+
'info' => serialize_info(room),
|
23
|
+
'room' => serialize_room(room),
|
24
|
+
'league' => serialize_league(room)
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
@@ -30,15 +30,15 @@ module Basketball
|
|
30
30
|
players = deserialize_players(json)
|
31
31
|
events = deserialize_events(json, players, front_offices)
|
32
32
|
|
33
|
-
|
33
|
+
room_opts = {
|
34
34
|
players:,
|
35
35
|
front_offices:,
|
36
36
|
events:
|
37
37
|
}
|
38
38
|
|
39
|
-
|
39
|
+
room_opts[:rounds] = json.dig('room', 'rounds') if json.dig('room', 'rounds')
|
40
40
|
|
41
|
-
|
41
|
+
Room.new(**room_opts)
|
42
42
|
end
|
43
43
|
|
44
44
|
def deserialize(string)
|
@@ -47,35 +47,35 @@ module Basketball
|
|
47
47
|
from_hash(json)
|
48
48
|
end
|
49
49
|
|
50
|
-
def serialize(
|
51
|
-
to_hash(
|
50
|
+
def serialize(room)
|
51
|
+
to_hash(room).to_json
|
52
52
|
end
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
-
def
|
56
|
+
def serialize_room(room)
|
57
57
|
{
|
58
|
-
'rounds' =>
|
59
|
-
'front_offices' => serialize_front_offices(
|
60
|
-
'players' => serialize_players(
|
61
|
-
'events' => serialize_events(
|
58
|
+
'rounds' => room.rounds,
|
59
|
+
'front_offices' => serialize_front_offices(room),
|
60
|
+
'players' => serialize_players(room),
|
61
|
+
'events' => serialize_events(room.events)
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
65
|
-
def serialize_info(
|
65
|
+
def serialize_info(room)
|
66
66
|
{
|
67
|
-
'total_picks' =>
|
68
|
-
'current_round' =>
|
69
|
-
'current_round_pick' =>
|
70
|
-
'current_front_office' =>
|
71
|
-
'current_pick' =>
|
72
|
-
'remaining_picks' =>
|
73
|
-
'done' =>
|
67
|
+
'total_picks' => room.total_picks,
|
68
|
+
'current_round' => room.current_round,
|
69
|
+
'current_round_pick' => room.current_round_pick,
|
70
|
+
'current_front_office' => room.current_front_office&.id,
|
71
|
+
'current_pick' => room.current_pick,
|
72
|
+
'remaining_picks' => room.remaining_picks,
|
73
|
+
'done' => room.done?
|
74
74
|
}
|
75
75
|
end
|
76
76
|
|
77
|
-
def serialize_league(
|
78
|
-
league =
|
77
|
+
def serialize_league(room)
|
78
|
+
league = room.to_league
|
79
79
|
|
80
80
|
rosters = league.rosters.to_h do |roster|
|
81
81
|
[
|
@@ -92,8 +92,8 @@ module Basketball
|
|
92
92
|
}
|
93
93
|
end
|
94
94
|
|
95
|
-
def serialize_front_offices(
|
96
|
-
|
95
|
+
def serialize_front_offices(room)
|
96
|
+
room.front_offices.to_h do |front_office|
|
97
97
|
[
|
98
98
|
front_office.id,
|
99
99
|
{
|
@@ -106,8 +106,8 @@ module Basketball
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
def serialize_players(
|
110
|
-
|
109
|
+
def serialize_players(room)
|
110
|
+
room.players.to_h do |player|
|
111
111
|
[
|
112
112
|
player.id,
|
113
113
|
{
|
@@ -135,7 +135,7 @@ module Basketball
|
|
135
135
|
end
|
136
136
|
|
137
137
|
def deserialize_front_offices(json)
|
138
|
-
(json.dig('
|
138
|
+
(json.dig('room', 'front_offices') || []).map do |id, front_office_hash|
|
139
139
|
prioritized_positions = (front_office_hash['prioritized_positions'] || []).map do |v|
|
140
140
|
Position.new(v)
|
141
141
|
end
|
@@ -153,7 +153,7 @@ module Basketball
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def deserialize_players(json)
|
156
|
-
(json.dig('
|
156
|
+
(json.dig('room', 'players') || []).map do |id, player_hash|
|
157
157
|
player_opts = {
|
158
158
|
id:,
|
159
159
|
first_name: player_hash['first_name'],
|
@@ -167,7 +167,7 @@ module Basketball
|
|
167
167
|
end
|
168
168
|
|
169
169
|
def deserialize_events(json, players, front_offices)
|
170
|
-
(json.dig('
|
170
|
+
(json.dig('room', 'events') || []).map do |event_hash|
|
171
171
|
event_opts = event_hash.slice('pick', 'round', 'round_pick').merge(
|
172
172
|
front_office: front_offices.find { |t| t.id == event_hash['front_office'] }
|
173
173
|
)
|
@@ -3,12 +3,12 @@
|
|
3
3
|
require_relative 'calendar'
|
4
4
|
|
5
5
|
module Basketball
|
6
|
-
module
|
6
|
+
module Season
|
7
7
|
# This is the service class responsible for actually picking out free dates ane pairing up teams to
|
8
8
|
# play each other. This is a reasonable naive first pass at some underlying match-making algorithms
|
9
9
|
# but could definitely use some help with the complexity/runtime/etc.
|
10
10
|
class Coordinator
|
11
|
-
MIN_PRESEASON_GAMES_PER_TEAM =
|
11
|
+
MIN_PRESEASON_GAMES_PER_TEAM = 3
|
12
12
|
MAX_PRESEASON_GAMES_PER_TEAM = 6
|
13
13
|
|
14
14
|
private_constant :MIN_PRESEASON_GAMES_PER_TEAM,
|
@@ -9,16 +9,16 @@ require_relative 'league_serializer'
|
|
9
9
|
require_relative 'team'
|
10
10
|
|
11
11
|
module Basketball
|
12
|
-
module
|
12
|
+
module Season
|
13
13
|
# Examples:
|
14
|
-
# exe/basketball-
|
15
|
-
# exe/basketball-
|
16
|
-
# exe/basketball-
|
17
|
-
# exe/basketball-
|
18
|
-
# exe/basketball-
|
19
|
-
# exe/basketball-
|
20
|
-
# exe/basketball-
|
21
|
-
class
|
14
|
+
# exe/basketball-season-scheduling -o tmp/league.json
|
15
|
+
# exe/basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json
|
16
|
+
# exe/basketball-season-scheduling -i tmp/league.json -o tmp/calendar.json -y 2005
|
17
|
+
# exe/basketball-season-scheduling -c tmp/calendar.json
|
18
|
+
# exe/basketball-season-scheduling -c tmp/calendar.json -t C0-D0-T0
|
19
|
+
# exe/basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03
|
20
|
+
# exe/basketball-season-scheduling -c tmp/calendar.json -d 2005-02-03 -t C0-D0-T0
|
21
|
+
class SchedulingCLI
|
22
22
|
attr_reader :opts,
|
23
23
|
:league_serializer,
|
24
24
|
:calendar_serializer,
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'season/scheduling_cli'
|
4
4
|
|
5
5
|
module Basketball
|
6
|
-
module
|
6
|
+
module Season
|
7
7
|
class ConferenceAlreadyRegisteredError < StandardError; end
|
8
8
|
class DivisionAlreadyRegisteredError < StandardError; end
|
9
9
|
class TeamAlreadyRegisteredError < StandardError; end
|
data/lib/basketball/version.rb
CHANGED
data/lib/basketball.rb
CHANGED
@@ -12,5 +12,5 @@ require_relative 'basketball/entity'
|
|
12
12
|
require_relative 'basketball/value_object'
|
13
13
|
|
14
14
|
# Submodules
|
15
|
-
require_relative 'basketball/
|
16
|
-
require_relative 'basketball/
|
15
|
+
require_relative 'basketball/draft'
|
16
|
+
require_relative 'basketball/season'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basketball
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -46,7 +46,7 @@ email:
|
|
46
46
|
- mattruggio@icloud.com
|
47
47
|
executables:
|
48
48
|
- basketball-draft
|
49
|
-
- basketball-
|
49
|
+
- basketball-season-scheduling
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
@@ -63,36 +63,36 @@ files:
|
|
63
63
|
- Rakefile
|
64
64
|
- basketball.gemspec
|
65
65
|
- exe/basketball-draft
|
66
|
-
- exe/basketball-
|
66
|
+
- exe/basketball-season-scheduling
|
67
67
|
- lib/basketball.rb
|
68
|
-
- lib/basketball/
|
69
|
-
- lib/basketball/
|
70
|
-
- lib/basketball/
|
71
|
-
- lib/basketball/
|
72
|
-
- lib/basketball/
|
73
|
-
- lib/basketball/
|
74
|
-
- lib/basketball/
|
75
|
-
- lib/basketball/
|
76
|
-
- lib/basketball/
|
77
|
-
- lib/basketball/
|
78
|
-
- lib/basketball/
|
79
|
-
- lib/basketball/
|
80
|
-
- lib/basketball/
|
81
|
-
- lib/basketball/
|
68
|
+
- lib/basketball/draft.rb
|
69
|
+
- lib/basketball/draft/cli.rb
|
70
|
+
- lib/basketball/draft/event.rb
|
71
|
+
- lib/basketball/draft/front_office.rb
|
72
|
+
- lib/basketball/draft/league.rb
|
73
|
+
- lib/basketball/draft/pick_event.rb
|
74
|
+
- lib/basketball/draft/player.rb
|
75
|
+
- lib/basketball/draft/player_search.rb
|
76
|
+
- lib/basketball/draft/position.rb
|
77
|
+
- lib/basketball/draft/room.rb
|
78
|
+
- lib/basketball/draft/room_serializer.rb
|
79
|
+
- lib/basketball/draft/roster.rb
|
80
|
+
- lib/basketball/draft/sim_event.rb
|
81
|
+
- lib/basketball/draft/skip_event.rb
|
82
82
|
- lib/basketball/entity.rb
|
83
|
-
- lib/basketball/
|
84
|
-
- lib/basketball/
|
85
|
-
- lib/basketball/
|
86
|
-
- lib/basketball/
|
87
|
-
- lib/basketball/
|
88
|
-
- lib/basketball/
|
89
|
-
- lib/basketball/
|
90
|
-
- lib/basketball/
|
91
|
-
- lib/basketball/
|
92
|
-
- lib/basketball/
|
93
|
-
- lib/basketball/
|
94
|
-
- lib/basketball/
|
95
|
-
- lib/basketball/
|
83
|
+
- lib/basketball/season.rb
|
84
|
+
- lib/basketball/season/calendar.rb
|
85
|
+
- lib/basketball/season/calendar_serializer.rb
|
86
|
+
- lib/basketball/season/conference.rb
|
87
|
+
- lib/basketball/season/coordinator.rb
|
88
|
+
- lib/basketball/season/division.rb
|
89
|
+
- lib/basketball/season/game.rb
|
90
|
+
- lib/basketball/season/league.rb
|
91
|
+
- lib/basketball/season/league_serializer.rb
|
92
|
+
- lib/basketball/season/preseason_game.rb
|
93
|
+
- lib/basketball/season/scheduling_cli.rb
|
94
|
+
- lib/basketball/season/season_game.rb
|
95
|
+
- lib/basketball/season/team.rb
|
96
96
|
- lib/basketball/value_object.rb
|
97
97
|
- lib/basketball/version.rb
|
98
98
|
homepage: https://github.com/mattruggio/basketball
|
@@ -123,5 +123,5 @@ requirements: []
|
|
123
123
|
rubygems_version: 3.4.6
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
|
-
summary: Basketball League Game
|
126
|
+
summary: Basketball League Game Room
|
127
127
|
test_files: []
|