sportdb-readers 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +66 -11
- data/lib/sportdb/readers.rb +4 -4
- data/lib/sportdb/readers/conf_reader.rb +2 -2
- data/lib/sportdb/readers/match_reader.rb +3 -3
- data/lib/sportdb/readers/package.rb +2 -1
- data/lib/sportdb/readers/version.rb +1 -1
- data/test/test_conf_reader.rb +2 -2
- data/test/test_match_reader_champs.rb +2 -2
- data/test/test_match_reader_eng.rb +2 -2
- data/test/test_match_reader_euro.rb +1 -1
- data/test/test_match_reader_mu.rb +1 -1
- data/test/test_reader.rb +2 -2
- data/test/test_reader_champs.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 618fca12af08a963b2d86cbb61b377751e365092
|
4
|
+
data.tar.gz: fdddea7cb85f4ff6581f11f897bd1f087d9bdd4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b1a5174887fd02e6f95f1574766dde03102b034175eb610cd8b28ab30d4cba890f256ac657af15e4129355807dada2294c2b101101d861bfccef71f4fd7f40e
|
7
|
+
data.tar.gz: 3e200b894e12bcfa8f0b44ae1efb2e4e123b06e6fbaac920be88a99aacbb68db5ce705b5c7f9c944ec91214b1b4f8f77096e7bf3af574a2ed54f62f25abed2de
|
data/README.md
CHANGED
@@ -31,46 +31,101 @@ Let's read in some leagues, seasons, clubs, and match schedules and results.
|
|
31
31
|
Let's use the public domain football.db datasets for England (see [`openfootball/england`](https://github.com/openfootball/england)), as an example:
|
32
32
|
|
33
33
|
|
34
|
-
```
|
35
|
-
|
36
|
-
|
34
|
+
```
|
35
|
+
= English Premier League 2015/16
|
36
|
+
|
37
|
+
Matchday 1
|
38
|
+
|
39
|
+
[Sat Aug 8]
|
40
|
+
Manchester United 1-0 Tottenham Hotspur
|
41
|
+
AFC Bournemouth 0-1 Aston Villa
|
42
|
+
Everton FC 2-2 Watford FC
|
43
|
+
Leicester City 4-2 Sunderland AFC
|
44
|
+
Norwich City 1-3 Crystal Palace
|
45
|
+
Chelsea FC 2-2 Swansea City
|
46
|
+
[Sun Aug 9]
|
47
|
+
Arsenal FC 0-2 West Ham United
|
48
|
+
Newcastle United 2-2 Southampton FC
|
49
|
+
Stoke City 0-1 Liverpool FC
|
50
|
+
[Mon Aug 10]
|
51
|
+
West Bromwich Albion 0-3 Manchester City
|
52
|
+
|
53
|
+
...
|
54
|
+
```
|
37
55
|
|
56
|
+
and let's try:
|
57
|
+
|
58
|
+
``` ruby
|
38
59
|
## assumes football.db datasets for England in ./england directory
|
39
60
|
## see github.com/openfootball/england
|
40
|
-
SportDb::
|
41
|
-
SportDb::
|
42
|
-
SportDb::MatchReaderV2.read( './england/2015-16/1-premierleague-ii.txt' )
|
61
|
+
SportDb::MatchReader.read( './england/2015-16/1-premierleague-i.txt' )
|
62
|
+
SportDb::MatchReader.read( './england/2015-16/1-premierleague-ii.txt' )
|
43
63
|
|
44
64
|
## let's try another season
|
45
|
-
SportDb::
|
46
|
-
SportDb::MatchReaderV2.read( './england/2019-20/1-premierleague.txt' )
|
65
|
+
SportDb::MatchReader.read( './england/2019-20/1-premierleague.txt' )
|
47
66
|
```
|
48
67
|
|
49
68
|
All leagues, seasons, clubs, match days and rounds, match fixtures and results,
|
50
69
|
and more are now in your (SQL) database of choice.
|
51
70
|
|
71
|
+
The proof of the pudding - Let's query the (SQL) database using the sport.db ActiveRecord models:
|
72
|
+
|
73
|
+
``` ruby
|
74
|
+
include SportDb::Models
|
75
|
+
|
76
|
+
pl_2015_16 = Event.find_by( key: 'eng.1.2015/16' )
|
77
|
+
#=> SELECT * FROM events WHERE key = 'eng.1.2015/16' LIMIT 1
|
78
|
+
|
79
|
+
pl_2015_16.teams.count #=> 20
|
80
|
+
#=> SELECT COUNT(*) FROM teams
|
81
|
+
# INNER JOIN events_teams ON teams.id = events_teams.team_id
|
82
|
+
# WHERE events_teams.event_id = 1
|
83
|
+
|
84
|
+
pl_2015_16.games.count #=> 380
|
85
|
+
#=> SELECT COUNT(*) FROM games
|
86
|
+
# INNER JOIN rounds ON games.round_id = rounds.id
|
87
|
+
# WHERE rounds.event_id = 1
|
88
|
+
|
89
|
+
pl_2019_20 = Event.find_by( key: 'eng.1.2019/20' )
|
90
|
+
pl_2015_16.teams.count #=> 20
|
91
|
+
pl_2015_16.games.count #=> 380
|
92
|
+
|
93
|
+
# -or-
|
94
|
+
|
95
|
+
pl = League.find_by( key: 'eng.1' )
|
96
|
+
#=> SELECT * FROM leagues WHERE key = 'eng.1' LIMIT 1
|
97
|
+
|
98
|
+
pl.seasons.count #=> 2
|
99
|
+
#=> SELECT COUNT(*) FROM seasons
|
100
|
+
# INNER JOIN events ON seasons.id = events.season_id
|
101
|
+
# WHERE events.league_id = 1
|
102
|
+
|
103
|
+
# and so on and so forth.
|
104
|
+
```
|
105
|
+
|
106
|
+
|
52
107
|
|
53
108
|
Or as an alternative use the `read` convenience all-in-one shortcut helper:
|
54
109
|
|
55
110
|
``` ruby
|
56
111
|
## assumes football.db datasets for England in ./england directory
|
57
112
|
## see github.com/openfootball/england
|
58
|
-
SportDb.read( './england/2015-16/.conf.txt' )
|
59
113
|
SportDb.read( './england/2015-16/1-premierleague-i.txt' )
|
60
114
|
SportDb.read( './england/2015-16/1-premierleague-ii.txt' )
|
61
115
|
|
62
116
|
## let's try another season
|
63
|
-
SportDb.read( './england/2019-20/.conf.txt' )
|
64
117
|
SportDb.read( './england/2019-20/1-premierleague.txt' )
|
65
118
|
```
|
66
119
|
|
67
|
-
Or as an alternative pass in the "package" directory and let `read` figure
|
120
|
+
Bonus: Or as an alternative pass in the "package" directory or a zip archive and let `read` figure
|
68
121
|
out what datafiles to read:
|
69
122
|
|
70
123
|
``` ruby
|
71
124
|
## assumes football.db datasets for England in ./england directory
|
72
125
|
## see github.com/openfootball/england
|
73
126
|
SportDb.read( './england' )
|
127
|
+
## -or- use a zip archive download
|
128
|
+
SportDb.read( './england.zip' )
|
74
129
|
```
|
75
130
|
|
76
131
|
That's it.
|
data/lib/sportdb/readers.rb
CHANGED
@@ -16,12 +16,12 @@ require 'sportdb/readers/package'
|
|
16
16
|
##
|
17
17
|
## add convenience shortcut helpers
|
18
18
|
module SportDb
|
19
|
-
def self.read_conf( path, season: nil )
|
20
|
-
def self.parse_conf( txt, season: nil )
|
19
|
+
def self.read_conf( path, season: nil ) ConfReader.read( path, season: season ); end
|
20
|
+
def self.parse_conf( txt, season: nil ) ConfReader.parse( txt, season: season ); end
|
21
21
|
|
22
22
|
### todo/check: add alias read_matches - why? why not?
|
23
|
-
def self.read_match( path, season: nil )
|
24
|
-
def self.parse_match( txt, season: nil )
|
23
|
+
def self.read_match( path, season: nil ) MatchReader.read( path, season: season ); end
|
24
|
+
def self.parse_match( txt, season: nil ) MatchReader.parse( txt, season: season ); end
|
25
25
|
|
26
26
|
def self.read_club_props( path ) Import::ClubPropsReader.read( path ); end
|
27
27
|
def self.parse_club_props( txt ) Import::ClubPropsReader.parse( txt ); end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module SportDb
|
4
4
|
|
5
5
|
|
6
|
-
class
|
6
|
+
class ConfReader ## todo/check: rename to EventsReaderV2 (use plural?) why? why not?
|
7
7
|
|
8
8
|
def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
|
9
9
|
txt = File.open( path, 'r:utf-8' ) {|f| f.read }
|
@@ -96,5 +96,5 @@ class ConfReaderV2 ## todo/check: rename to EventsReaderV2 (use plural?) why?
|
|
96
96
|
|
97
97
|
def catalog() Import.catalog; end ## shortcut convenience helper
|
98
98
|
|
99
|
-
end # class
|
99
|
+
end # class ConfReader
|
100
100
|
end # module SportDb
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module SportDb
|
4
4
|
|
5
|
-
class
|
5
|
+
class MatchReader ## todo/check: rename to MatchReaderV2 (use plural?) why? why not?
|
6
6
|
|
7
7
|
def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
|
8
8
|
txt = File.open( path, 'r:utf-8' ) {|f| f.read }
|
@@ -87,7 +87,7 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
|
|
87
87
|
team_mapping = auto_conf_teams.keys.zip( teams ).to_h
|
88
88
|
|
89
89
|
|
90
|
-
parser =
|
90
|
+
parser = MatchParser.new( lines,
|
91
91
|
team_mapping,
|
92
92
|
start ) ## note: keep season start_at date for now (no need for more specific stage date need for now)
|
93
93
|
|
@@ -149,5 +149,5 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
|
|
149
149
|
|
150
150
|
def catalog() Import.catalog; end
|
151
151
|
|
152
|
-
end # class
|
152
|
+
end # class MatchReader
|
153
153
|
end # module SportDb
|
data/test/test_conf_reader.rb
CHANGED
@@ -25,7 +25,7 @@ class TestConfReader < MiniTest::Test
|
|
25
25
|
# path = "../../../openfootball/england/2017-18/.conf.txt"
|
26
26
|
# path = "../../../openfootball/england/2018-19/.conf.txt"
|
27
27
|
# path = "../../../openfootball/england/2019-20/.conf.txt"
|
28
|
-
SportDb::
|
28
|
+
SportDb::ConfReader.read( path )
|
29
29
|
end # method test_read
|
30
30
|
|
31
31
|
|
@@ -73,6 +73,6 @@ Monaco › MCO
|
|
73
73
|
APOEL › CYP
|
74
74
|
TXT
|
75
75
|
|
76
|
-
SportDb::
|
76
|
+
SportDb::ConfReader.parse( txt )
|
77
77
|
end
|
78
78
|
end # class TestConfReader
|
@@ -363,7 +363,7 @@ Group H:
|
|
363
363
|
[Llorente 20' Son Heung-min 37' N'Koudou 80']
|
364
364
|
TXT
|
365
365
|
|
366
|
-
SportDb::
|
366
|
+
SportDb::MatchReader.parse( txt )
|
367
367
|
end
|
368
368
|
|
369
369
|
def test_read_finals
|
@@ -480,7 +480,7 @@ Final
|
|
480
480
|
[Benzema 51' Bale 64', 83'; Mané 55']
|
481
481
|
TXT
|
482
482
|
|
483
|
-
SportDb::
|
483
|
+
SportDb::MatchReader.parse( txt )
|
484
484
|
end
|
485
485
|
|
486
486
|
|
@@ -58,7 +58,7 @@ Matchday 2
|
|
58
58
|
Manchester City 1-1 Everton FC
|
59
59
|
TXT
|
60
60
|
|
61
|
-
SportDb::
|
61
|
+
SportDb::MatchReader.parse( txt )
|
62
62
|
end # method test_read_eng
|
63
63
|
|
64
64
|
def test_read_eng_2012_13
|
@@ -87,7 +87,7 @@ Matchday 20
|
|
87
87
|
QPR 0-3 Liverpool
|
88
88
|
TXT
|
89
89
|
|
90
|
-
SportDb::
|
90
|
+
SportDb::MatchReader.parse( txt )
|
91
91
|
|
92
92
|
puts SportDb::Model::Game.count
|
93
93
|
end
|
data/test/test_reader.rb
CHANGED
@@ -24,13 +24,13 @@ class TestReader < MiniTest::Test
|
|
24
24
|
# path = "../../../openfootball/england/2017-18/.conf.txt"
|
25
25
|
# path = "../../../openfootball/england/2018-19/.conf.txt"
|
26
26
|
# path = "../../../openfootball/england/2019-20/.conf.txt"
|
27
|
-
recs = SportDb::
|
27
|
+
recs = SportDb::ConfReader.read( path )
|
28
28
|
# path = "../../../openfootball/austria/2018-19/1-bundesliga.txt"
|
29
29
|
path = "../../../openfootball/england/2015-16/1-premierleague-i.txt"
|
30
30
|
# path = "../../../openfootball/england/2017-18/1-premierleague-i.txt"
|
31
31
|
# path = "../../../openfootball/england/2018-19/1-premierleague.txt"
|
32
32
|
# path = "../../../openfootball/england/2019-20/1-premierleague.txt"
|
33
|
-
recs = SportDb::
|
33
|
+
recs = SportDb::MatchReader.read( path )
|
34
34
|
# path = "../../../openfootball/england/2017-18/1-premierleague-ii.txt"
|
35
35
|
#recs = SportDb::MatchReaderV2.read( path )
|
36
36
|
end # method test_read
|
data/test/test_reader_champs.rb
CHANGED
@@ -64,7 +64,7 @@ Monaco › MCO
|
|
64
64
|
APOEL › CYP
|
65
65
|
TXT
|
66
66
|
|
67
|
-
SportDb::
|
67
|
+
SportDb::ConfReader.parse( txt )
|
68
68
|
|
69
69
|
|
70
70
|
txt =<<TXT
|
@@ -180,7 +180,7 @@ Final
|
|
180
180
|
[Benzema 51' Bale 64', 83'; Mané 55']
|
181
181
|
TXT
|
182
182
|
|
183
|
-
SportDb::
|
183
|
+
SportDb::MatchReader.parse( txt )
|
184
184
|
end
|
185
185
|
|
186
186
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-readers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sportdb-sync
|