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,53 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module SportDb
4
-
5
-
6
- class GroundReader
7
-
8
- include LogUtils::Logging
9
-
10
- ## make models available by default with namespace
11
- # e.g. lets you use Usage instead of Model::Usage
12
- include Models
13
-
14
- def self.from_zip( zip_file, entry_path, more_attribs={} )
15
- ## get text content from zip
16
- entry = zip_file.find_entry( entry_path )
17
-
18
- text = entry.get_input_stream().read()
19
- text = text.force_encoding( Encoding::UTF_8 )
20
-
21
- self.from_string( text, more_attribs )
22
- end
23
-
24
- def self.from_file( path, more_attribs={} )
25
- ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
26
- ## - see textutils/utils.rb
27
- text = File.read_utf8( path )
28
- self.from_string( text, more_attribs )
29
- end
30
-
31
- def self.from_string( text, more_attribs={} )
32
- GroundReader.new( text, more_attribs )
33
- end
34
-
35
-
36
- def initialize( text, more_attribs={} )
37
- ## todo/fix: how to add opts={} ???
38
- @text = text
39
- @more_attribs = more_attribs
40
- end
41
-
42
-
43
- def read( name, more_attribs={} )
44
- reader = ValuesReader.from_string( @text, @more_attribs )
45
-
46
- reader.each_line do |new_attributes, values|
47
- Ground.create_or_update_from_values( new_attributes, values )
48
- end # each lines
49
- end
50
-
51
-
52
- end # class GroundReader
53
- end # module SportDb
@@ -1,54 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module SportDb
4
-
5
-
6
- class LeagueReader
7
-
8
- include LogUtils::Logging
9
-
10
- ## make models available by default with namespace
11
- # e.g. lets you use Usage instead of Model::Usage
12
- include Models
13
-
14
-
15
- def self.from_zip( zip_file, entry_path, more_attribs={} )
16
- ## get text content from zip
17
- entry = zip_file.find_entry( entry_path )
18
-
19
- text = entry.get_input_stream().read()
20
- text = text.force_encoding( Encoding::UTF_8 )
21
-
22
- self.from_string( text, more_attribs )
23
- end
24
-
25
- def self.from_file( path, more_attribs={} )
26
- ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
27
- ## - see textutils/utils.rb
28
- text = File.read_utf8( path )
29
- self.from_string( text, more_attribs )
30
- end
31
-
32
- def self.from_string( text, more_attribs={} )
33
- LeagueReader.new( text, more_attribs )
34
- end
35
-
36
-
37
- def initialize( text, more_attribs={} )
38
- ## todo/fix: how to add opts={} ???
39
- @text = text
40
- @more_attribs = more_attribs
41
- end
42
-
43
-
44
- def read()
45
- reader = ValuesReader.from_string( @text, @more_attribs )
46
-
47
- reader.each_line do |new_attributes, values|
48
- League.create_or_update_from_values( new_attributes, values )
49
- end # each lines
50
- end
51
-
52
-
53
- end # class LeagueReader
54
- end # module SportDb
@@ -1,83 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module SportDb
4
-
5
-
6
- class SeasonReader
7
-
8
- include LogUtils::Logging
9
-
10
- ## make models available by default with namespace
11
- # e.g. lets you use Usage instead of Model::Usage
12
- include Models
13
-
14
-
15
- def self.from_zip( zip_file, entry_path )
16
- ## get text content from zip
17
- entry = zip_file.find_entry( entry_path )
18
-
19
- text = entry.get_input_stream().read()
20
- text = text.force_encoding( Encoding::UTF_8 )
21
-
22
- self.from_string( text )
23
- end
24
-
25
- def self.from_file( path )
26
- ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
27
- ## - see textutils/utils.rb
28
- text = File.read_utf8( path )
29
- self.from_string( text )
30
- end
31
-
32
- def self.from_string( text )
33
- SeasonReader.new( text )
34
- end
35
-
36
-
37
- def initialize( text )
38
- ## todo/fix: how to add opts={} ???
39
- @text = text
40
- end
41
-
42
- def read()
43
- reader = LineReader.from_string( @text )
44
-
45
- ####
46
- ## fix!!!!!
47
- ## use Season.create_or_update_from_hash or similar
48
- ## use Season.create_or_update_from_hash_reader?? or similar
49
- # move parsing code to model
50
-
51
- reader.each_line do |line|
52
-
53
- # for now assume single value
54
- logger.debug ">#{line}<"
55
-
56
- key = line
57
-
58
- logger.debug " find season key: #{key}"
59
- season = Season.find_by_key( key )
60
-
61
- season_attribs = {}
62
-
63
- ## check if it exists
64
- if season.present?
65
- logger.debug "update season #{season.id}-#{season.key}:"
66
- else
67
- logger.debug "create season:"
68
- season = Season.new
69
- season_attribs[ :key ] = key
70
- end
71
-
72
- season_attribs[ :title ] = key # for now key n title are the same
73
-
74
- logger.debug season_attribs.to_json
75
-
76
- season.update_attributes!( season_attribs )
77
- end # each line
78
-
79
- end # method read
80
-
81
-
82
- end # class SeasonReader
83
- end # module SportDb
@@ -1,201 +0,0 @@
1
- # encoding: UTF-8
2
-
3
-
4
- module SportDb
5
-
6
- ###
7
- # todo/fix: use one squad reader for
8
- # national teams and clubs? possible? why? why not?
9
-
10
-
11
- class ClubSquadReader
12
-
13
- include LogUtils::Logging
14
-
15
- ## make models available by default with namespace
16
- # e.g. lets you use Usage instead of Model::Usage
17
- include Models
18
-
19
- ## value helpers e.g. is_year?, is_taglist? etc.
20
- include TextUtils::ValueHelper
21
-
22
- include FixtureHelpers
23
-
24
-
25
- def self.from_zip( zip_file, entry_path, more_attribs={} )
26
- ## get text content from zip
27
- entry = zip_file.find_entry( entry_path )
28
-
29
- text = entry.get_input_stream().read()
30
- text = text.force_encoding( Encoding::UTF_8 )
31
-
32
- self.from_string( text, more_attribs )
33
- end
34
-
35
- def self.from_file( path, more_attribs={} )
36
- ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
37
- ## - see textutils/utils.rb
38
- text = File.read_utf8( path )
39
- self.from_string( text, more_attribs )
40
- end
41
-
42
- def self.from_string( text, more_attribs={} )
43
- ClubSquadReader.new( text, more_attribs )
44
- end
45
-
46
-
47
- def initialize( text, more_attribs={} )
48
- ## todo/fix: how to add opts={} ???
49
- @text = text
50
- @more_attribs = more_attribs
51
- end
52
-
53
-
54
-
55
- def read()
56
- ## note:
57
- # event_id and team_id required!!
58
-
59
- # event
60
- @event = Event.find( @more_attribs[:event_id] )
61
- pp @event
62
-
63
- ## note: use @team - share/use in worker method
64
- @team = Team.find( @more_attribs[:team_id] )
65
- pp @team
66
-
67
- ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
68
-
69
- ## mapping tables for persons per country (indexed by country code); reset
70
- @country_persons_cache = {}
71
-
72
- reader = LineReader.from_string( @text )
73
-
74
- read_worker( reader )
75
-
76
- ## Prop.create_from_fixture!( name, path )
77
- end
78
-
79
-
80
- def read_worker( reader )
81
- ##
82
- ## fix: use num (optional) for offical jersey number
83
- # use pos for internal use only (ordering)
84
-
85
- pos_counter = 999000 # pos counter for undefined players w/o pos
86
-
87
- reader.each_line do |line|
88
- logger.debug " line: >#{line}<"
89
-
90
- cut_off_end_of_line_comment!( line )
91
-
92
- pos = find_leading_num!( line )
93
-
94
- if pos.nil?
95
- pos_counter+=1 ## e.g. 999001,999002 etc.
96
- pos = pos_counter
97
- end
98
-
99
- nationality = find_nationality!( line ) # e.g. ARG,AUT,USA,MEX etc. (three-letter country code)
100
-
101
- if nationality.nil?
102
- ## note: use/assume team's nationality is player's nationality
103
- nationality = @team.country.code
104
- end
105
-
106
- ## note: for now allow lines w/ missing country records in db (used in unit tests)
107
- country = Country.find_by_code( nationality )
108
- if country.nil?
109
- logger.warn "*** no country found for code >#{nationality}< in line: >#{line}<"
110
- person_key = nil ## no country, no mapping table - canNOT map person
111
- else
112
- ## try mapping person using country table
113
- ## cache mapping table by country code
114
-
115
- country_persons = @country_persons_cache[ country.code ]
116
- if country_persons.nil?
117
- logger.info " persons count for country (#{country.code}): #{country.persons.count}"
118
- country_persons = TextUtils.build_title_table_for( country.persons )
119
- @country_persons_cache[ country.code ] = country_persons # cache mapping table
120
- end
121
-
122
- map_person!( line, country_persons )
123
- person_key = find_person!( line )
124
- end
125
-
126
-
127
- logger.debug " line2: >#{line}<"
128
-
129
- if person_key.nil?
130
- ## no person match found; try auto-add person
131
- logger.info " !! no player match found; try auto-create player"
132
-
133
- buf = line.clone
134
- # remove (single match) if line starts w/ - (allow spaces) e.g. | - or |- note: must start line e.g. anchor ^ used
135
- buf = buf.sub( /^[ ]*-[ ]*/, '' ) # remove leading dash - for jersey number n/a
136
- buf = buf.gsub( /\[[^\]]+\]/, '' ) # remove [POS] or similar
137
- buf = buf.sub( '(c)', '' ) # remove captain marker
138
- buf = buf.sub( '(vc)', '' ) # remove vice-captain marker
139
- ### note: uses sub; assumes one pos marker per line
140
- buf = buf.sub( /\b(GK|DF|MF|FW)\b/, '' ) # remove position marker
141
- # since year/date e.g. 2011- assume one per line
142
- # note: use (?= |$) lookahead e.g. must be followed by space or end-of-line
143
- buf = buf.sub( /\b\d{4}-?(?= |$)/, '' )
144
- buf = buf.strip # remove leading and trailing spaces
145
-
146
- ## assume what's left is player name
147
- logger.info " player_name >#{buf}<"
148
-
149
- ## fix: add auto flag (for auto-created persons/players)
150
- ## fix: move title_to_key logic to person model etc.
151
- person_attribs = {
152
- key: TextUtils.title_to_key( buf ),
153
- title: buf
154
- }
155
-
156
- # note: add country from team or nationality marker
157
- if country
158
- person_attribs[ :country_id ] = country.id
159
- person_attribs[ :nationality_id ] = country.id
160
- end
161
-
162
- logger.info " using attribs: #{person_attribs.inspect}"
163
-
164
- person = Person.create!( person_attribs )
165
- else
166
- person = Person.find_by_key( person_key )
167
-
168
- if person.nil?
169
- logger.error " !!!!!! no mapping found for player in line >#{line}< for team #{@team.code} - #{@team.title}"
170
- next ## skip further processing of line; can NOT save w/o person; continue w/ next record
171
- end
172
- end
173
-
174
-
175
- ### check if roster record exists
176
- roster = Roster.find_by_event_id_and_team_id_and_person_id( @event.id, @team.id, person.id )
177
-
178
- if roster.present?
179
- logger.debug "update Roster #{roster.id}:"
180
- else
181
- logger.debug "create Roster:"
182
- roster = Roster.new
183
- end
184
-
185
- roster_attribs = {
186
- pos: pos,
187
- person_id: person.id,
188
- team_id: @team.id,
189
- event_id: @event.id # NB: reuse/fallthrough from races - make sure load_races goes first (to setup event)
190
- }
191
-
192
- logger.debug roster_attribs.to_json
193
-
194
- roster.update_attributes!( roster_attribs )
195
- end # lines.each
196
-
197
- end # method read_worker
198
-
199
-
200
- end # class ClubSquadReader
201
- end # module SportDb
@@ -1,173 +0,0 @@
1
- # encoding: UTF-8
2
-
3
-
4
- module SportDb
5
-
6
- ### squad/roster reader for national teams for now
7
-
8
- class NationalTeamSquadReader
9
-
10
- include LogUtils::Logging
11
-
12
- ## make models available by default with namespace
13
- # e.g. lets you use Usage instead of Model::Usage
14
- include Models
15
-
16
- ## value helpers e.g. is_year?, is_taglist? etc.
17
- include TextUtils::ValueHelper
18
-
19
- include FixtureHelpers
20
-
21
-
22
- def self.from_zip( zip_file, entry_path, more_attribs={} )
23
- ## get text content from zip
24
- entry = zip_file.find_entry( entry_path )
25
-
26
- text = entry.get_input_stream().read()
27
- text = text.force_encoding( Encoding::UTF_8 )
28
-
29
- self.from_string( text, more_attribs )
30
- end
31
-
32
- def self.from_file( path, more_attribs={} )
33
- ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
34
- ## - see textutils/utils.rb
35
- text = File.read_utf8( path )
36
- self.from_string( text, more_attribs )
37
- end
38
-
39
- def self.from_string( text, more_attribs={} )
40
- NationalTeamSquadReader.new( text, more_attribs )
41
- end
42
-
43
-
44
- def initialize( text, more_attribs={} )
45
- ## todo/fix: how to add opts={} ???
46
- @text = text
47
- @more_attribs = more_attribs
48
- end
49
-
50
-
51
- def read()
52
- ## note:
53
- # event_id and team_id required!!
54
-
55
- # event
56
- @event = Event.find( @more_attribs[:event_id] )
57
- pp @event
58
-
59
- ## note: use @team - share/use in worker method
60
- @team = Team.find( @more_attribs[:team_id] )
61
- pp @team
62
-
63
- ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
64
-
65
- reader = LineReader.from_string( @text )
66
-
67
-
68
- ##########
69
- # fix: lookup table for now assumes national team
70
- # make it usable for clubs too etc.
71
- country = @team.country
72
- pp country
73
-
74
- logger.info " persons count for country: #{country.persons.count}"
75
- @known_persons = TextUtils.build_title_table_for( country.persons )
76
-
77
-
78
- read_worker( reader )
79
-
80
- ## Prop.create_from_fixture!( name, path )
81
- end
82
-
83
-
84
- def read_worker( reader )
85
- ##
86
- ## fix: use num (optional) for offical jersey number
87
- # use pos for internal use only (ordering)
88
-
89
- pos_counter = 999000 # pos counter for undefined players w/o pos
90
-
91
- reader.each_line do |line|
92
- logger.debug " line: >#{line}<"
93
-
94
- cut_off_end_of_line_comment!( line )
95
-
96
- pos = find_leading_pos!( line )
97
-
98
- if pos.nil?
99
- pos_counter+=1 ## e.g. 999001,999002 etc.
100
- pos = pos_counter
101
- end
102
-
103
- #####
104
- # - for now do NOT map team
105
- # map_team!( line )
106
- # team_key = find_team!( line )
107
- # team = Team.find_by_key!( team_key )
108
-
109
- map_person!( line )
110
- person_key = find_person!( line )
111
-
112
- logger.debug " line2: >#{line}<"
113
-
114
- if person_key.nil?
115
- ## no person match found; try auto-add person
116
- logger.info " !! no player match found; try auto-create player"
117
-
118
- buf = line.clone
119
- # remove (single match) if line starts w/ - (allow spaces) e.g. | - or |- note: must start line e.g. anchor ^ used
120
- buf = buf.sub( /^[ ]*-[ ]*/, '' )
121
- buf = buf.gsub( /\[[^\]]+\]/, '' ) # remove [POS] or similar
122
- buf = buf.gsub( /\b(GK|DF|MF|FW)\b/, '' ) # remove position marker - use sub (just single marker?)
123
- buf = buf.strip # remove leading and trailing spaces
124
-
125
- ## assume what's left is player name
126
- logger.info " player_name >#{buf}<"
127
-
128
- ## fix: add auto flag (for auto-created persons/players)
129
- ## fix: move title_to_key logic to person model etc.
130
- person_attribs = {
131
- key: TextUtils.title_to_key( buf ),
132
- title: buf
133
- }
134
- logger.info " using attribs: #{person_attribs.inspect}"
135
-
136
- person = Person.create!( person_attribs )
137
- else
138
- person = Person.find_by_key( person_key )
139
-
140
- if person.nil?
141
- logger.error " !!!!!! no mapping found for player in line >#{line}< for team #{@team.code} - #{@team.title}"
142
- next ## skip further processing of line; can NOT save w/o person; continue w/ next record
143
- end
144
- end
145
-
146
-
147
- ### check if roster record exists
148
- roster = Roster.find_by_event_id_and_team_id_and_person_id( @event.id, @team.id, person.id )
149
-
150
- if roster.present?
151
- logger.debug "update Roster #{roster.id}:"
152
- else
153
- logger.debug "create Roster:"
154
- roster = Roster.new
155
- end
156
-
157
- roster_attribs = {
158
- pos: pos,
159
- person_id: person.id,
160
- team_id: @team.id,
161
- event_id: @event.id # NB: reuse/fallthrough from races - make sure load_races goes first (to setup event)
162
- }
163
-
164
- logger.debug roster_attribs.to_json
165
-
166
- roster.update_attributes!( roster_attribs )
167
- end # lines.each
168
-
169
- end # method read_worker
170
-
171
-
172
- end # class NationTeamSquadReader
173
- end # module SportDb