sciolyff 0.7.2 → 0.8.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: 3fa5d842e42bc16f982593c2035ba2c753b91ce4bf39f330ece71a8dff70371c
4
- data.tar.gz: 2ceecc1b1830a25f71e77327ab3ea6859ac1299be30cb4ceaeca431faf286377
3
+ metadata.gz: c0b0585e73d7a00ceda5496078ca65998b8bea5fa1ece51bd76ac4c496074767
4
+ data.tar.gz: 3f9770165cfccc02e9d575b457ebf397e7f6a65d6861fbb9ee27959f9614445d
5
5
  SHA512:
6
- metadata.gz: 8852c727705a1de79952ee46dabf8092db727603b599111c4c95d5c092109c7e6c93f9e5926a318b87ec0dba605800483b7fbff327663b83a01679387dee28e7
7
- data.tar.gz: 30f12194806aeb5eff2080d674e1e925174324d031a9f4d34575facb48ccc3ab61f7d4287e8fc266902cd6d6a66c3455494f03731e913ff8f6322352d815277a
6
+ metadata.gz: ebacad7be6d0faa35892d239d48562b37d894919ea0b41bc40d4ebd668b306c3a2dda093605d18c0a924735366ab061597f941375f938c71313440beb1941bc5
7
+ data.tar.gz: f9ab9e0d567ef8cbf9d5740e7205f49324715ce0db3633716a689e61170a9ad2a576ac1ecd78029f1b8864b9255690ee36b793db2b0ef8b2d3c3bbd09eba16f0
@@ -6,7 +6,7 @@ require 'yaml'
6
6
  require 'sciolyff'
7
7
 
8
8
  opts = Optimist.options do
9
- version 'sciolyff 0.7.2'
9
+ version 'sciolyff 0.8.0'
10
10
  banner <<~STRING
11
11
  Checks if a given file is in the Scioly File Format
12
12
 
@@ -40,10 +40,14 @@ module SciolyFF
40
40
  @placings_by_team[team]
41
41
  end
42
42
 
43
- def competing_teams
44
- return placings.map(&:team) if trial?
43
+ def maximum_place
44
+ return placings.size if trial?
45
45
 
46
- placings.map(&:team).reject(&:exhibition?)
46
+ tournament.maximum_place
47
+ end
48
+
49
+ def maximum_points
50
+ maximum_place + 2
47
51
  end
48
52
  end
49
53
  end
@@ -5,7 +5,6 @@ module SciolyFF
5
5
  class Interpreter::Model
6
6
  def initialize(rep, index)
7
7
  @rep = rep[pluralize_for_key(self.class)][index]
8
- @cache = {}
9
8
  end
10
9
 
11
10
  def link_to_other_models(interpreter)
@@ -50,23 +50,19 @@ module SciolyFF
50
50
  end
51
51
 
52
52
  def points
53
- return 0 unless considered_for_team_points?
54
-
55
- isolated_points
53
+ @points ||= if !considered_for_team_points? then 0
54
+ else isolated_points
55
+ end
56
56
  end
57
57
 
58
58
  def isolated_points
59
- return @cache[:points] if @cache[:points]
60
-
61
- n = event.competing_teams.count
59
+ n = event.maximum_place
62
60
 
63
- @cache[:points] =
64
- if disqualified? then n + 2
65
- elsif did_not_participate? then n + 1
66
- elsif participation_only? then n
67
- elsif unknown? then n - 1
68
- else calculate_points
69
- end
61
+ if disqualified? then n + 2
62
+ elsif did_not_participate? then n + 1
63
+ elsif participation_only? || unknown? then n
64
+ else [calculate_points, n].min
65
+ end
70
66
  end
71
67
 
72
68
  def considered_for_team_points?
@@ -78,12 +74,25 @@ module SciolyFF
78
74
  !(event.trial? || event.trialed? || exempt?)
79
75
  end
80
76
 
77
+ def points_affected_by_exhibition?
78
+ considered_for_team_points? && place && !exhibition_placings_behind.zero?
79
+ end
80
+
81
+ def points_limited_by_maximum_place?
82
+ tournament.custom_maximum_place? &&
83
+ (unknown? || (place && calculate_points > event.maximum_place))
84
+ end
85
+
81
86
  private
82
87
 
83
88
  def calculate_points
84
89
  return place if event.trial?
85
90
 
86
- place - event.placings.count do |p|
91
+ place - exhibition_placings_behind
92
+ end
93
+
94
+ def exhibition_placings_behind
95
+ @exhibition_placings_behind ||= event.placings.count do |p|
87
96
  (p.exempt? || p.team.exhibition?) &&
88
97
  p.place &&
89
98
  p.place < place
@@ -59,9 +59,7 @@ module SciolyFF
59
59
  end
60
60
 
61
61
  def points
62
- return @cache[:points] if @cache[:points]
63
-
64
- @cache[:points] = placings.sum(&:points) + penalties.sum(&:points)
62
+ @points ||= placings.sum(&:points) + penalties.sum(&:points)
65
63
  end
66
64
 
67
65
  def worst_placings_to_be_dropped
@@ -79,16 +77,16 @@ module SciolyFF
79
77
  end
80
78
 
81
79
  def medal_counts
82
- (1..@tournament.max_points_per_event).map do |medal_points|
80
+ (1..@tournament.events.first.maximum_points).map do |medal_points|
83
81
  placings.select(&:considered_for_team_points?)
84
82
  .count { |p| p.points == medal_points }
85
83
  end
86
84
  end
87
85
 
88
86
  def trial_event_medal_counts
89
- (1..@tournament.max_points_per_event(trial: true)).map do |medal_points|
87
+ (1..@tournament.events.last.maximum_points).map do |medal_points|
90
88
  placings.select { |p| p.event.trial? }
91
- .count { |p| p.points == medal_points }
89
+ .count { |p| p.isolated_points == medal_points }
92
90
  end
93
91
  end
94
92
  end
@@ -68,10 +68,14 @@ module SciolyFF
68
68
  exempt_placings? ? @rep[:'exempt placings'] : 0
69
69
  end
70
70
 
71
- def max_points_per_event(trial: false)
72
- return @teams.size + 2 if trial
71
+ def custom_maximum_place?
72
+ maximum_place != @teams.count { |t| !t.exhibition? }
73
+ end
74
+
75
+ def maximum_place
76
+ return @rep[:'maximum place'] if @rep[:'maximum place']
73
77
 
74
- @teams.count { |t| !t.exhibition? } + 2
78
+ @teams.count { |t| !t.exhibition? }
75
79
  end
76
80
  end
77
81
  end
@@ -107,6 +107,8 @@ module SciolyFF
107
107
  end
108
108
 
109
109
  def test_each_placing_has_valid_unknown
110
+ skip if SciolyFF.rep[:Tournament]&.key? :'maximum place'
111
+
110
112
  @placings.select { |p| p.instance_of? Hash }.each do |placing|
111
113
  next unless placing.key? :unknown
112
114
 
@@ -24,6 +24,7 @@ module SciolyFF
24
24
  def test_does_not_have_extra_info
25
25
  info = Set.new %i[name location level division state year date]
26
26
  info << :'short name' << :'worst placings dropped' << :'exempt placings'
27
+ info << :'maximum place'
27
28
  assert Set.new(@tournament.keys).subset? info
28
29
  end
29
30
 
@@ -84,5 +85,10 @@ module SciolyFF
84
85
  skip unless @tournament.key? :'exempt placings'
85
86
  assert_instance_of Integer, @tournament[:'exempt placings']
86
87
  end
88
+
89
+ def test_has_valid_maximum_place
90
+ skip unless @tournament.key? :'maximum place'
91
+ assert_instance_of Integer, @tournament[:'maximum place']
92
+ end
87
93
  end
88
94
  end
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.7.2
4
+ version: 0.8.0
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-10-17 00:00:00.000000000 Z
11
+ date: 2019-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest