sportdb 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
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
+
15
+ attr_reader :include_path
16
+
17
+
18
+ def initialize( include_path, opts = {} )
19
+ @include_path = include_path
20
+ end
21
+
22
+
23
+ def read( name, more_attribs={} )
24
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
25
+
26
+ reader.each_line do |new_attributes, values|
27
+ Ground.create_or_update_from_values( new_attributes, values )
28
+ end # each lines
29
+ end
30
+
31
+
32
+ end # class GroundReader
33
+ end # module SportDb
@@ -0,0 +1,32 @@
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
+ attr_reader :include_path
15
+
16
+
17
+ def initialize( include_path, opts = {} )
18
+ @include_path = include_path
19
+ end
20
+
21
+
22
+ def read( name, more_attribs={} )
23
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
24
+
25
+ reader.each_line do |new_attributes, values|
26
+ League.create_or_update_from_values( new_attributes, values )
27
+ end # each lines
28
+ end
29
+
30
+
31
+ end # class LeagueReader
32
+ end # module SportDb
@@ -0,0 +1,102 @@
1
+ # encoding: UTF-8
2
+
3
+ module SportDb
4
+
5
+
6
+ class RaceReader
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
+ ## value helpers e.g. is_year?, is_taglist? etc.
15
+ include TextUtils::ValueHelper
16
+
17
+ include FixtureHelpers
18
+
19
+
20
+ attr_reader :include_path
21
+
22
+ def initialize( include_path, opts = {} )
23
+ @include_path = include_path
24
+ end
25
+
26
+
27
+ ###
28
+ ## fix: use read_fixtures( event_key, name )
29
+ ##
30
+ ## move EventReader out of read - why?? why not??
31
+
32
+ def read( name, more_attribs={} )
33
+
34
+ # must have .yml file with same name for event definition
35
+ evreader = EventReader.new( include_path )
36
+ evreader.read( name )
37
+
38
+ @event = evreader.event
39
+
40
+ logger.info " event: #{@event.key} >>#{@event.full_title}<<"
41
+
42
+ path = "#{include_path}/#{name}.txt"
43
+
44
+ logger.info "parsing data '#{name}' (#{path})..."
45
+
46
+ ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
47
+
48
+ ## for now: use all tracks (later filter/scope by event)
49
+ @known_tracks = Track.known_tracks_table
50
+
51
+ reader = LineReader.new( path )
52
+
53
+ read_races_worker( reader )
54
+
55
+ Prop.create_from_fixture!( name, path )
56
+ end
57
+
58
+
59
+ def read_races_worker( reader )
60
+
61
+ reader.each_line do |line|
62
+ logger.debug " line: >#{line}<"
63
+
64
+ cut_off_end_of_line_comment!( line )
65
+
66
+ pos = find_leading_pos!( line )
67
+
68
+ map_track!( line )
69
+ track_key = find_track!( line )
70
+ track = Track.find_by_key!( track_key )
71
+
72
+ date = find_date!( line )
73
+
74
+ logger.debug " line2: >#{line}<"
75
+
76
+ ### check if games exists
77
+ race = Race.find_by_event_id_and_track_id( @event.id, track.id )
78
+
79
+ if race.present?
80
+ logger.debug "update race #{race.id}:"
81
+ else
82
+ logger.debug "create race:"
83
+ race = Race.new
84
+ end
85
+
86
+ race_attribs = {
87
+ pos: pos,
88
+ track_id: track.id,
89
+ start_at: date,
90
+ event_id: @event.id
91
+ }
92
+
93
+ logger.debug race_attribs.to_json
94
+
95
+ race.update_attributes!( race_attribs )
96
+ end # lines.each
97
+
98
+ end # method read_races_worker
99
+
100
+
101
+ end # class RaceReader
102
+ end # module SportDb
@@ -0,0 +1,108 @@
1
+ # encoding: UTF-8
2
+
3
+ module SportDb
4
+
5
+
6
+ class RecordReader
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
+ ## value helpers e.g. is_year?, is_taglist? etc.
15
+ include TextUtils::ValueHelper
16
+
17
+ include FixtureHelpers
18
+
19
+
20
+ attr_reader :include_path
21
+
22
+
23
+ def initialize( include_path, opts = {} )
24
+ @include_path = include_path
25
+ end
26
+
27
+
28
+ def read( name, more_attribs={} )
29
+ path = "#{include_path}/#{name}.txt"
30
+
31
+ logger.info "parsing data '#{name}' (#{path})..."
32
+
33
+ ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
34
+
35
+ reader = LineReader.new( path )
36
+
37
+ ## for now: use all tracks (later filter/scope by event)
38
+ # @known_tracks = Track.known_tracks_table
39
+
40
+ ## fix: add @known_teams - for now; use teams (not scoped by event)
41
+ @known_teams = TextUtils.build_title_table_for( Team.all )
42
+ ## and for now use all persons
43
+ @known_persons = TextUtils.build_title_table_for( Person.all )
44
+
45
+ read_records_worker( reader, more_attribs )
46
+
47
+ Prop.create_from_fixture!( name, path )
48
+ end
49
+
50
+
51
+ def read_records_worker( reader, more_attribs )
52
+
53
+ reader.each_line do |line|
54
+ logger.debug " line: >#{line}<"
55
+
56
+ cut_off_end_of_line_comment!( line )
57
+
58
+ state = find_record_leading_state!( line )
59
+
60
+ map_team!( line )
61
+ team_key = find_team!( line )
62
+ team = Team.find_by_key!( team_key )
63
+
64
+ map_person!( line )
65
+ person_key = find_person!( line )
66
+ person = Person.find_by_key!( person_key )
67
+
68
+ timeline = find_record_timeline!( line )
69
+
70
+ laps = find_record_laps!( line )
71
+
72
+ comment = find_record_comment!( line )
73
+
74
+ logger.debug " line2: >#{line}<"
75
+
76
+ record_attribs = {
77
+ state: state,
78
+ ## team_id: team.id, ## NB: not needed for db
79
+ person_id: person.id,
80
+ timeline: timeline,
81
+ comment: comment,
82
+ laps: laps
83
+ }
84
+
85
+ record_attribs = record_attribs.merge( more_attribs )
86
+
87
+ ### check if record exists
88
+ record = Record.find_by_race_id_and_person_id( record_attribs[ :race_id ],
89
+ record_attribs[ :person_id ])
90
+
91
+ if record.present?
92
+ logger.debug "update Record #{record.id}:"
93
+ else
94
+ logger.debug "create Record:"
95
+ record = Record.new
96
+ end
97
+
98
+ logger.debug record_attribs.to_json
99
+
100
+ record.update_attributes!( record_attribs )
101
+
102
+ end # lines.each
103
+
104
+ end # method read_records_worker
105
+
106
+
107
+ end # class RecordReader
108
+ end # module SportDb
@@ -0,0 +1,98 @@
1
+ # encoding: UTF-8
2
+
3
+ module SportDb
4
+
5
+
6
+ class RosterReader
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
+ ## value helpers e.g. is_year?, is_taglist? etc.
15
+ include TextUtils::ValueHelper
16
+
17
+ include FixtureHelpers
18
+
19
+
20
+ attr_reader :include_path
21
+
22
+
23
+ def initialize( include_path, opts = {} )
24
+ @include_path = include_path
25
+ end
26
+
27
+
28
+ def read( name, more_attribs={} )
29
+ path = "#{include_path}/#{name}.txt"
30
+
31
+ logger.info "parsing data '#{name}' (#{path})..."
32
+
33
+ ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
34
+
35
+ reader = LineReader.new( path )
36
+
37
+ ## for now: use all tracks (later filter/scope by event)
38
+ # @known_tracks = Track.known_tracks_table
39
+
40
+ ## fix: add @known_teams - for now; use teams (not scoped by event)
41
+ ## for now use all teams
42
+ @known_teams = TextUtils.build_title_table_for( Team.all )
43
+ ## and for now use all persons
44
+ @known_persons = TextUtils.build_title_table_for( Person.all )
45
+
46
+
47
+ read_rosters_worker( reader )
48
+
49
+ Prop.create_from_fixture!( name, path )
50
+ end
51
+
52
+
53
+ def read_rosters_worker( reader )
54
+
55
+ reader.each_line do |line|
56
+ logger.debug " line: >#{line}<"
57
+
58
+ cut_off_end_of_line_comment!( line )
59
+
60
+ pos = find_leading_pos!( line )
61
+
62
+ map_team!( line )
63
+ team_key = find_team!( line )
64
+ team = Team.find_by_key!( team_key )
65
+
66
+ map_person!( line )
67
+ person_key = find_person!( line )
68
+ person = Person.find_by_key!( person_key )
69
+
70
+ logger.debug " line2: >#{line}<"
71
+
72
+ ### check if roster record exists
73
+ roster = Roster.find_by_event_id_and_team_id_and_person_id( @event.id, team.id, person.id )
74
+
75
+ if roster.present?
76
+ logger.debug "update Roster #{roster.id}:"
77
+ else
78
+ logger.debug "create Roster:"
79
+ roster = Roster.new
80
+ end
81
+
82
+ roster_attribs = {
83
+ pos: pos,
84
+ team_id: team.id,
85
+ person_id: person.id,
86
+ event_id: @event.id # NB: reuse/fallthrough from races - make sure load_races goes first (to setup event)
87
+ }
88
+
89
+ logger.debug roster_attribs.to_json
90
+
91
+ roster.update_attributes!( roster_attribs )
92
+ end # lines.each
93
+
94
+ end # method read_rosters_worker
95
+
96
+
97
+ end # class RosterReader
98
+ end # module SportDb
@@ -0,0 +1,64 @@
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
+ attr_reader :include_path
16
+
17
+
18
+ def initialize( include_path, opts = {} )
19
+ @include_path = include_path
20
+ end
21
+
22
+
23
+ def read( name, more_attribs={} )
24
+ reader = LineReaderV2.new( name, include_path )
25
+
26
+ ####
27
+ ## fix!!!!!
28
+ ## use Season.create_or_update_from_hash or similar
29
+ ## use Season.create_or_update_from_hash_reader?? or similar
30
+ # move parsing code to model
31
+
32
+ reader.each_line do |line|
33
+
34
+ # for now assume single value
35
+ logger.debug ">#{line}<"
36
+
37
+ key = line
38
+
39
+ logger.debug " find season key: #{key}"
40
+ season = Season.find_by_key( key )
41
+
42
+ season_attribs = {}
43
+
44
+ ## check if it exists
45
+ if season.present?
46
+ logger.debug "update season #{season.id}-#{season.key}:"
47
+ else
48
+ logger.debug "create season:"
49
+ season = Season.new
50
+ season_attribs[ :key ] = key
51
+ end
52
+
53
+ season_attribs[ :title ] = key # for now key n title are the same
54
+
55
+ logger.debug season_attribs.to_json
56
+
57
+ season.update_attributes!( season_attribs )
58
+ end # each line
59
+
60
+ end # method read
61
+
62
+
63
+ end # class SeasonReader
64
+ end # module SportDb
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+
3
+ module SportDb
4
+
5
+
6
+ class TeamReader
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
+ attr_reader :include_path
16
+
17
+
18
+ def initialize( include_path, opts = {} )
19
+ @include_path = include_path
20
+ end
21
+
22
+
23
+ def read( name, more_attribs={} )
24
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
25
+
26
+ reader.each_line do |new_attributes, values|
27
+ Team.create_or_update_from_values( new_attributes, values )
28
+ end # each lines
29
+ end
30
+
31
+
32
+
33
+ end # class TeamReader
34
+ end # module SportDb