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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59763aec58a5729bbe978c4f81ac60de0b883e3f
4
- data.tar.gz: 8fe8c7a0362bb664620f0392865a2435d8d54ef7
3
+ metadata.gz: 618fca12af08a963b2d86cbb61b377751e365092
4
+ data.tar.gz: fdddea7cb85f4ff6581f11f897bd1f087d9bdd4b
5
5
  SHA512:
6
- metadata.gz: f700cc86b085a7b882211c0d2bc7033287e4b523403374eba95ff58ef2fe9b930fd09d6e4c57483e5b5a978aa487825b7fcdcd34ea873299a94604d443403f83
7
- data.tar.gz: '08a052e7b179189c2eae987c24c6e90915a74f3666a87dd116bef60a4b7266c693d7419415df0311e91f35c287c2c19b0b5b8a7faa86c2f0345f88bd5e672090'
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
- ``` ruby
35
- ## turn on logging to console
36
- ActiveRecord::Base.logger = Logger.new( STDOUT )
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::ConfReaderV2.read( './england/2015-16/.conf.txt' )
41
- SportDb::MatchReaderV2.read( './england/2015-16/1-premierleague-i.txt' )
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::ConfReaderV2.read( './england/2019-20/.conf.txt' )
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.
@@ -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 ) ConfReaderV2.read( path, season: season ); end
20
- def self.parse_conf( txt, season: nil ) ConfReaderV2.parse( txt, season: season ); end
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 ) MatchReaderV2.read( path, season: season ); end
24
- def self.parse_match( txt, season: nil ) MatchReaderV2.parse( txt, season: season ); end
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 ConfReaderV2 ## todo/check: rename to EventsReaderV2 (use plural?) why? why not?
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 ConfReaderV2
99
+ end # class ConfReader
100
100
  end # module SportDb
@@ -2,7 +2,7 @@
2
2
 
3
3
  module SportDb
4
4
 
5
- class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why? why not?
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 = MatchParserSimpleV2.new( lines,
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 MatchReaderV2
152
+ end # class MatchReader
153
153
  end # module SportDb
@@ -49,7 +49,8 @@ module SportDb
49
49
  read_leagues()
50
50
  read_clubs()
51
51
  read_club_props()
52
- read_conf( season: season )
52
+ ## note: skip conf(iguration)s for now!!!!!!!
53
+ ## read_conf( season: season )
53
54
  read_match( season: season )
54
55
  else
55
56
  names.each do |name|
@@ -6,7 +6,7 @@ module Readers
6
6
 
7
7
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
8
8
  MINOR = 0
9
- PATCH = 1
9
+ PATCH = 2
10
10
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
11
 
12
12
  def self.version
@@ -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::ConfReaderV2.read( path )
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::ConfReaderV2.parse( txt )
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::MatchReaderV2.parse( txt )
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::MatchReaderV2.parse( txt )
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::MatchReaderV2.parse( txt )
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::MatchReaderV2.parse( txt )
90
+ SportDb::MatchReader.parse( txt )
91
91
 
92
92
  puts SportDb::Model::Game.count
93
93
  end
@@ -149,7 +149,7 @@ Final
149
149
  (51) Jul/10 21:00 Portugal 0:0 1:0nV France @ Stade de France, Saint-Denis
150
150
  TXT
151
151
 
152
- SportDb::MatchReaderV2.parse( txt )
152
+ SportDb::MatchReader.parse( txt )
153
153
  end
154
154
  end # class TestMatchReaderEuro
155
155
 
@@ -91,7 +91,7 @@ Matchday 3
91
91
  AS Port-Louis 2000 1-0 La Cure Sylvester
92
92
  TXT
93
93
 
94
- SportDb::MatchReaderV2.parse( txt )
94
+ SportDb::MatchReader.parse( txt )
95
95
  end # method test_read_mauritius
96
96
 
97
97
  end # class TestMatchReaderMu
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::ConfReaderV2.read( path )
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::MatchReaderV2.read( path )
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
@@ -64,7 +64,7 @@ Monaco › MCO
64
64
  APOEL › CYP
65
65
  TXT
66
66
 
67
- SportDb::ConfReaderV2.parse( txt )
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::MatchReaderV2.parse( txt )
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.1
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 00:00:00.000000000 Z
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-sync