sportdb 1.9.16 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +2 -19
  3. data/Manifest.txt +1 -137
  4. data/README.md +2 -21
  5. data/Rakefile +14 -25
  6. data/lib/sportdb.rb +9 -260
  7. data/lib/sportdb/cli/main.rb +5 -14
  8. data/lib/sportdb/cli/opts.rb +2 -0
  9. data/lib/sportdb/cli/version.rb +26 -0
  10. metadata +10 -278
  11. data/.gemtest +0 -0
  12. data/config/fixtures/de.yml +0 -46
  13. data/config/fixtures/en.yml +0 -54
  14. data/config/fixtures/es.yml +0 -48
  15. data/config/fixtures/fr.yml +0 -53
  16. data/config/fixtures/it.yml +0 -55
  17. data/config/fixtures/pt.yml +0 -46
  18. data/config/fixtures/ro.yml +0 -55
  19. data/data/seasons.txt +0 -74
  20. data/data/setups/all.txt +0 -5
  21. data/lib/sportdb/calc.rb +0 -279
  22. data/lib/sportdb/deleter.rb +0 -52
  23. data/lib/sportdb/finders/date.rb +0 -374
  24. data/lib/sportdb/finders/goals.rb +0 -260
  25. data/lib/sportdb/finders/scores.rb +0 -122
  26. data/lib/sportdb/lang.rb +0 -216
  27. data/lib/sportdb/matcher.rb +0 -31
  28. data/lib/sportdb/models/assoc.rb +0 -106
  29. data/lib/sportdb/models/assoc_assoc.rb +0 -15
  30. data/lib/sportdb/models/badge.rb +0 -14
  31. data/lib/sportdb/models/event.rb +0 -65
  32. data/lib/sportdb/models/event_ground.rb +0 -15
  33. data/lib/sportdb/models/event_team.rb +0 -16
  34. data/lib/sportdb/models/forward.rb +0 -55
  35. data/lib/sportdb/models/game.rb +0 -244
  36. data/lib/sportdb/models/goal.rb +0 -15
  37. data/lib/sportdb/models/ground.rb +0 -100
  38. data/lib/sportdb/models/group.rb +0 -23
  39. data/lib/sportdb/models/group_team.rb +0 -14
  40. data/lib/sportdb/models/league.rb +0 -83
  41. data/lib/sportdb/models/person.rb +0 -21
  42. data/lib/sportdb/models/roster.rb +0 -18
  43. data/lib/sportdb/models/round.rb +0 -22
  44. data/lib/sportdb/models/season.rb +0 -14
  45. data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
  46. data/lib/sportdb/models/stats/alltime_standing_entry.rb +0 -23
  47. data/lib/sportdb/models/stats/event_standing.rb +0 -55
  48. data/lib/sportdb/models/stats/event_standing_entry.rb +0 -21
  49. data/lib/sportdb/models/stats/group_standing.rb +0 -50
  50. data/lib/sportdb/models/stats/group_standing_entry.rb +0 -22
  51. data/lib/sportdb/models/team.rb +0 -119
  52. data/lib/sportdb/models/team_comp.rb +0 -64
  53. data/lib/sportdb/models/utils.rb +0 -78
  54. data/lib/sportdb/models/world/city.rb +0 -21
  55. data/lib/sportdb/models/world/continent.rb +0 -20
  56. data/lib/sportdb/models/world/country.rb +0 -19
  57. data/lib/sportdb/models/world/region.rb +0 -19
  58. data/lib/sportdb/patterns.rb +0 -38
  59. data/lib/sportdb/reader.rb +0 -130
  60. data/lib/sportdb/reader_file.rb +0 -123
  61. data/lib/sportdb/reader_zip.rb +0 -165
  62. data/lib/sportdb/readers/assoc.rb +0 -54
  63. data/lib/sportdb/readers/event.rb +0 -200
  64. data/lib/sportdb/readers/game.rb +0 -877
  65. data/lib/sportdb/readers/ground.rb +0 -53
  66. data/lib/sportdb/readers/league.rb +0 -54
  67. data/lib/sportdb/readers/season.rb +0 -83
  68. data/lib/sportdb/readers/squad_club.rb +0 -201
  69. data/lib/sportdb/readers/squad_national_team.rb +0 -173
  70. data/lib/sportdb/readers/team.rb +0 -53
  71. data/lib/sportdb/schema.rb +0 -373
  72. data/lib/sportdb/standings.rb +0 -178
  73. data/lib/sportdb/stats.rb +0 -27
  74. data/lib/sportdb/utils.rb +0 -89
  75. data/lib/sportdb/utils_date.rb +0 -26
  76. data/lib/sportdb/utils_goals.rb +0 -20
  77. data/lib/sportdb/utils_group.rb +0 -63
  78. data/lib/sportdb/utils_map.rb +0 -44
  79. data/lib/sportdb/utils_round.rb +0 -165
  80. data/lib/sportdb/utils_scores.rb +0 -17
  81. data/lib/sportdb/utils_teams.rb +0 -43
  82. data/lib/sportdb/version.rb +0 -22
  83. data/test/data/at-austria/2013_14/bl.txt +0 -227
  84. data/test/data/at-austria/2013_14/bl.yml +0 -30
  85. data/test/data/at-austria/2013_14/bl_ii.txt +0 -154
  86. data/test/data/at-austria/2013_14/el.txt +0 -4
  87. data/test/data/at-austria/2013_14/el.yml +0 -25
  88. data/test/data/at-austria/2013_14/squads/austria.txt +0 -40
  89. data/test/data/at-austria/2013_14/squads/salzburg.txt +0 -35
  90. data/test/data/at-austria/leagues.txt +0 -11
  91. data/test/data/at-austria/teams.txt +0 -75
  92. data/test/data/at-austria/teams_2.txt +0 -34
  93. data/test/data/national-teams/assocs.txt +0 -231
  94. data/test/data/national-teams/europe/assocs.txt +0 -13
  95. data/test/data/national-teams/europe/teams.txt +0 -13
  96. data/test/data/national-teams/north-america/assocs.txt +0 -10
  97. data/test/data/national-teams/north-america/teams.txt +0 -7
  98. data/test/data/national-teams/teams.txt +0 -19
  99. data/test/data/players/europe/at-austria/players.txt +0 -45
  100. data/test/data/players/europe/de-deutschland/players.txt +0 -41
  101. data/test/data/players/south-america/br-brazil/players.txt +0 -51
  102. data/test/data/world-cup/1930/cup.txt +0 -71
  103. data/test/data/world-cup/1930/cup.yml +0 -23
  104. data/test/data/world-cup/1930/cup_goals.txt +0 -47
  105. data/test/data/world-cup/1930/cup_goals.yml +0 -23
  106. data/test/data/world-cup/1954/cup.txt +0 -90
  107. data/test/data/world-cup/1954/cup.yml +0 -30
  108. data/test/data/world-cup/1962/cup.txt +0 -86
  109. data/test/data/world-cup/1962/cup.yml +0 -32
  110. data/test/data/world-cup/1974/cup.yml +0 -35
  111. data/test/data/world-cup/1974/cup_finals.txt +0 -14
  112. data/test/data/world-cup/1974/cup_i.txt +0 -55
  113. data/test/data/world-cup/1974/cup_ii.txt +0 -34
  114. data/test/data/world-cup/2014/cup.txt +0 -5
  115. data/test/data/world-cup/2014/cup.yml +0 -54
  116. data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
  117. data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
  118. data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
  119. data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
  120. data/test/data/world-cup/leagues.txt +0 -5
  121. data/test/data/world-cup/seasons_1930.txt +0 -4
  122. data/test/data/world-cup/seasons_1954.txt +0 -4
  123. data/test/data/world-cup/seasons_1962.txt +0 -4
  124. data/test/data/world-cup/seasons_1974.txt +0 -5
  125. data/test/data/world-cup/teams_1930.txt +0 -26
  126. data/test/data/world-cup/teams_1954.txt +0 -30
  127. data/test/data/world-cup/teams_1962.txt +0 -29
  128. data/test/data/world-cup/teams_1974.txt +0 -29
  129. data/test/helper.rb +0 -120
  130. data/test/test_assoc_reader.rb +0 -201
  131. data/test/test_changes.rb +0 -74
  132. data/test/test_cursor.rb +0 -50
  133. data/test/test_date.rb +0 -100
  134. data/test/test_goals.rb +0 -109
  135. data/test/test_lang.rb +0 -130
  136. data/test/test_load.rb +0 -61
  137. data/test/test_reader.rb +0 -88
  138. data/test/test_reader_from_string.rb +0 -65
  139. data/test/test_round_auto.rb +0 -370
  140. data/test/test_round_def.rb +0 -109
  141. data/test/test_round_header.rb +0 -183
  142. data/test/test_scores.rb +0 -70
  143. data/test/test_squad_club_reader.rb +0 -76
  144. data/test/test_squad_national_team_reader.rb +0 -116
  145. data/test/test_standings.rb +0 -279
  146. data/test/test_standings_ii.rb +0 -46
  147. data/test/test_utils.rb +0 -124
  148. data/test/test_winner.rb +0 -95
@@ -1,15 +0,0 @@
1
- module SportDb
2
- module Model
3
-
4
-
5
- class AssocAssoc < ActiveRecord::Base
6
- self.table_name = 'assocs_assocs'
7
-
8
- belongs_to :assoc1, class_name: 'Assoc', foreign_key: 'assoc1_id' # parent assoc
9
- belongs_to :assoc2, class_name: 'Assoc', foreign_key: 'assoc2_id' # child assoc is_member_of parent assoc
10
-
11
- end # class AssocAssoc
12
-
13
-
14
- end # module Model
15
- end # module SportDb
@@ -1,14 +0,0 @@
1
- module SportDb
2
- module Model
3
-
4
- class Badge < ActiveRecord::Base
5
-
6
- belongs_to :team
7
- belongs_to :league
8
- belongs_to :season
9
-
10
- end # class Badge
11
-
12
-
13
- end # module Model
14
- end # module SportDb
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Model
5
-
6
- class Event < ActiveRecord::Base
7
-
8
- belongs_to :league
9
- belongs_to :season
10
-
11
- if ActiveRecord::VERSION::MAJOR == 3
12
- has_many :rounds, order: 'pos' # all (fix and flex) rounds
13
- has_many :groups, order: 'pos'
14
- else
15
- has_many :rounds, -> { order('pos') } # all (fix and flex) rounds
16
- has_many :groups, -> { order('pos') }
17
- end
18
-
19
- has_many :games, :through => :rounds
20
-
21
- has_many :event_teams, class_name: 'EventTeam'
22
- has_many :teams, :through => :event_teams
23
-
24
- has_many :event_grounds, class_name: 'EventGround'
25
- has_many :grounds, :through => :event_grounds
26
-
27
-
28
- before_save :on_before_save
29
-
30
-
31
- def add_teams_from_ary!( team_keys )
32
- ## move to depreciated? used in event reader? why? why not?
33
- team_keys.each do |team_key|
34
- team = Team.find_by_key!( team_key )
35
- self.teams << team
36
- end
37
- end
38
-
39
- def on_before_save
40
- # event key is composite of league + season (e.g. at.2012/13) etc.
41
- self.key = "#{league.key}.#{season.key}"
42
- end
43
-
44
- def title
45
- "#{league.title} #{season.title}"
46
- end
47
-
48
-
49
- #####################
50
- ## convenience helper for text parser/reader
51
-
52
- ###
53
- ## fix: use/add to_teams_table( rec ) for reuse
54
- #
55
- ## @known_teams = @event.known_teams_table
56
-
57
-
58
- def known_teams_table
59
- @known_teams_table ||= TextUtils.build_title_table_for( teams )
60
- end # method known_teams_table
61
-
62
- end # class Event
63
-
64
- end # module Model
65
- end # module SportDb
@@ -1,15 +0,0 @@
1
-
2
- module SportDb
3
- module Model
4
-
5
-
6
- class EventGround < ActiveRecord::Base
7
- self.table_name = 'events_grounds'
8
-
9
- belongs_to :event
10
- belongs_to :ground
11
- end # class EventGround
12
-
13
-
14
- end # module Model
15
- end # module SportDb
@@ -1,16 +0,0 @@
1
-
2
- module SportDb
3
- module Model
4
-
5
-
6
- class EventTeam < ActiveRecord::Base
7
- self.table_name = 'events_teams'
8
-
9
- belongs_to :event
10
- belongs_to :team
11
- end # class EventTeam
12
-
13
-
14
- end # module Model
15
- end # module SportDb
16
-
@@ -1,55 +0,0 @@
1
-
2
- ### forward references
3
- ## require first to resolve circular references
4
-
5
- module SportDb
6
- module Model
7
-
8
- Prop = ConfDb::Model::Prop
9
-
10
- ## todo: why? why not use include WorldDb::Models here???
11
- Continent = WorldDb::Model::Continent
12
- Country = WorldDb::Model::Country
13
- Region = WorldDb::Model::Region
14
- City = WorldDb::Model::City
15
-
16
- Person = PersonDb::Model::Person
17
-
18
- ## nb: for now only team and league use worlddb tables
19
- # e.g. with belongs_to assoc (country,region)
20
-
21
- class Assoc < ActiveRecord::Base ; end
22
- class Team < ActiveRecord::Base ; end
23
- class League < ActiveRecord::Base ; end
24
- class Ground < ActiveRecord::Base ; end
25
- class Goal < ActiveRecord::Base ; end
26
-
27
- end
28
-
29
- ## add backwards compatible n convenience namespace
30
- Models = Model
31
- end # module SportDb
32
-
33
-
34
- module WorldDb
35
- module Model
36
-
37
- # add alias? why? why not? # is there a better way?
38
- # - just include SportDb::Models - why? why not?
39
- # - just include once in loader??
40
- Assoc = SportDb::Model::Assoc
41
- Team = SportDb::Model::Team
42
- League = SportDb::Model::League
43
- Ground = SportDb::Model::Ground
44
-
45
- end
46
- end
47
-
48
-
49
- module PersonDb
50
- module Model
51
- Goal = SportDb::Model::Goal
52
- end
53
- end
54
-
55
-
@@ -1,244 +0,0 @@
1
-
2
- module SportDb
3
- module Model
4
-
5
-
6
- class Game < ActiveRecord::Base
7
-
8
- belongs_to :team1, class_name: 'Team', foreign_key: 'team1_id'
9
- belongs_to :team2, class_name: 'Team', foreign_key: 'team2_id'
10
-
11
- belongs_to :round
12
- belongs_to :group # group is optional
13
-
14
- belongs_to :ground # ground is optional
15
- belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id' # city is optioanl (remove?? redundant?? use ground ??)
16
-
17
- has_many :goals, :dependent => :delete_all
18
-
19
-
20
- before_save :calc_winner
21
-
22
-
23
- def team1_name() team1.name; end
24
- def team2_name() team2.name; end
25
-
26
-
27
- def toto12x() toto1x2; end # alias for toto12x - todo/fix: use ruby alias helper
28
- def toto1x2
29
- ## note: will return string e.g. 1-X-2 (winner will return int e.g. 1-0-2)
30
-
31
- ## fix: use switch/when expr/stmt instead of ifs
32
- value = winner90 # 1 0 2 1 => team 1 0 => draw 2 => team
33
- if value == 0
34
- 'X'
35
- elsif value == 1
36
- '1'
37
- elsif value == 2
38
- '2'
39
- elsif value == -1
40
- nil # ??? - unknown -- include --??? why? why not??
41
- else
42
- nil
43
- end
44
- end
45
-
46
-
47
- def winner1?() winner == 1; end
48
- def winner2?() winner == 2; end
49
- def draw? () winner == 0; end # use different name; use an alias (any better names more speaking???)
50
-
51
-
52
-
53
- ## winner after extra time (will ignore possible penalty shootout; used for alltime standings in world cup calc, for example)
54
- ## - also add winnerp nil,1,2 => nil -> no penalty shoutout (or no scores) -- needed for what?
55
- def winneret
56
- ## check for extra time
57
- if score1et.present? && score2et.present?
58
- if score1et > score2et
59
- 1
60
- elsif score1et < score2et
61
- 2
62
- else # assume score1et == score2et - draw
63
- 0
64
- end
65
- else
66
- nil # no extra time; note: return nil use winneret || winner90 to get result for both extra time or if not present regular time
67
- end
68
- end
69
-
70
-
71
- def calc_winner
72
- if score1.nil? || score2.nil?
73
- self.winner90 = nil
74
- self.winner = nil
75
- else
76
- if score1 > score2
77
- self.winner90 = 1
78
- elsif score1 < score2
79
- self.winner90 = 2
80
- else # assume score1 == score2 - draw
81
- self.winner90 = 0
82
- end
83
-
84
- ## todo/fix:
85
- # check for next-game/pre-game !!!
86
- # use 1st leg and 2nd leg - use for winner too
87
- # or add new winner_total or winner_aggregated method ???
88
-
89
- ## check for penalty - note: some games might only have penalty and no extra time (e.g. copa liberatadores)
90
- if score1p.present? && score2p.present?
91
- if score1p > score2p
92
- self.winner = 1
93
- elsif score1p < score2p
94
- self.winner = 2
95
- else
96
- # issue warning! - should not happen; penalty goes on until winner found!
97
- puts "*** warn: should not happen; penalty goes on until winner found"
98
- end
99
- ## check for extra time
100
- elsif score1et.present? && score2et.present?
101
- if score1et > score2et
102
- self.winner = 1
103
- elsif score1et < score2et
104
- self.winner = 2
105
- else # assume score1et == score2et - draw
106
- self.winner = 0
107
- end
108
- else
109
- # assume no penalty and no extra time; same as 90min result
110
- self.winner = self.winner90
111
- end
112
- end
113
- end
114
-
115
-
116
- ### getter/setters for deprecated attribs (score3,4,5,6) n national
117
-
118
- def score1ot() score1et end
119
- def score2ot() score2et end
120
-
121
- def score1ot=(value) self.score1et = value end
122
- def score2ot=(value) self.score2et = value end
123
-
124
-
125
- # game over?
126
- def over?() play_at <= Time.now; end
127
-
128
- ## fix/todo: already added by ar magic ??? remove code
129
- def knockout?() knockout == true; end
130
- def complete?() score1.present? && score2.present?; end
131
-
132
-
133
- ############# convenience helpers for styling
134
- ##
135
-
136
- def team1_style_class
137
- buf = ''
138
- ## NB: remove if calc?
139
-
140
- ### fix: loser
141
- ## - add method for checking winner/loser on ko pairs using (1st leg/2nd leg totals) ??
142
- ## use new winner_total method ??
143
-
144
- if complete?
145
- if winner1?
146
- buf << 'game-team-winner '
147
- elsif winner2?
148
- buf << 'game-team-loser '
149
- else # assume draw
150
- buf << 'game-team-draw '
151
- end
152
- end
153
-
154
- buf << 'game-knockout ' if knockout?
155
- buf
156
- end
157
-
158
- def team2_style_class
159
- buf = ''
160
- ## NB: remove if calc?
161
-
162
- ### fix: loser
163
- ## - add method for checking winner/loser on ko pairs using (1st leg/2nd leg totals) ??
164
- ## use new winner_total method ??
165
-
166
- if complete?
167
- if winner1?
168
- buf << 'game-team-loser '
169
- elsif winner2?
170
- buf << 'game-team-winner '
171
- else # assume draw
172
- buf << 'game-team-draw '
173
- end
174
- end
175
-
176
- buf << 'game-knockout ' if knockout?
177
- buf
178
- end
179
-
180
-
181
- def play_at_str( format = nil )
182
- ## e.g. use like
183
- # play_at_str or
184
- # play_at_str( :db ) etc.
185
- if format == :db
186
- play_at.strftime( '%Y-%m-%d %H:%M %z' ) # NB: removed seconds (:%S)
187
- else
188
- play_at.strftime( "%a. %d. %b. / %H:%M" )
189
- end
190
- end
191
-
192
-
193
- def score_str
194
- ## return ' - ' if score1.nil? && score2.nil?
195
-
196
- # note: make after extra time optional;
197
- # e.g. copa liberatadores only has regular time plus penalty, for example
198
-
199
- buf = ""
200
-
201
- buf << "#{score1_str} : #{score2_str}"
202
- buf << " / #{score1et_str} : #{score2et_str} n.V." if score1et.present? || score2et.present?
203
- buf << " / #{score1p_str} : #{score2p_str} i.E." if score1p.present? || score2p.present?
204
-
205
- buf
206
- end
207
-
208
- def score1_str() score1.nil? ? '-' : score1.to_s; end
209
- def score2_str() score2.nil? ? '-' : score2.to_s; end
210
-
211
- def score1et_str() score1et.nil? ? '-' : score1et.to_s; end
212
- def score2et_str() score2et.nil? ? '-' : score2et.to_s; end
213
-
214
- def score1p_str() score1p.nil? ? '-' : score1p.to_s; end
215
- def score2p_str() score2p.nil? ? '-' : score2p.to_s; end
216
-
217
-
218
-
219
- ## todo/fix: find a better name?
220
- ## todo: move to utils for reuse?
221
-
222
- def check_for_changes( new_attributes )
223
- changes_counter = 0
224
- new_attributes.each do |key,new_value|
225
- old_value = attributes[ key.to_s ]
226
- ## todo/fix: also check for class/type matching ????
227
- if new_value == old_value
228
- # do nothing
229
- else
230
- changes_counter +=1
231
- puts "change #{changes_counter} for #{key} old:>#{old_value}< : #{old_value.class.name} new:>#{new_value}< : #{new_value.class.name}"
232
- end
233
- end
234
-
235
- # no changes found for counter==0;
236
- # -- otherwise x changes found; return true
237
- changes_counter == 0 ? false : true
238
- end
239
-
240
- end # class Game
241
-
242
-
243
- end # module Model
244
- end # module SportDb
@@ -1,15 +0,0 @@
1
-
2
- module SportDb
3
- module Model
4
-
5
-
6
- class Goal < ActiveRecord::Base
7
-
8
- belongs_to :game
9
- belongs_to :person, class_name: 'PersonDb::Model::Person', foreign_key: 'person_id'
10
-
11
- end # class Goal
12
-
13
-
14
- end # module Model
15
- end # module SportDb