sportdb-formats 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51b22ea9a05b89006e8048871b2616d5a4fadd4fcb435dc1fd33c1194a6182de
4
- data.tar.gz: '069b114b3679b2f0bf1fda38c4b97b52a949d7e3e0ab1e9cad41e0f08b540c28'
3
+ metadata.gz: e1efe8dd989cd71d6a1860f9b0845b9aa96fadab5abe9e381bcae2cb3da77d5a
4
+ data.tar.gz: d03be83401dec8b4ad1c09455d11c307bb4bd83e706d47c2ce8950dae1744e10
5
5
  SHA512:
6
- metadata.gz: 29f00ceff229bc2e8445ee6ef6c2c0a7ecd27b00c899535130f10f480ec0526b18d5e3df30e78f1577f35f6e65fe6aafff2f99ef587eb869445b9b9ab5f20c2c
7
- data.tar.gz: c97c1568d3b063ba2e25afa21c07479ac4f098df7c0bf2e5a3701a5ef2eb9d8c2c56415573191bae0cb7fbbc07e8ee229eca30fdeda9b1a0713615cdf4c46b5a
6
+ metadata.gz: 64e3013796d515b02564e179bb3b0eed1bc12a671f9f0615d613c9f86dc3eea465a0ff6680904c5f1465dc7b252791bc8ae4012c914599bbcddf1534aa77d705
7
+ data.tar.gz: f1f9ed7ec7fc1fb6af8fb143f7510e503d70d0e7ab6114763b2bdc3aef545d9dde6b0a6bdff4064e273268d5ba0b01e865aaeeebeee3d1c42ffd6767c47b2db8
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 1.2.0
1
+ ### 2.0.0
2
2
 
3
3
  ### 0.0.1 / 2019-10-28
4
4
 
data/Manifest.txt CHANGED
@@ -4,23 +4,22 @@ README.md
4
4
  Rakefile
5
5
  lib/sportdb/formats.rb
6
6
  lib/sportdb/formats/country/country_reader.rb
7
+ lib/sportdb/formats/csv/goal.rb
8
+ lib/sportdb/formats/csv/goal_parser_csv.rb
9
+ lib/sportdb/formats/csv/match_parser_csv.rb
10
+ lib/sportdb/formats/csv/match_status_parser.rb
7
11
  lib/sportdb/formats/datafile.rb
8
12
  lib/sportdb/formats/datafile_package.rb
9
13
  lib/sportdb/formats/event/event_reader.rb
10
- lib/sportdb/formats/goals.rb
11
14
  lib/sportdb/formats/ground/ground_reader.rb
12
15
  lib/sportdb/formats/league/league_outline_reader.rb
13
16
  lib/sportdb/formats/league/league_reader.rb
14
- lib/sportdb/formats/lines_reader.rb
15
17
  lib/sportdb/formats/match/conf_parser.rb
16
- lib/sportdb/formats/match/mapper.rb
17
- lib/sportdb/formats/match/mapper_teams.rb
18
18
  lib/sportdb/formats/match/match_parser.rb
19
- lib/sportdb/formats/match/match_parser_auto_conf.rb
20
- lib/sportdb/formats/outline_reader.rb
19
+ lib/sportdb/formats/name_helper.rb
21
20
  lib/sportdb/formats/package.rb
22
- lib/sportdb/formats/parser_helper.rb
23
21
  lib/sportdb/formats/search/sport.rb
22
+ lib/sportdb/formats/search/structs.rb
24
23
  lib/sportdb/formats/search/world.rb
25
24
  lib/sportdb/formats/team/club_index_history.rb
26
25
  lib/sportdb/formats/team/club_reader.rb
data/Rakefile CHANGED
@@ -20,12 +20,16 @@ Hoe.spec 'sportdb-formats' do
20
20
  self.licenses = ['Public Domain']
21
21
 
22
22
  self.extra_deps = [
23
- ['sportdb-structs', '>= 0.1.1'],
23
+ ['sportdb-structs', '>= 0.3.0'],
24
+ ['sportdb-parser', '>= 0.2.0'],
25
+ ['date-formats', '>= 1.0.2'],
26
+ ['cocos', '>= 0.4.0'],
27
+ ['logutils', '>= 0.6.1'],
24
28
 
25
- ['rubyzip', '>= 1.2.4' ],
29
+ ['rubyzip', '>= 2.3.2' ],
26
30
  ]
27
31
 
28
32
  self.spec_extras = {
29
- required_ruby_version: '>= 2.2.2'
33
+ required_ruby_version: '>= 3.1.0'
30
34
  }
31
35
  end
@@ -0,0 +1,192 @@
1
+
2
+ module Sports
3
+
4
+ ## "free-standing" goal event - for import/export in separate event / goal datafiles
5
+ ## returned by CsvGoalParser and others
6
+ class GoalEvent
7
+
8
+ def self.build( row ) ## rename to parse or such - why? why not?
9
+
10
+ ## split match_id
11
+ team_str, more_str = row['Match'].split( '|' )
12
+ team1_str, team2_str = team_str.split( ' - ' )
13
+
14
+ more_str = more_str.strip
15
+ team1_str = team1_str.strip
16
+ team2_str = team2_str.strip
17
+
18
+ # check if more_str is a date otherwise assume round
19
+ date_fmt = if more_str =~ /^[A-Z]{3} [0-9]{1,2}$/i ## Apr 4
20
+ '%b %d'
21
+ elsif more_str =~ /^[A-Z]{3} [0-9]{1,2} [0-9]{4}$/i ## Apr 4 2019
22
+ '%b %d %Y'
23
+ else
24
+ nil
25
+ end
26
+
27
+ if date_fmt
28
+ date = Date.strptime( more_str, date_fmt )
29
+ round = nil
30
+ else
31
+ date = nil
32
+ round = more_str
33
+ end
34
+
35
+
36
+ values = row['Score'].split('-')
37
+ values = values.map { |value| value.strip }
38
+ score1 = values[0].to_i
39
+ score2 = values[1].to_i
40
+
41
+ minute = nil
42
+ offset = nil
43
+ if m=%r{([0-9]+)
44
+ (?:[ ]+
45
+ \+([0-9]+)
46
+ )?
47
+ ['.]
48
+ $}x.match( row['Minute'])
49
+ minute = m[1].to_i
50
+ offset = m[2] ? m[2].to_i : nil
51
+ else
52
+ puts "!! ERROR - unsupported minute (goal) format >#{row['Minute']}<"
53
+ exit 1
54
+ end
55
+
56
+ attributes = {
57
+ team1: team1_str,
58
+ team2: team2_str,
59
+ date: date,
60
+ round: round,
61
+ score1: score1,
62
+ score2: score2,
63
+ minute: minute,
64
+ offset: offset,
65
+ player: row['Player'],
66
+ owngoal: ['(og)', '(o.g.)'].include?( row['Extra']),
67
+ penalty: ['(pen)', '(pen.)'].include?( row['Extra']),
68
+ notes: (row['Notes'].nil? || row['Notes'].empty?) ? nil : row['Notes']
69
+ }
70
+
71
+ new( **attributes )
72
+ end
73
+
74
+
75
+ ## match id
76
+ attr_reader :team1,
77
+ :team2,
78
+ :round, ## optional
79
+ :date ## optional
80
+
81
+ ## main attributes
82
+ attr_reader :score1,
83
+ :score2,
84
+ :player,
85
+ :minute,
86
+ :offset,
87
+ :owngoal,
88
+ :penalty,
89
+ :notes
90
+
91
+
92
+ ## todo/check: or just use match.hash or such if match mapping known - why? why not?
93
+ def match_id
94
+ if round
95
+ "#{@team1} - #{@team2} | #{@round}"
96
+ else
97
+ "#{@team1} - #{@team2} | #{@date}"
98
+ end
99
+ end
100
+
101
+
102
+ def owngoal?() @owngoal==true; end
103
+ def penalty?() @penalty==true; end
104
+
105
+ def initialize( team1:,
106
+ team2:,
107
+ round: nil,
108
+ date: nil,
109
+ score1:,
110
+ score2:,
111
+ player:,
112
+ minute:,
113
+ offset: nil,
114
+ owngoal: false,
115
+ penalty: false,
116
+ notes: nil
117
+ )
118
+ @team1 = team1
119
+ @team2 = team2
120
+ @round = round
121
+ @date = date
122
+
123
+ @score1 = score1
124
+ @score2 = score2
125
+ @player = player
126
+ @minute = minute
127
+ @offset = offset
128
+ @owngoal = owngoal
129
+ @penalty = penalty
130
+ @notes = notes
131
+ end
132
+
133
+
134
+ ## note: lets you use normalize teams or such acts like a Match struct
135
+ def update( **kwargs )
136
+ ## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not?
137
+ @team1 = kwargs[:team1] if kwargs.has_key? :team1
138
+ @team2 = kwargs[:team2] if kwargs.has_key? :team2
139
+ end
140
+ end # class GoalEvent
141
+
142
+
143
+ ### extend "basic" goal struct with goal event build
144
+ class Goal ### nested (non-freestanding) inside match (match is parent)
145
+
146
+ def self.build( events ) ## check/todo - rename to build_from_event/row or such - why? why not?
147
+ ## build an array of goal structs from (csv) recs
148
+ recs = []
149
+
150
+ last_score1 = 0
151
+ last_score2 = 0
152
+
153
+ events.each do |event|
154
+
155
+ if last_score1+1 == event.score1 && last_score2 == event.score2
156
+ team = 1
157
+ elsif last_score2+1 == event.score2 && last_score1 == event.score1
158
+ team = 2
159
+ else
160
+ puts "!! ERROR - unexpected score advance (one goal at a time expected):"
161
+ puts " #{last_score1}-#{last_score2}=> #{event.score1}-#{event.score2}"
162
+ exit 1
163
+ end
164
+
165
+ last_score1 = event.score1
166
+ last_score2 = event.score2
167
+
168
+
169
+ attributes = {
170
+ score1: event.score1,
171
+ score2: event.score2,
172
+ team: team,
173
+ minute: event.minute,
174
+ offset: event.offset,
175
+ player: event.player,
176
+ owngoal: event.owngoal,
177
+ penalty: event.penalty,
178
+ notes: event.notes
179
+ }
180
+
181
+ recs << new( **attributes )
182
+ end
183
+
184
+ recs
185
+ end
186
+ end # class Goal
187
+
188
+
189
+ end # module Sports
190
+
191
+
192
+
@@ -0,0 +1,28 @@
1
+
2
+ module SportDb
3
+ class CsvGoalParser
4
+
5
+
6
+ def self.read( path )
7
+ txt = File.open( path, 'r:utf-8' ) {|f| f.read } ## note: make sure to use (assume) utf-8
8
+ parse( txt )
9
+ end
10
+
11
+ def self.parse( txt )
12
+ new( txt ).parse
13
+ end
14
+
15
+
16
+ def initialize( txt )
17
+ @txt = txt
18
+ end
19
+
20
+ def parse
21
+ rows = parse_csv( @txt )
22
+ recs = rows.map { |row| Sports::GoalEvent.build( row ) }
23
+ ## pp recs[0]
24
+ recs
25
+ end
26
+
27
+ end # class CsvGoalParser
28
+ end # module Sports