sciolyff 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sciolyff +1 -1
  3. data/lib/sciolyff.rb +20 -7
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e74a3f87dca96e2c00acbccb2f6c324ff669bc348af5e029b0b93a1d2fb50eb
4
- data.tar.gz: a871c9a14be7c08449d5a94f71fc8d0d759a89d6b3e85c866dc86bebcf717735
3
+ metadata.gz: b5ade4d7bbd00e33e30bfeafffb0b30532e8210280ca6eae2b7720010fff532f
4
+ data.tar.gz: 6955635e1bb01bb523c21633e4610583b4cabfc0349c9d1e9475ad9b5fae7307
5
5
  SHA512:
6
- metadata.gz: d45d2a1a73ad360be109d3bb5c6a3b778416de2a7833c54b9c4dc4e1b55ca4a299ed82b3d17817a3f5b906d1d745e574e39feac7ce8901a41558d8098fb3fbae
7
- data.tar.gz: 54835c59ff8927dbdd9232edd185fc904563e4e6a4b19b6e2bdae8f0f4cb10845dcc3eb905a5f826113e4b7c2958745f62b276c711d3b138b87c4e3764cbd2a4
6
+ metadata.gz: b308389be5811e1fa13c93d08111d639f3c50dc64c1aed146e103aa048a02512c69558220b6e4e5f68bf10ef18c02a5995cde3715ade6932228cf24a05258c4a
7
+ data.tar.gz: f38152c0da8db0f4bcd7e0bd19fd473e11a92b6ff6cc09a4a6f21cfbfca1b7ee141e66fc568e9c6c517f0446702cad459eddbfd40cb0e0edc2f9165a3f28a4d9
data/bin/sciolyff CHANGED
@@ -6,7 +6,7 @@ require 'yaml'
6
6
  require 'sciolyff'
7
7
 
8
8
  opts = Optimist.options do
9
- version 'sciolyff 0.4.0'
9
+ version 'sciolyff 0.4.1'
10
10
  banner <<~STRING
11
11
  Checks if a given file is in the Scioly File Format
12
12
 
data/lib/sciolyff.rb CHANGED
@@ -54,6 +54,9 @@ module SciolyFF
54
54
 
55
55
  def initialize(rep)
56
56
  @rep = rep
57
+ @exhibition_teams_count = rep[:Teams].count { |t| t[:exhibition] }
58
+ @team_points_cache = {}
59
+
57
60
  @tournament = rep[:Tournament]
58
61
  @events_by_name = index_array(rep[:Events], [:name])
59
62
  @teams_by_number = index_array(rep[:Teams], [:number])
@@ -80,12 +83,9 @@ module SciolyFF
80
83
  end
81
84
 
82
85
  def team_points(team_number)
83
- @placings_by_team[team_number]
84
- .values
85
- .reject { |p| @events_by_name[p[:event]][:trial] }
86
- .reject { |p| @events_by_name[p[:event]][:trialed] }
87
- .sum { |p| event_points(team_number, p[:event]) } \
88
- + team_points_from_penalties(team_number)
86
+ return @team_points_cache[team_number] if @team_points_cache[team_number]
87
+
88
+ @team_points_cache[team_number] = calculate_team_points(team_number)
89
89
  end
90
90
 
91
91
  def team_points_from_penalties(team_number)
@@ -134,7 +134,7 @@ module SciolyFF
134
134
  end
135
135
 
136
136
  def calculate_event_points(placing)
137
- return placing[:place] if @events_by_name[placing[:event]][:trial]
137
+ return placing[:place] if simple_placing?(placing)
138
138
 
139
139
  # Points is place minus number of exhibition teams with a better place
140
140
  placing[:place] -
@@ -144,6 +144,19 @@ module SciolyFF
144
144
  .count { |p| p[:place] < placing[:place] }
145
145
  end
146
146
 
147
+ def calculate_team_points(team_number)
148
+ @placings_by_team[team_number]
149
+ .values
150
+ .reject { |p| @events_by_name[p[:event]][:trial] }
151
+ .reject { |p| @events_by_name[p[:event]][:trialed] }
152
+ .sum { |p| event_points(team_number, p[:event]) } \
153
+ + team_points_from_penalties(team_number)
154
+ end
155
+
156
+ def simple_placing?(placing)
157
+ @exhibition_teams_count.zero? || @events_by_name[placing[:event]][:trial]
158
+ end
159
+
147
160
  def break_tie(team_number_a, team_number_b)
148
161
  medal_counts(team_number_a)
149
162
  .zip(medal_counts(team_number_b))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sciolyff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Em Zhan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-11 00:00:00.000000000 Z
11
+ date: 2019-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.0.3
91
+ rubygems_version: 3.0.4
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: A file format for Science Olympiad tournament results.