sportdb-models 1.18.5 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +27 -145
- data/Rakefile +4 -5
- data/lib/sportdb/models.rb +93 -160
- data/lib/sportdb/{deleter.rb → models/deleter.rb} +4 -10
- data/lib/sportdb/models/formats.rb +23 -0
- data/lib/sportdb/models/models/assoc.rb +38 -0
- data/lib/sportdb/models/{badge.rb → models/badge.rb} +1 -1
- data/lib/sportdb/models/models/event.rb +55 -0
- data/lib/sportdb/models/{forward.rb → models/forward.rb} +3 -3
- data/lib/sportdb/models/{goal.rb → models/goal.rb} +1 -1
- data/lib/sportdb/models/models/ground.rb +16 -0
- data/lib/sportdb/models/{group.rb → models/group.rb} +10 -7
- data/lib/sportdb/models/models/league.rb +20 -0
- data/lib/sportdb/models/{roster.rb → models/lineup.rb} +3 -4
- data/lib/sportdb/models/{game.rb → models/match.rb} +18 -61
- data/lib/sportdb/models/{person.rb → models/person.rb} +0 -0
- data/lib/sportdb/models/{round.rb → models/round.rb} +1 -6
- data/lib/sportdb/models/{season.rb → models/season.rb} +2 -1
- data/lib/sportdb/models/{stage.rb → models/stage.rb} +9 -5
- data/lib/sportdb/models/{stats/alltime_standing_entry.rb → models/stats/alltime_standing.rb} +9 -1
- data/lib/sportdb/models/{stats/event_standing_entry.rb → models/stats/event_standing.rb} +11 -1
- data/lib/sportdb/models/{stats/group_standing_entry.rb → models/stats/group_standing.rb} +10 -1
- data/lib/sportdb/models/models/team.rb +56 -0
- data/lib/sportdb/models/{world → models/world}/city.rb +2 -2
- data/lib/sportdb/models/{world → models/world}/continent.rb +0 -0
- data/lib/sportdb/models/{world → models/world}/country.rb +0 -0
- data/lib/sportdb/models/{world → models/world}/state.rb +0 -0
- data/lib/sportdb/{schema.rb → models/schema.rb} +165 -100
- data/lib/sportdb/models/stats.rb +23 -0
- data/lib/sportdb/models/utils.rb +24 -24
- data/lib/sportdb/{version.rb → models/version.rb} +12 -5
- data/test/helper.rb +10 -114
- data/test/test_changes.rb +38 -38
- data/test/test_cursor.rb +15 -15
- data/test/test_winner.rb +75 -70
- metadata +29 -161
- data/lib/sportdb/calc.rb +0 -279
- data/lib/sportdb/indexers/team.rb +0 -87
- data/lib/sportdb/mapper_teams.rb +0 -24
- data/lib/sportdb/matcher.rb +0 -31
- data/lib/sportdb/models/assoc.rb +0 -106
- data/lib/sportdb/models/assoc_assoc.rb +0 -15
- data/lib/sportdb/models/event.rb +0 -66
- data/lib/sportdb/models/event_ground.rb +0 -15
- data/lib/sportdb/models/event_team.rb +0 -16
- data/lib/sportdb/models/ground.rb +0 -100
- data/lib/sportdb/models/group_team.rb +0 -14
- data/lib/sportdb/models/league.rb +0 -83
- data/lib/sportdb/models/stage_team.rb +0 -14
- data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
- data/lib/sportdb/models/stats/event_standing.rb +0 -55
- data/lib/sportdb/models/stats/group_standing.rb +0 -50
- data/lib/sportdb/models/team.rb +0 -119
- data/lib/sportdb/models/team_compat.rb +0 -64
- data/lib/sportdb/patterns.rb +0 -37
- data/lib/sportdb/pretty_printer.rb +0 -175
- data/lib/sportdb/reader.rb +0 -132
- data/lib/sportdb/reader_file.rb +0 -131
- data/lib/sportdb/reader_zip.rb +0 -172
- data/lib/sportdb/readers/assoc.rb +0 -54
- data/lib/sportdb/readers/event.rb +0 -253
- data/lib/sportdb/readers/event_meta.rb +0 -133
- data/lib/sportdb/readers/event_table.rb +0 -196
- data/lib/sportdb/readers/game.rb +0 -912
- data/lib/sportdb/readers/ground.rb +0 -53
- data/lib/sportdb/readers/league.rb +0 -54
- data/lib/sportdb/readers/season.rb +0 -83
- data/lib/sportdb/readers/squad_club.rb +0 -201
- data/lib/sportdb/readers/squad_national_team.rb +0 -173
- data/lib/sportdb/readers/team.rb +0 -53
- data/lib/sportdb/rsssf_reader.rb +0 -367
- data/lib/sportdb/standings.rb +0 -178
- data/lib/sportdb/stats.rb +0 -27
- data/lib/sportdb/utils.rb +0 -89
- data/lib/sportdb/utils_date.rb +0 -26
- data/lib/sportdb/utils_goals.rb +0 -20
- data/lib/sportdb/utils_group.rb +0 -63
- data/lib/sportdb/utils_map.rb +0 -44
- data/lib/sportdb/utils_round.rb +0 -165
- data/lib/sportdb/utils_scores.rb +0 -17
- data/lib/sportdb/utils_teams.rb +0 -48
- data/test/data/at-austria/2013_14/bl.txt +0 -227
- data/test/data/at-austria/2013_14/bl.yml +0 -30
- data/test/data/at-austria/2013_14/bl_ii.txt +0 -154
- data/test/data/at-austria/2013_14/el.txt +0 -4
- data/test/data/at-austria/2013_14/el.yml +0 -25
- data/test/data/at-austria/2013_14/squads/austria.txt +0 -40
- data/test/data/at-austria/2013_14/squads/salzburg.txt +0 -35
- data/test/data/at-austria/2014_15/1-bundesliga-ii.txt +0 -158
- data/test/data/at-austria/2014_15/1-bundesliga.yml +0 -18
- data/test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga-v2.yml +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.yml +0 -24
- data/test/data/at-austria/2015_16/cup.yml +0 -77
- data/test/data/at-austria/leagues.txt +0 -11
- data/test/data/at-austria/teams.txt +0 -68
- data/test/data/at-austria/teams_2.txt +0 -21
- data/test/data/csv/de-2013-14--1-bundesliga.txt +0 -307
- data/test/data/de-deutschland/2013-14/1-bundesliga.yml +0 -26
- data/test/data/de-deutschland/leagues.txt +0 -4
- data/test/data/de-deutschland/teams.txt +0 -53
- data/test/data/eng-england/2015-16/1-premierleague-v2.yml +0 -2
- data/test/data/eng-england/2015-16/1-premierleague.yml +0 -5
- data/test/data/national-teams/assocs.txt +0 -231
- data/test/data/national-teams/europe/assocs.txt +0 -13
- data/test/data/national-teams/europe/teams.txt +0 -13
- data/test/data/national-teams/north-america/assocs.txt +0 -10
- data/test/data/national-teams/north-america/teams.txt +0 -7
- data/test/data/national-teams/teams.txt +0 -19
- data/test/data/players/europe/at-austria/players.txt +0 -45
- data/test/data/players/europe/de-deutschland/players.txt +0 -41
- data/test/data/players/south-america/br-brazil/players.txt +0 -51
- data/test/data/rsssf/at-2014-15--1-bundesliga.txt +0 -339
- data/test/data/rsssf/at-2015-16--1-bundesliga.txt +0 -18
- data/test/data/world-cup/1930/cup.txt +0 -71
- data/test/data/world-cup/1930/cup.yml +0 -23
- data/test/data/world-cup/1930/cup_goals.txt +0 -47
- data/test/data/world-cup/1930/cup_goals.yml +0 -23
- data/test/data/world-cup/1954/cup.txt +0 -90
- data/test/data/world-cup/1954/cup.yml +0 -30
- data/test/data/world-cup/1962/cup.txt +0 -86
- data/test/data/world-cup/1962/cup.yml +0 -32
- data/test/data/world-cup/1974/cup.yml +0 -35
- data/test/data/world-cup/1974/cup_finals.txt +0 -14
- data/test/data/world-cup/1974/cup_i.txt +0 -55
- data/test/data/world-cup/1974/cup_ii.txt +0 -34
- data/test/data/world-cup/2014/cup.txt +0 -5
- data/test/data/world-cup/2014/cup.yml +0 -54
- data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
- data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
- data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
- data/test/data/world-cup/leagues.txt +0 -5
- data/test/data/world-cup/seasons_1930.txt +0 -4
- data/test/data/world-cup/seasons_1954.txt +0 -4
- data/test/data/world-cup/seasons_1962.txt +0 -4
- data/test/data/world-cup/seasons_1974.txt +0 -5
- data/test/data/world-cup/teams_1930.txt +0 -26
- data/test/data/world-cup/teams_1954.txt +0 -30
- data/test/data/world-cup/teams_1962.txt +0 -29
- data/test/data/world-cup/teams_1974.txt +0 -29
- data/test/test_assoc_reader.rb +0 -199
- data/test/test_event_meta_reader.rb +0 -47
- data/test/test_event_reader.rb +0 -64
- data/test/test_event_table_reader.rb +0 -57
- data/test/test_goals.rb +0 -107
- data/test/test_indexer_team.rb +0 -34
- data/test/test_load.rb +0 -61
- data/test/test_pp.rb +0 -35
- data/test/test_reader.rb +0 -88
- data/test/test_reader_from_string.rb +0 -63
- data/test/test_round_auto.rb +0 -370
- data/test/test_round_def.rb +0 -109
- data/test/test_round_header.rb +0 -183
- data/test/test_rsssf_reader.rb +0 -76
- data/test/test_squad_club_reader.rb +0 -76
- data/test/test_squad_national_team_reader.rb +0 -116
- data/test/test_standings.rb +0 -279
- data/test/test_standings_ii.rb +0 -46
- data/test/test_utils.rb +0 -124
@@ -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
|
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
|