sportdb-readers 0.4.8 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fdbf4230ab31efee1c3f29d51e3f447caf9b161
4
- data.tar.gz: 48df0e0b7e1e28c06670431d7642bf9b0d2d6fbf
3
+ metadata.gz: f4a900ae50e920da9b842d72e975577d098dbedd
4
+ data.tar.gz: 9576ab392dcadb0d672535d59614c7d93ed29387
5
5
  SHA512:
6
- metadata.gz: 40ce7917d320fada2dd95eb7625ea5f1ec9646729c38c9f540c6cd0e78bf5e7fe8200e82a2b6f546239faa5da120af527c867f364a4aa61fe001a3f8b2fae775
7
- data.tar.gz: 581fffa22c4ffad1e1c8cb385e99307cc19a7099700a76d387e65e5cfb6194aa35ebd0e104a50473f15893b325955e25b648e429b29835241b2440a5641a7515
6
+ metadata.gz: e1585ce4281e1725b0452194c1c34858714dc5a40ed4b25ffe598182be9878ce46f544ee66b3d43dc64ca5480b3e00195ae6c08de013a4f3c26962c1cb920484
7
+ data.tar.gz: fd04ee65cde3a82a144473b1d63eb8a2cba1cf63c5dc0d4e0a98122ece942f2bef980ef751a6752273acf01c7adaaab68e5202d35bc86c8dc09356dde39b1b84
data/Manifest.txt CHANGED
@@ -11,5 +11,7 @@ lib/sportdb/readers/match_reader.rb
11
11
  lib/sportdb/readers/package.rb
12
12
  lib/sportdb/readers/version.rb
13
13
  test/helper.rb
14
+ test/test_match_reader_eng.rb
15
+ test/test_match_reader_mu.rb
14
16
  test/test_read.rb
15
17
  test/test_reader.rb
@@ -42,76 +42,65 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
42
42
  DateFormats.lang = 'en'
43
43
  end
44
44
 
45
+
45
46
  ## todo/fix:
46
47
  ## always auto create
47
48
  ## 1) check for clubs count on event/stage - only if count == 0 use autoconf!!!
48
49
  ## 2) add lang switch for date/lang too!!!!
49
50
 
50
- stage = nil
51
- auto_conf_clubs = nil
52
- if rec[:stage]
53
- event = Sync::Event.find_or_create( league: league, season: season )
54
- stage = Sync::Stage.find( rec[:stage], event: event )
55
- if stage.nil?
56
- ## fix: just use Stage.create
57
- stage = Sync::Stage.find_or_create( rec[:stage], event: event )
58
-
59
- auto_conf_clubs, _ = AutoConfParser.parse( rec[:lines],
60
- start: event.start_at )
61
- end
51
+ event = Sync::Event.find_or_create( league: league, season: season )
52
+
53
+ stage = if rec[:stage]
54
+ Sync::Stage.find_or_create( rec[:stage], event: event )
62
55
  else
63
- event = Sync::Event.find( league: league, season: season )
64
- if event.nil?
65
- ## fix: just use Event.create
66
- event = Sync::Event.find_or_create( league: league, season: season )
67
-
68
- auto_conf_clubs, _ = AutoConfParser.parse( rec[:lines],
69
- start: event.start_at )
70
- end
56
+ nil
71
57
  end
72
58
 
73
59
 
74
- if auto_conf_clubs
75
- pp auto_conf_clubs
76
-
77
- ## step 1: map/find clubs
78
- club_recs = []
79
- ## note: loop over keys (holding the names); values hold the usage counter!! e.g. 'Arsenal' => 2, etc.
80
- country = league.country
81
- auto_conf_clubs.keys.each do |name|
82
- club_rec = config.clubs.find_by!( name: name, country: country )
83
- club_recs << club_rec
84
- end
85
-
86
- ## todo/fix: check if all clubs are unique
87
-
88
-
89
- ## step 2: add to database
90
- club_recs.each do |club_rec|
91
- club = Sync::Club.find_or_create( club_rec )
92
- ## add teams to event
93
- ## todo/fix: check if team is alreay included?
94
- ## or clear/destroy_all first!!!
95
- if stage
96
- stage.teams << club
97
- else
98
- event.teams << club
99
- end
100
- end
60
+ auto_conf_clubs, _ = AutoConfParser.parse( rec[:lines],
61
+ start: event.start_at )
62
+
63
+ ## step 1: map/find clubs
64
+ club_recs = [] ## array of struct records
65
+ club_mapping = {} ## name => database (ActiveRecord) record
66
+
67
+ ## note: loop over keys (holding the names); values hold the usage counter!! e.g. 'Arsenal' => 2, etc.
68
+ country = league.country
69
+ auto_conf_clubs.keys.each do |name|
70
+ club_rec = config.clubs.find_by!( name: name, country: country )
71
+ club_recs << club_rec
72
+
73
+ club = Sync::Club.find_or_create( club_rec )
74
+ club_mapping[ name ] = club
101
75
  end
102
76
 
103
77
 
104
- if rec[:stage]
105
- teams = stage.teams
106
- else
107
- teams = event.teams
78
+ ## todo/fix: check if all clubs are unique
79
+ ## check if uniq works for club record (struct) - yes,no ??
80
+ clubs = club_mapping.values.uniq
81
+
82
+
83
+ ## step 2: add to database
84
+ teams = stage ? stage.teams : event.teams
85
+ team_ids = stage ? stage.team_ids : event.team_ids
86
+
87
+ clubs.each do |club|
88
+ ## add teams to event
89
+ ## for now check if team is alreay included
90
+ ## todo/fix: clear/destroy_all first - why? why not!!!
91
+
92
+ teams << club unless team_ids.include?( club.id )
108
93
  end
109
94
 
95
+
96
+
110
97
  ## todo/fix: set lang for now depending on league country!!!
111
98
  parser = MatchParserSimpleV2.new( rec[:lines],
112
- teams, ## note: use event OR stage teams (if stage is present)
99
+ club_mapping,
113
100
  event.start_at ) ## note: keep season start_at date for now (no need for more specific stage date need for now)
114
- round_recs, match_recs = parser.parse
101
+
102
+ match_recs, round_recs = parser.parse
103
+
115
104
  pp round_recs
116
105
 
117
106
  round_recs.each do |round_rec|
@@ -119,6 +108,7 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
119
108
  round_rec.pos = 999 if round_rec.pos.nil?
120
109
  round = Sync::Round.find_or_create( round_rec, event: event ) ## check: use/rename to EventRound why? why not?
121
110
  end
111
+
122
112
  match_recs.each do |match_rec|
123
113
  ## todo/fix: pass along stage (if present): stage - optional!!!!
124
114
  match = Sync::Match.create_or_update( match_rec, event: event )
@@ -5,8 +5,8 @@ module SportDb
5
5
  module Readers
6
6
 
7
7
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
8
- MINOR = 4
9
- PATCH = 8
8
+ MINOR = 5
9
+ PATCH = 0
10
10
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
11
 
12
12
  def self.version
data/test/helper.rb CHANGED
@@ -4,6 +4,10 @@
4
4
  require 'minitest/autorun'
5
5
 
6
6
 
7
+ ## note: use the local version of sportdb gems
8
+ $LOAD_PATH.unshift( File.expand_path( '../sportdb-match-formats/lib' ))
9
+
10
+
7
11
  ## our own code
8
12
  require 'sportdb/readers'
9
13
 
@@ -11,5 +15,5 @@ require 'sportdb/readers'
11
15
 
12
16
 
13
17
  ## use (switch to) "external" datasets
14
- SportDb::Import.config.clubs_dir = "../../../openfootball/clubs"
15
18
  SportDb::Import.config.leagues_dir = "../../../openfootball/leagues"
19
+ SportDb::Import.config.clubs_dir = "../../../openfootball/clubs"
@@ -0,0 +1,95 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_match_reader_eng.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestMatchReaderEng < MiniTest::Test
12
+
13
+ def setup
14
+ SportDb.connect( adapter: 'sqlite3',
15
+ database: ':memory:' )
16
+ SportDb.create_all ## build schema
17
+
18
+ ## turn on logging to console
19
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
20
+ end
21
+
22
+
23
+ def xxx_test_read_eng
24
+ txt =<<TXT
25
+ = English Premier League 2017/18
26
+
27
+ Matchday 1
28
+
29
+ [Fri Aug/11]
30
+ Arsenal FC 4-3 Leicester City
31
+ [Sat Aug/12]
32
+ Watford FC 3-3 Liverpool FC
33
+ Chelsea FC 2-3 Burnley FC
34
+ Crystal Palace 0-3 Huddersfield Town
35
+ Everton FC 1-0 Stoke City
36
+ Southampton FC 0-0 Swansea City
37
+ West Bromwich Albion 1-0 AFC Bournemouth
38
+ Brighton & Hove Albion 0-2 Manchester City
39
+ [Sun Aug/13]
40
+ Newcastle United 0-2 Tottenham Hotspur
41
+ Manchester United 4-0 West Ham United
42
+
43
+
44
+ Matchday 2
45
+
46
+ [Sat Aug/19]
47
+ Swansea City 0-4 Manchester United
48
+ AFC Bournemouth 0-2 Watford FC
49
+ Burnley FC 0-1 West Bromwich Albion
50
+ Leicester City 2-0 Brighton & Hove Albion
51
+ Liverpool FC 1-0 Crystal Palace
52
+ Southampton FC 3-2 West Ham United
53
+ Stoke City 1-0 Arsenal FC
54
+ [Sun Aug/20]
55
+ Huddersfield Town 1-0 Newcastle United
56
+ Tottenham Hotspur 1-2 Chelsea FC
57
+ [Mon Aug/21]
58
+ Manchester City 1-1 Everton FC
59
+ TXT
60
+
61
+ SportDb::MatchReaderV2.parse( txt )
62
+ end # method test_read_eng
63
+
64
+ def test_read_eng_2012_13
65
+ txt =<<TXT
66
+ ###
67
+ # see https://github.com/openfootball/england/blob/master/2012-13/1-premierleague-ii.txt
68
+ #
69
+ # check for Manchester U and Manchester C matching names
70
+ # see issue https://github.com/openfootball/england/issues/32
71
+
72
+ = English Premier League 2012/13
73
+
74
+ Matchday 20
75
+
76
+ [Sat Dec/29]
77
+ Arsenal 7-3 Newcastle
78
+ Aston Villa 0-3 Wigan
79
+ Fulham 1-2 Swansea
80
+ Manchester U. 2-0 West Bromwich
81
+ Norwich 3-4 Manchester C.
82
+ Reading 1-0 West Ham
83
+ Stoke 3-3 Southampton
84
+ Sunderland 1-2 Tottenham
85
+ [Sun Dec/30]
86
+ Everton 1-2 Chelsea
87
+ QPR 0-3 Liverpool
88
+ TXT
89
+
90
+ SportDb::MatchReaderV2.parse( txt )
91
+
92
+ puts SportDb::Model::Game.count
93
+ end
94
+
95
+ end # class TestMatchReaderEng
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_match_reader_mu.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestMatchReaderMu < MiniTest::Test
12
+
13
+ def setup
14
+ SportDb.connect( adapter: 'sqlite3',
15
+ database: ':memory:' )
16
+ SportDb.create_all ## build schema
17
+
18
+ ## turn on logging to console
19
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
20
+ end
21
+
22
+
23
+ def test_read_mauritius
24
+ leagues_txt =<<TXT
25
+ = Mauritius =
26
+
27
+ 1 Mauritius Premier League
28
+ cup Mauritius Cup
29
+ TXT
30
+
31
+
32
+ clubs_txt =<<TXT
33
+ = Mauritius =
34
+
35
+ Cercle de Joachim | Cercle de Joachim SC | Joachim
36
+ Chamarel SC | Chamarel | Chamarel Sport Club
37
+ Curepipe Starlight | Curepipe Starlight SC
38
+ Entente Boulet Rouge | Entente Boulet Rouge SC | Entente Boulet Rouge-Riche Mare Rovers
39
+ La Cure Sylvester | La Cure Sylvester SC | La Cure
40
+ Pamplemousses | Pamplemousses SC
41
+ Petite Rivière Noire | Petite Rivière Noire SC | Petite Rivière
42
+ AS Port-Louis 2000 | ASPL 2000 | Port-Louis 2000 |Association Sportive Port-Louis 2000
43
+ AS Quatre Bornes | ASQB | Quatre Bornes
44
+ Rivière du Rempart | AS Rivière du Rempart
45
+ Pointe-aux-Sables Mates
46
+ Savanne SC | Savanne Sporting Club
47
+ TXT
48
+
49
+ recs = SportDb::Import::LeagueReader.parse( leagues_txt )
50
+ SportDb::Import::config.leagues.add( recs )
51
+
52
+ recs = SportDb::Import::ClubReader.parse( clubs_txt )
53
+ SportDb::Import::config.clubs.add( recs )
54
+
55
+ pp recs
56
+
57
+ country = SportDb::Import::config.countries[ 'Mauritius']
58
+ pp country
59
+
60
+ clubs = SportDb::Import::config.clubs.match( 'Chamarel SC' )
61
+ pp clubs
62
+ club = SportDb::Import::config.clubs.find_by( name: 'Chamarel SC',
63
+ country: country )
64
+ pp club
65
+
66
+ txt =<<TXT
67
+ = Mauritius Premier League 2014/15 =
68
+
69
+ Matchday 1
70
+ [Wed Nov/5]
71
+ Curepipe Starlight 1-3 Petite Rivière Noire
72
+ AS Quatre Bornes 1-0 La Cure Sylvester
73
+ Pamplemousses 0-1 Rivière du Rempart
74
+ AS Port-Louis 2000 5-1 Entente Boulet Rouge
75
+ Chamarel SC 2-3 Cercle de Joachim
76
+
77
+ Matchday 2
78
+ [Sun Nov/9]
79
+ Curepipe Starlight 2-1 AS Quatre Bornes
80
+ Entente Boulet Rouge 1-2 Chamarel SC
81
+ Rivière du Rempart 1-1 AS Port-Louis 2000
82
+ La Cure Sylvester 1-2 Pamplemousses
83
+ Petite Rivière Noire 2-0 Cercle de Joachim
84
+
85
+ Matchday 3
86
+ [Wed Nov/12]
87
+ AS Quatre Bornes 1-2 Petite Rivière Noire
88
+ Pamplemousses 0-4 Curepipe Starlight
89
+ Chamarel SC 1-1 Rivière du Rempart
90
+ Cercle de Joachim 2-2 Entente Boulet Rouge
91
+ AS Port-Louis 2000 1-0 La Cure Sylvester
92
+ TXT
93
+
94
+ SportDb::MatchReaderV2.parse( txt )
95
+ end # method test_read_mauritius
96
+
97
+ end # class TestMatchReaderMu
data/test/test_reader.rb CHANGED
@@ -10,143 +10,15 @@ require 'helper'
10
10
 
11
11
  class TestReader < MiniTest::Test
12
12
 
13
-
14
- def test_read_mauritius
13
+ def setup
15
14
  SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
16
15
  SportDb.create_all ## build schema
17
16
 
18
17
  ## turn on logging to console
19
18
  ActiveRecord::Base.logger = Logger.new(STDOUT)
19
+ end
20
20
 
21
- leagues_txt =<<TXT
22
- = Mauritius =
23
-
24
- 1 Mauritius Premier League
25
- cup Mauritius Cup
26
- TXT
27
-
28
-
29
- clubs_txt =<<TXT
30
- = Mauritius =
31
-
32
- Cercle de Joachim | Cercle de Joachim SC | Joachim
33
- Chamarel SC | Chamarel | Chamarel Sport Club
34
- Curepipe Starlight | Curepipe Starlight SC
35
- Entente Boulet Rouge | Entente Boulet Rouge SC | Entente Boulet Rouge-Riche Mare Rovers
36
- La Cure Sylvester | La Cure Sylvester SC | La Cure
37
- Pamplemousses | Pamplemousses SC
38
- Petite Rivière Noire | Petite Rivière Noire SC | Petite Rivière
39
- AS Port-Louis 2000 | ASPL 2000 | Port-Louis 2000 |Association Sportive Port-Louis 2000
40
- AS Quatre Bornes | ASQB | Quatre Bornes
41
- Rivière du Rempart | AS Rivière du Rempart
42
- Pointe-aux-Sables Mates
43
- Savanne SC | Savanne Sporting Club
44
- TXT
45
-
46
- recs = SportDb::Import::LeagueReader.parse( leagues_txt )
47
- SportDb::Import::config.leagues.add( recs )
48
-
49
- recs = SportDb::Import::ClubReader.parse( clubs_txt )
50
- SportDb::Import::config.clubs.add( recs )
51
-
52
- pp recs
53
-
54
- country = SportDb::Import::config.countries[ 'Mauritius']
55
- pp country
56
- clubs = SportDb::Import::config.clubs.match( 'Chamarel SC' )
57
- pp clubs
58
- club = SportDb::Import::config.clubs.find_by( name: 'Chamarel SC',
59
- country: country )
60
- pp club
61
-
62
- txt =<<TXT
63
- = Mauritius Premier League 2014/15 =
64
-
65
- Matchday 1
66
- [Wed Nov/5]
67
- Curepipe Starlight 1-3 Petite Rivière Noire
68
- AS Quatre Bornes 1-0 La Cure Sylvester
69
- Pamplemousses 0-1 Rivière du Rempart
70
- AS Port-Louis 2000 5-1 Entente Boulet Rouge
71
- Chamarel SC 2-3 Cercle de Joachim
72
-
73
- Matchday 2
74
- [Sun Nov/9]
75
- Curepipe Starlight 2-1 AS Quatre Bornes
76
- Entente Boulet Rouge 1-2 Chamarel SC
77
- Rivière du Rempart 1-1 AS Port-Louis 2000
78
- La Cure Sylvester 1-2 Pamplemousses
79
- Petite Rivière Noire 2-0 Cercle de Joachim
80
-
81
- Matchday 3
82
- [Wed Nov/12]
83
- AS Quatre Bornes 1-2 Petite Rivière Noire
84
- Pamplemousses 0-4 Curepipe Starlight
85
- Chamarel SC 1-1 Rivière du Rempart
86
- Cercle de Joachim 2-2 Entente Boulet Rouge
87
- AS Port-Louis 2000 1-0 La Cure Sylvester
88
- TXT
89
-
90
- SportDb::MatchReaderV2.parse( txt )
91
- end # method test_read_mauritius
92
-
93
-
94
- def xxx_test_read_eng
95
- SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
96
- SportDb.create_all ## build schema
97
-
98
- ## turn on logging to console
99
- ActiveRecord::Base.logger = Logger.new(STDOUT)
100
-
101
- txt =<<TXT
102
- = English Premier League 2017/18
103
-
104
- Matchday 1
105
-
106
- [Fri Aug/11]
107
- Arsenal FC 4-3 Leicester City
108
- [Sat Aug/12]
109
- Watford FC 3-3 Liverpool FC
110
- Chelsea FC 2-3 Burnley FC
111
- Crystal Palace 0-3 Huddersfield Town
112
- Everton FC 1-0 Stoke City
113
- Southampton FC 0-0 Swansea City
114
- West Bromwich Albion 1-0 AFC Bournemouth
115
- Brighton & Hove Albion 0-2 Manchester City
116
- [Sun Aug/13]
117
- Newcastle United 0-2 Tottenham Hotspur
118
- Manchester United 4-0 West Ham United
119
-
120
-
121
- Matchday 2
122
-
123
- [Sat Aug/19]
124
- Swansea City 0-4 Manchester United
125
- AFC Bournemouth 0-2 Watford FC
126
- Burnley FC 0-1 West Bromwich Albion
127
- Leicester City 2-0 Brighton & Hove Albion
128
- Liverpool FC 1-0 Crystal Palace
129
- Southampton FC 3-2 West Ham United
130
- Stoke City 1-0 Arsenal FC
131
- [Sun Aug/20]
132
- Huddersfield Town 1-0 Newcastle United
133
- Tottenham Hotspur 1-2 Chelsea FC
134
- [Mon Aug/21]
135
- Manchester City 1-1 Everton FC
136
- TXT
137
-
138
- SportDb::MatchReaderV2.parse( txt )
139
- end # method test_read_eng
140
-
141
-
142
- def xxx_test_read
143
- SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
144
- SportDb.create_all ## build schema
145
-
146
- ## turn on logging to console
147
- ActiveRecord::Base.logger = Logger.new(STDOUT)
148
-
149
-
21
+ def test_read
150
22
  # path = "../../../openfootball/austria/2018-19/.conf.txt"
151
23
  path = "../../../openfootball/england/2015-16/.conf.txt"
152
24
  # path = "../../../openfootball/england/2017-18/.conf.txt"
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: 0.4.8
4
+ version: 0.5.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: 2019-12-29 00:00:00.000000000 Z
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-config
@@ -103,6 +103,8 @@ files:
103
103
  - lib/sportdb/readers/package.rb
104
104
  - lib/sportdb/readers/version.rb
105
105
  - test/helper.rb
106
+ - test/test_match_reader_eng.rb
107
+ - test/test_match_reader_mu.rb
106
108
  - test/test_read.rb
107
109
  - test/test_reader.rb
108
110
  homepage: https://github.com/sportdb/sport.db