sportdb-structs 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Manifest.txt +2 -0
- data/README.md +0 -1
- data/Rakefile +1 -1
- data/lib/sportdb/structs/event_info.rb +65 -0
- data/lib/sportdb/structs/match.rb +52 -1
- data/lib/sportdb/structs/name_helper.rb +87 -0
- data/lib/sportdb/structs/round.rb +6 -5
- data/lib/sportdb/structs/version.rb +1 -1
- data/lib/sportdb/structs.rb +40 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70fb10b4bb83d5146eb004d6c3143045e0efa430095a091429c51695a15461c6
|
4
|
+
data.tar.gz: b8377ca328aec94770b9d7e90fc60b83cbf2264a4b9ce295af7acd4846586f78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edb013626541448b4f4211d2afc779f018fe27a7b2b33af99bfce9a0876d243d4ba4079677ce7e14e5911ad7e013992632600dd5bee0958db7fc37900ded7a55
|
7
|
+
data.tar.gz: '08964910e951e7c92ef3a46a5348b1111109d326d9aed0a41311a63047de63f6a11c21bffbe8cb0f5becdb78240b66ab17817e89b2eca53059ea7b8ed601756a'
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
@@ -4,12 +4,14 @@ README.md
|
|
4
4
|
Rakefile
|
5
5
|
lib/sportdb/structs.rb
|
6
6
|
lib/sportdb/structs/country.rb
|
7
|
+
lib/sportdb/structs/event_info.rb
|
7
8
|
lib/sportdb/structs/goal.rb
|
8
9
|
lib/sportdb/structs/ground.rb
|
9
10
|
lib/sportdb/structs/group.rb
|
10
11
|
lib/sportdb/structs/league.rb
|
11
12
|
lib/sportdb/structs/match.rb
|
12
13
|
lib/sportdb/structs/matchlist.rb
|
14
|
+
lib/sportdb/structs/name_helper.rb
|
13
15
|
lib/sportdb/structs/round.rb
|
14
16
|
lib/sportdb/structs/standings.rb
|
15
17
|
lib/sportdb/structs/team.rb
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
* bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
|
6
6
|
* gem :: [rubygems.org/gems/sportdb-structs](https://rubygems.org/gems/sportdb-structs)
|
7
7
|
* rdoc :: [rubydoc.info/gems/sportdb-structs](http://rubydoc.info/gems/sportdb-structs)
|
8
|
-
* forum :: [opensport](http://groups.google.com/group/opensport)
|
9
8
|
|
10
9
|
|
11
10
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Sports
|
2
|
+
|
3
|
+
class EventInfo
|
4
|
+
## "high level" info (summary) about event
|
5
|
+
## (like a "wikipedia infobox")
|
6
|
+
## use for checking dataset imports; lets you check e.g.
|
7
|
+
## - dates within range
|
8
|
+
## - number of teams e.g. 20
|
9
|
+
## - matches played e.g. 380
|
10
|
+
## - goals scored e.g. 937
|
11
|
+
## etc.
|
12
|
+
|
13
|
+
attr_reader :league,
|
14
|
+
:season,
|
15
|
+
:teams,
|
16
|
+
:matches,
|
17
|
+
:goals,
|
18
|
+
:start_date,
|
19
|
+
:end_date
|
20
|
+
|
21
|
+
def initialize( league:, season:,
|
22
|
+
start_date: nil, end_date: nil,
|
23
|
+
teams: nil,
|
24
|
+
matches: nil,
|
25
|
+
goals: nil )
|
26
|
+
|
27
|
+
@league = league
|
28
|
+
@season = season
|
29
|
+
|
30
|
+
@start_date = start_date
|
31
|
+
@end_date = end_date
|
32
|
+
|
33
|
+
@teams = teams ## todo/check: rename/use teams_count ??
|
34
|
+
@matches = matches ## todo/check: rename/use match_count ??
|
35
|
+
@goals = goals
|
36
|
+
end
|
37
|
+
|
38
|
+
def include?( date )
|
39
|
+
## todo/fix: add options e.g.
|
40
|
+
## - add delta/off_by_one or such?
|
41
|
+
## - add strict (for) only return true if date range (really) defined (no generic auto-rules)
|
42
|
+
|
43
|
+
### note: for now allow off by one error (via timezone/local time errors)
|
44
|
+
## todo/fix: issue warning if off by one!!!!
|
45
|
+
if @start_date && @end_date
|
46
|
+
date >= (@start_date-1) &&
|
47
|
+
date <= (@end_date+1)
|
48
|
+
else
|
49
|
+
if @season.year?
|
50
|
+
# assume generic rule
|
51
|
+
## same year e.g. Jan 1 - Dec 31; always true for now
|
52
|
+
date.year == @season.start_year
|
53
|
+
else
|
54
|
+
# assume generic rule
|
55
|
+
## July 1 - June 30 (Y+1)
|
56
|
+
## - todo/check -start for some countries/leagues in June 1 or August 1 ????
|
57
|
+
date >= Date.new( @season.start_year, 7, 1 ) &&
|
58
|
+
date <= Date.new( @season.end_year, 6, 30 )
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end # method include?
|
62
|
+
alias_method :between?, :include?
|
63
|
+
end # class EventInfo
|
64
|
+
|
65
|
+
end # module Sports
|
@@ -178,8 +178,59 @@ class Match
|
|
178
178
|
# def scorei_str # pretty print (half time) scores; convenience method
|
179
179
|
# "#{@score1i}-#{@score2i}"
|
180
180
|
# end
|
181
|
-
end # class Match
|
182
181
|
|
182
|
+
|
183
|
+
def as_json
|
184
|
+
##
|
185
|
+
data = {}
|
186
|
+
|
187
|
+
## check round
|
188
|
+
if @round
|
189
|
+
data[:round ] = if round.is_a?( Integer )
|
190
|
+
"Matchday #{@round}"
|
191
|
+
else ## assume string
|
192
|
+
@round
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
data[:num] = @num if @num
|
198
|
+
if @date
|
199
|
+
## assume 2020-09-19 date format!!
|
200
|
+
data[:date] = @date.is_a?( String ) ? @date : @date.strftime('%Y-%m-%d')
|
201
|
+
|
202
|
+
data[:time] = @time if @time
|
203
|
+
end
|
204
|
+
|
205
|
+
data[:team1] = @team1.is_a?( String ) ? @team1 : @team1.name
|
206
|
+
data[:team2] = @team2.is_a?( String ) ? @team2 : @team2.name
|
207
|
+
|
208
|
+
data[:score] = {}
|
209
|
+
|
210
|
+
data[:score][:ht] = [@score1i, @score2i] if @score1i && @score2i
|
211
|
+
data[:score][:ft] = [@score1, @score2] if @score1 && @score2
|
212
|
+
data[:score][:et] = [@score1et, @score2et] if @score1et && @score2et
|
213
|
+
data[:score][:p] = [@score1p, @score2p] if @score1p && @score2p
|
214
|
+
|
215
|
+
data[:group] = @group if @group
|
216
|
+
|
217
|
+
=begin
|
218
|
+
"round": "Spieltag 1",
|
219
|
+
"date": "2020-09-19",
|
220
|
+
"team1": "Eintracht Frankfurt",
|
221
|
+
"team2": "Arminia Bielefeld",
|
222
|
+
"score": {
|
223
|
+
"ft": [
|
224
|
+
1,
|
225
|
+
1
|
226
|
+
]
|
227
|
+
}
|
228
|
+
=end
|
229
|
+
data
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
end # class Match
|
183
234
|
end # module Sports
|
184
235
|
|
185
236
|
|
@@ -0,0 +1,87 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
module NameHelper
|
4
|
+
|
5
|
+
|
6
|
+
## note: allow placeholder years to e.g. (-___) or (-????)
|
7
|
+
## for marking missing (to be filled in) years
|
8
|
+
## e.g. (1887-1911), (-2013),
|
9
|
+
## (1946-2001, 2013-) etc.
|
10
|
+
## todo/check: make more strict e.g. only accept 4-digit years? - why? why not?
|
11
|
+
YEAR_RE = %r{\(
|
12
|
+
[0-9, ?_-]+? # note: non-greedy (minimum/first) match
|
13
|
+
\)}x
|
14
|
+
|
15
|
+
def strip_year( name )
|
16
|
+
## check for year(s) e.g. (1887-1911), (-2013),
|
17
|
+
## (1946-2001, 2013-) etc.
|
18
|
+
## todo/check: only sub once (not global) - why? why not?
|
19
|
+
name.gsub( YEAR_RE, '' ).strip
|
20
|
+
end
|
21
|
+
|
22
|
+
def has_year?( name ) name =~ YEAR_RE; end
|
23
|
+
|
24
|
+
|
25
|
+
LANG_RE = %r{\[
|
26
|
+
[a-z]{1,2} # note also allow single-letter [a] or [d] or [e] - why? why not?
|
27
|
+
\]}x
|
28
|
+
def strip_lang( name )
|
29
|
+
name.gsub( LANG_RE, '' ).strip
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_lang?( name ) name =~ LANG_RE; end
|
33
|
+
|
34
|
+
|
35
|
+
def sanitize( name )
|
36
|
+
## check for year(s) e.g. (1887-1911), (-2013),
|
37
|
+
## (1946-2001,2013-) etc.
|
38
|
+
name = strip_year( name )
|
39
|
+
## check lang codes e.g. [en], [fr], etc.
|
40
|
+
name = strip_lang( name )
|
41
|
+
name
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
## note: also add (),’,− etc. e.g.
|
46
|
+
## Estudiantes (LP) => Estudiantes LP
|
47
|
+
## Saint Patrick’s Athletic FC => Saint Patricks Athletic FC
|
48
|
+
## Myllykosken Pallo −47 => Myllykosken Pallo 47
|
49
|
+
##
|
50
|
+
## add & too!!
|
51
|
+
## e.g. Brighton & Hove Albion => Brighton Hove Albion -- and others in England
|
52
|
+
|
53
|
+
NORM_RE = %r{
|
54
|
+
[.'’º/()&_−-]
|
55
|
+
}x # note: in [] dash (-) if last doesn't need to get escaped
|
56
|
+
## note: remove all dots (.), dash (-), ', º, /, etc.
|
57
|
+
# . U+002E (46) - FULL STOP
|
58
|
+
# ' U+0027 (39) - APOSTROPHE
|
59
|
+
# ’ U+2019 (8217) - RIGHT SINGLE QUOTATION MARK
|
60
|
+
# º U+00BA (186) - MASCULINE ORDINAL INDICATOR
|
61
|
+
# / U+002F (47) - SOLIDUS
|
62
|
+
# ( U+0028 (40) - LEFT PARENTHESIS
|
63
|
+
# ) U+0029 (41) - RIGHT PARENTHESIS
|
64
|
+
# − U+2212 (8722) - MINUS SIGN
|
65
|
+
# - U+002D (45) - HYPHEN-MINUS
|
66
|
+
|
67
|
+
## for norm(alizing) names
|
68
|
+
def strip_norm( name )
|
69
|
+
name.gsub( NORM_RE, '' )
|
70
|
+
end
|
71
|
+
|
72
|
+
def normalize( name )
|
73
|
+
# note: do NOT call sanitize here (keep normalize "atomic" for reuse)
|
74
|
+
name = strip_norm( name )
|
75
|
+
name = name.gsub( ' ', '' ) # note: also remove all spaces!!!
|
76
|
+
|
77
|
+
## todo/check: use our own downcase - why? why not?
|
78
|
+
name = downcase_i18n( name ) ## do NOT care about upper and lowercase for now
|
79
|
+
name
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def variants( name ) Variant.find( name ); end
|
84
|
+
|
85
|
+
end # module NameHelper
|
86
|
+
end # module SportDb
|
87
|
+
|
@@ -18,18 +18,19 @@ module Sports
|
|
18
18
|
@auto = auto # auto-created (inline reference/header without proper definition before)
|
19
19
|
end
|
20
20
|
|
21
|
-
def pretty_print( printer )
|
22
|
-
## todo/check - how to display/format key - use () or not - why? why not?
|
21
|
+
def pretty_print( printer )
|
22
|
+
## todo/check - how to display/format key - use () or not - why? why not?
|
23
23
|
buf = String.new
|
24
24
|
buf << "<Round: "
|
25
25
|
buf << "(#{@num}) " if @num
|
26
26
|
buf << "#{@name}, "
|
27
|
-
buf << "#{@start_date}
|
27
|
+
buf << "#{@start_date}"
|
28
|
+
buf << " - #{@end_date}" if @start_date != @end_date
|
28
29
|
buf << " (knockout)" if @knockout
|
29
30
|
buf << " (auto)" if @auto
|
30
31
|
buf << ">"
|
31
|
-
|
32
|
-
printer.text( buf )
|
32
|
+
|
33
|
+
printer.text( buf )
|
33
34
|
end
|
34
35
|
end # class Round
|
35
36
|
end # module Sports
|
data/lib/sportdb/structs.rb
CHANGED
@@ -21,6 +21,12 @@ require_relative 'structs/matchlist'
|
|
21
21
|
require_relative 'structs/standings'
|
22
22
|
require_relative 'structs/team_usage'
|
23
23
|
|
24
|
+
require_relative 'structs/event_info'
|
25
|
+
|
26
|
+
|
27
|
+
## shared support helpers/machinery
|
28
|
+
require_relative 'structs/name_helper'
|
29
|
+
|
24
30
|
|
25
31
|
##
|
26
32
|
## todo/fix - move "inline" player to structs/player file !!!!
|
@@ -59,13 +65,45 @@ end # module Sports
|
|
59
65
|
|
60
66
|
|
61
67
|
|
68
|
+
|
69
|
+
|
70
|
+
##
|
71
|
+
## add all structs in SportDb::Import namespace too
|
72
|
+
module SportDb
|
73
|
+
module Import
|
74
|
+
Season = ::Season ## add a convenience alias for top-level Season class
|
75
|
+
|
76
|
+
## add "old" convenience aliases for structs - why? why not?
|
77
|
+
## todo/check: just use include Sports !!!!
|
78
|
+
Country = ::Sports::Country
|
79
|
+
League = ::Sports::League
|
80
|
+
Group = ::Sports::Group
|
81
|
+
Round = ::Sports::Round
|
82
|
+
Match = ::Sports::Match
|
83
|
+
Matchlist = ::Sports::Matchlist
|
84
|
+
Goal = ::Sports::Goal
|
85
|
+
Team = ::Sports::Team
|
86
|
+
NationalTeam = ::Sports::NationalTeam
|
87
|
+
Club = ::Sports::Club
|
88
|
+
Standings = ::Sports::Standings
|
89
|
+
TeamUsage = ::Sports::TeamUsage
|
90
|
+
|
91
|
+
Ground = ::Sports::Ground
|
92
|
+
|
93
|
+
Player = ::Sports::Player
|
94
|
+
|
95
|
+
EventInfo = ::Sports::EventInfo
|
96
|
+
end # module Import
|
97
|
+
end # module SportDb
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
62
102
|
#####
|
63
103
|
# note: add Sport and Football convenience alias - why? why not?
|
64
104
|
Sport = Sports
|
65
105
|
Football = Sports
|
66
106
|
|
67
107
|
|
68
|
-
|
69
|
-
|
70
108
|
puts SportDb::Module::Structs.banner # say hello
|
71
109
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-structs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alphabets
|
@@ -102,12 +102,14 @@ files:
|
|
102
102
|
- Rakefile
|
103
103
|
- lib/sportdb/structs.rb
|
104
104
|
- lib/sportdb/structs/country.rb
|
105
|
+
- lib/sportdb/structs/event_info.rb
|
105
106
|
- lib/sportdb/structs/goal.rb
|
106
107
|
- lib/sportdb/structs/ground.rb
|
107
108
|
- lib/sportdb/structs/group.rb
|
108
109
|
- lib/sportdb/structs/league.rb
|
109
110
|
- lib/sportdb/structs/match.rb
|
110
111
|
- lib/sportdb/structs/matchlist.rb
|
112
|
+
- lib/sportdb/structs/name_helper.rb
|
111
113
|
- lib/sportdb/structs/round.rb
|
112
114
|
- lib/sportdb/structs/standings.rb
|
113
115
|
- lib/sportdb/structs/team.rb
|
@@ -127,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
129
|
requirements:
|
128
130
|
- - ">="
|
129
131
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
132
|
+
version: 3.1.0
|
131
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
134
|
requirements:
|
133
135
|
- - ">="
|