killer_queen_scene_scoring 0.2.0 → 0.3.0
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.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d7f77f6799315d7f83d6983b58afdd4238e9fefec3b2b1373d44a544c609b0fa
|
|
4
|
+
data.tar.gz: 92a9376cabf9522a4f622ef254b12f235f7b9b4c6342c351c0d9ad0c6893b44a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97dbba12475dc82e9ff3e5232f06337535e42fe0f3cb9bcaa917c52a118ea3037c5d5d55fb2008f626f4e3f155968934818d1c12acb9e3cfdd49bc1e2ed04379
|
|
7
|
+
data.tar.gz: adc0b6dbb14ad7fb8f9ca6fc4534ba0f00f7c46a03b0d5bdb192304fa025e771ff0d3d445874f34c00912952d13159e027196150fa184745a0d52da8c6f63616
|
data/Gemfile.lock
CHANGED
|
@@ -23,7 +23,7 @@ unless id && api_key
|
|
|
23
23
|
return
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
t = KillerQueenSceneScoring::Tournament.new(id: id, api_key: api_key)
|
|
26
|
+
t = KillerQueenSceneScoring::Tournament.new(id: id, api_key: api_key, logger: true)
|
|
27
27
|
t.load
|
|
28
28
|
t.calculate_points
|
|
29
29
|
puts t.scene_scores.sort
|
|
@@ -8,9 +8,10 @@ class Bracket
|
|
|
8
8
|
# `id` can be the slug or the challonge ID of the bracket. If you pass a
|
|
9
9
|
# and the bracket is owned by an organization, it must be of the form
|
|
10
10
|
# "<org name>-<slug>". `api_key` is your Challonge API key.
|
|
11
|
-
def initialize(id:, api_key:)
|
|
11
|
+
def initialize(id:, api_key:, logger:)
|
|
12
12
|
@id = id
|
|
13
13
|
@api_key = api_key
|
|
14
|
+
@logger = logger
|
|
14
15
|
@loaded = false
|
|
15
16
|
@state == ""
|
|
16
17
|
end
|
|
@@ -31,7 +32,7 @@ class Bracket
|
|
|
31
32
|
rescue RestClient::NotFound
|
|
32
33
|
# Bail out if we got a 404 error. The bracket doesn't exist on
|
|
33
34
|
# Challonge right now, but it might be created in the future.
|
|
34
|
-
|
|
35
|
+
@logger&.warn "The bracket does not exist."
|
|
35
36
|
return false
|
|
36
37
|
end
|
|
37
38
|
|
|
@@ -48,7 +49,7 @@ class Bracket
|
|
|
48
49
|
# bracket, and set `next_bracket` in the wild card bracket to the ID
|
|
49
50
|
# of the finals bracket before the wild card bracket has finished.
|
|
50
51
|
if @challonge_bracket.started_at.nil?
|
|
51
|
-
|
|
52
|
+
@logger&.warn "The bracket has not been started yet."
|
|
52
53
|
return false
|
|
53
54
|
end
|
|
54
55
|
|
|
@@ -85,7 +86,7 @@ class Bracket
|
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
def raise_error(msg)
|
|
88
|
-
|
|
89
|
+
@logger&.error "ERROR: #{msg}"
|
|
89
90
|
raise msg
|
|
90
91
|
end
|
|
91
92
|
|
|
@@ -117,7 +118,7 @@ class Bracket
|
|
|
117
118
|
# instead start with "//". Default to HTTPS.
|
|
118
119
|
uri.scheme ||= "https"
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
@logger&.debug "Reading the config file from #{uri}"
|
|
121
122
|
|
|
122
123
|
# Read the config file from the attchment.
|
|
123
124
|
config = send_get_request(uri.to_s)
|
|
@@ -140,8 +141,8 @@ class Bracket
|
|
|
140
141
|
@teams << Team.new(team[:participant])
|
|
141
142
|
end
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
@logger&.info "#{@teams.size} teams are in the bracket: " +
|
|
145
|
+
@teams.sort_by(&:name).map { |t| %("#{t.name}") }.join(", ")
|
|
145
146
|
|
|
146
147
|
# Check that all of the teams in the bracket are also in the config file.
|
|
147
148
|
# We do case-insensitive name comparisons to allow for different
|
|
@@ -217,7 +218,7 @@ class Bracket
|
|
|
217
218
|
# isn't in the bracket. We allow this so that multiple brackets can
|
|
218
219
|
# use the same master team list during a tournament.
|
|
219
220
|
if team_obj.nil?
|
|
220
|
-
|
|
221
|
+
@logger&.info "Skipping a team that isn't in the bracket: #{team[:name]}"
|
|
221
222
|
next
|
|
222
223
|
end
|
|
223
224
|
|
|
@@ -225,8 +226,8 @@ class Bracket
|
|
|
225
226
|
@players[team_obj.id] << Player.new(player)
|
|
226
227
|
end
|
|
227
228
|
|
|
228
|
-
|
|
229
|
-
|
|
229
|
+
@logger&.info "#{team[:name]} (ID #{team_obj.id}) has: " +
|
|
230
|
+
@players[team_obj.id].map { |p| "#{p.name} (#{p.scene})" }.join(", ")
|
|
230
231
|
end
|
|
231
232
|
|
|
232
233
|
# Bail out if any team doesn't have exactly 5 players.
|
|
@@ -263,12 +264,12 @@ class Bracket
|
|
|
263
264
|
@teams.each do |team|
|
|
264
265
|
matches_with_team = @matches.select { |match| match.has_team?(team.id) }
|
|
265
266
|
|
|
266
|
-
|
|
267
|
+
@logger&.info "Team #{team.name} was in #{matches_with_team.size} matches"
|
|
267
268
|
|
|
268
269
|
points_earned = matches_with_team.max_by(&:points).points
|
|
269
270
|
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
@logger&.info "The largest point value of those matches is #{points_earned}" \
|
|
272
|
+
"#{" + #{base_point_value} base" if base_point_value > 0}"
|
|
272
273
|
|
|
273
274
|
team.points = points_earned + base_point_value
|
|
274
275
|
end
|
|
@@ -281,8 +282,8 @@ class Bracket
|
|
|
281
282
|
# the debug output will follow the teams' finishing order, which will be
|
|
282
283
|
# easier to read.
|
|
283
284
|
@teams.sort_by(&:points).reverse_each do |team|
|
|
284
|
-
|
|
285
|
-
|
|
285
|
+
@logger&.info "Awarding #{team.points} points to #{team.name}: " +
|
|
286
|
+
@players[team.id].map(&:to_s).join(", ")
|
|
286
287
|
|
|
287
288
|
@players[team.id].each do |player|
|
|
288
289
|
player.points = team.points
|
|
@@ -313,9 +314,9 @@ class Bracket
|
|
|
313
314
|
points_earned = final_rank_points[team.final_rank].sum /
|
|
314
315
|
final_rank_points[team.final_rank].size
|
|
315
316
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
@logger&.info "#{team.name} finished in position #{team.final_rank}" \
|
|
318
|
+
" and gets #{points_earned} points" \
|
|
319
|
+
"#{" + #{base_point_value} base" if base_point_value > 0}"
|
|
319
320
|
|
|
320
321
|
team.points = points_earned + base_point_value
|
|
321
322
|
end
|
|
@@ -9,13 +9,23 @@ class Tournament
|
|
|
9
9
|
# tournament. If you pass a slug, and the bracket is owned by an organization,
|
|
10
10
|
# it must be of the form "<org name>-<slug>".
|
|
11
11
|
# `api_key` is your Challonge API key.
|
|
12
|
-
|
|
12
|
+
# `logger` can be a `Logger` object, or `true` to log to standard output.
|
|
13
|
+
def initialize(id:, api_key:, logger: nil)
|
|
13
14
|
@brackets = []
|
|
14
15
|
@scene_scores = []
|
|
15
16
|
@loaded = false
|
|
16
17
|
@complete = false
|
|
17
18
|
@id = id
|
|
18
19
|
@api_key = api_key
|
|
20
|
+
|
|
21
|
+
@logger = case logger
|
|
22
|
+
when true
|
|
23
|
+
Logger.new(STDOUT, progname: "KillerQueenSceneScoring")
|
|
24
|
+
when Logger
|
|
25
|
+
logger
|
|
26
|
+
else
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
19
29
|
end
|
|
20
30
|
|
|
21
31
|
# Reads the Challonge bracket with the ID that was passed to the constructor,
|
|
@@ -29,10 +39,10 @@ class Tournament
|
|
|
29
39
|
all_brackets_loaded = true
|
|
30
40
|
|
|
31
41
|
while tournament_id
|
|
32
|
-
|
|
42
|
+
@logger&.debug "Reading the bracket \"#{tournament_id}\""
|
|
33
43
|
|
|
34
44
|
# Load the next bracket in the chain. Bail out if we can't load it.
|
|
35
|
-
bracket = Bracket.new(id: tournament_id, api_key: @api_key)
|
|
45
|
+
bracket = Bracket.new(id: tournament_id, api_key: @api_key, logger: @logger)
|
|
36
46
|
|
|
37
47
|
if !bracket.load
|
|
38
48
|
all_brackets_loaded = false
|
|
@@ -56,7 +66,7 @@ class Tournament
|
|
|
56
66
|
players.map(&:name).join(", ")
|
|
57
67
|
end
|
|
58
68
|
|
|
59
|
-
|
|
69
|
+
@logger&.info scene_list.join("\n")
|
|
60
70
|
# <- end debug logging
|
|
61
71
|
|
|
62
72
|
# Go to the next bracket in the chain.
|
|
@@ -70,7 +80,7 @@ class Tournament
|
|
|
70
80
|
|
|
71
81
|
if values.count(values[0]) != values.size
|
|
72
82
|
msg = "ERROR: All brackets must have the same \"max_players_to_count\"."
|
|
73
|
-
|
|
83
|
+
@logger&.error msg
|
|
74
84
|
raise msg
|
|
75
85
|
end
|
|
76
86
|
|
|
@@ -140,8 +150,8 @@ class Tournament
|
|
|
140
150
|
if scores.size > max_players_to_count
|
|
141
151
|
dropped = scores.slice!(max_players_to_count..-1)
|
|
142
152
|
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
@logger&.info "Dropping the #{dropped.size} lowest scores from #{scene}:" +
|
|
154
|
+
dropped.join(", ")
|
|
145
155
|
end
|
|
146
156
|
|
|
147
157
|
# Add up the scores for this scene.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: killer_queen_scene_scoring
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Dunn
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-03-
|
|
11
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|