sportdb-readers 0.3.7 → 0.4.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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34f6b00e00c0ff63899b32ef86eefd077d54315a
|
4
|
+
data.tar.gz: 6da90ea9439ed32f442fb148ce79d3184bfa7e32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ea4888386c7ae6c371d5145728a04516de88d6aa3d392feb1a141301215fd0268338e944415137ea7ded6e740ff37256da584ef53c411c6f0b2441eef96d9ee
|
7
|
+
data.tar.gz: f43c9e976a1ad41d5096bc7205799eb7371a980f8753dd6f5507e3e68ea46576e971cf41f347a0e369c83c4b4c2f52c6f7d430f1609343bc0a24213aedd2bb15
|
@@ -5,6 +5,14 @@ module SportDb
|
|
5
5
|
|
6
6
|
class AutoConfParser
|
7
7
|
|
8
|
+
def self.parse( lines, start: )
|
9
|
+
## todo/fix: add support for txt and lines
|
10
|
+
## check if lines_or_txt is an array or just a string
|
11
|
+
parser = new( lines, start )
|
12
|
+
parser.parse
|
13
|
+
end
|
14
|
+
|
15
|
+
|
8
16
|
include LogUtils::Logging
|
9
17
|
|
10
18
|
def initialize( lines, start )
|
@@ -3,6 +3,16 @@
|
|
3
3
|
module SportDb
|
4
4
|
|
5
5
|
class MatchParserSimpleV2 ## simple match parser for club match schedules
|
6
|
+
|
7
|
+
def self.parse( lines, teams, start: )
|
8
|
+
## todo/fix: add support for txt and lines
|
9
|
+
## check if lines_or_txt is an array or just a string
|
10
|
+
## use teams: like start: why? why not?
|
11
|
+
parser = new( lines, teams, start )
|
12
|
+
parser.parse
|
13
|
+
end
|
14
|
+
|
15
|
+
|
6
16
|
include LogUtils::Logging
|
7
17
|
|
8
18
|
def initialize( lines, teams, start )
|
@@ -4,6 +4,10 @@ module SportDb
|
|
4
4
|
|
5
5
|
class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why? why not?
|
6
6
|
|
7
|
+
def self.config() Import.config; end
|
8
|
+
|
9
|
+
|
10
|
+
|
7
11
|
def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
|
8
12
|
txt = File.open( path, 'r:utf-8' ).read
|
9
13
|
parse( txt, season: season )
|
@@ -14,12 +18,61 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
|
|
14
18
|
pp recs
|
15
19
|
|
16
20
|
recs.each do |rec|
|
17
|
-
league = Sync::League.
|
18
|
-
season = Sync::Season.
|
21
|
+
league = Sync::League.find_or_create( rec[:league] )
|
22
|
+
season = Sync::Season.find_or_create( rec[:season] )
|
23
|
+
|
24
|
+
stage = nil
|
25
|
+
auto_conf_clubs = nil
|
26
|
+
if rec[:stage]
|
27
|
+
event = Sync::Event.find_or_create( league: league, season: season )
|
28
|
+
stage = Sync::Stage.find( rec[:stage], event: event )
|
29
|
+
if stage.nil?
|
30
|
+
## fix: just use Stage.create
|
31
|
+
stage = Sync::Stage.find_or_create( rec[:stage], event: event )
|
32
|
+
|
33
|
+
auto_conf_clubs = AutoConfParser.parse( rec[:lines],
|
34
|
+
start: event.start_at )
|
35
|
+
end
|
36
|
+
else
|
37
|
+
event = Sync::Event.find( league: league, season: season )
|
38
|
+
if event.nil?
|
39
|
+
## fix: just use Event.create
|
40
|
+
event = Sync::Event.find_or_create( league: league, season: season )
|
41
|
+
|
42
|
+
auto_conf_clubs = AutoConfParser.parse( rec[:lines],
|
43
|
+
start: event.start_at )
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
if auto_conf_clubs
|
49
|
+
## step 1: map/find clubs
|
50
|
+
club_recs = []
|
51
|
+
## note: loop over keys (holding the names); values hold the usage counter!! e.g. 'Arsenal' => 2, etc.
|
52
|
+
country = config.countries[ league.country.key ] ## hack/fix: convert to Import::Country from Model::Country
|
53
|
+
## todo: check is_a? Country check to respond_to? :key in match in sportdb-clubs !!!!!
|
54
|
+
## todo/fix: just pass in league.country (and NOT key)
|
55
|
+
auto_conf_clubs.keys.each do |name|
|
56
|
+
club_rec = config.clubs.find_by!( name: name, country: country )
|
57
|
+
club_recs << club_rec
|
58
|
+
end
|
59
|
+
|
60
|
+
## step 2: add to database
|
61
|
+
club_recs.each do |club_rec|
|
62
|
+
club = Sync::Club.find_or_create( club_rec )
|
63
|
+
## add teams to event
|
64
|
+
## todo/fix: check if team is alreay included?
|
65
|
+
## or clear/destroy_all first!!!
|
66
|
+
if stage
|
67
|
+
stage.teams << club
|
68
|
+
else
|
69
|
+
event.teams << club
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
19
74
|
|
20
|
-
event = Sync::Event.find!( league: league, season: season )
|
21
75
|
if rec[:stage]
|
22
|
-
stage = Sync::Stage.find!( rec[:stage], event: event )
|
23
76
|
teams = stage.teams
|
24
77
|
else
|
25
78
|
teams = event.teams
|
data/test/test_reader.rb
CHANGED
@@ -10,8 +10,55 @@ require 'helper'
|
|
10
10
|
|
11
11
|
class TestReader < MiniTest::Test
|
12
12
|
|
13
|
-
def
|
13
|
+
def test_read_i
|
14
|
+
SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
|
15
|
+
SportDb.create_all ## build schema
|
16
|
+
|
17
|
+
## turn on logging to console
|
18
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
19
|
+
|
20
|
+
txt =<<TXT
|
21
|
+
= English Premier League 2017/18
|
22
|
+
|
23
|
+
Matchday 1
|
24
|
+
|
25
|
+
[Fri Aug/11]
|
26
|
+
Arsenal FC 4-3 Leicester City
|
27
|
+
[Sat Aug/12]
|
28
|
+
Watford FC 3-3 Liverpool FC
|
29
|
+
Chelsea FC 2-3 Burnley FC
|
30
|
+
Crystal Palace 0-3 Huddersfield Town
|
31
|
+
Everton FC 1-0 Stoke City
|
32
|
+
Southampton FC 0-0 Swansea City
|
33
|
+
West Bromwich Albion 1-0 AFC Bournemouth
|
34
|
+
Brighton & Hove Albion 0-2 Manchester City
|
35
|
+
[Sun Aug/13]
|
36
|
+
Newcastle United 0-2 Tottenham Hotspur
|
37
|
+
Manchester United 4-0 West Ham United
|
38
|
+
|
39
|
+
|
40
|
+
Matchday 2
|
41
|
+
|
42
|
+
[Sat Aug/19]
|
43
|
+
Swansea City 0-4 Manchester United
|
44
|
+
AFC Bournemouth 0-2 Watford FC
|
45
|
+
Burnley FC 0-1 West Bromwich Albion
|
46
|
+
Leicester City 2-0 Brighton & Hove Albion
|
47
|
+
Liverpool FC 1-0 Crystal Palace
|
48
|
+
Southampton FC 3-2 West Ham United
|
49
|
+
Stoke City 1-0 Arsenal FC
|
50
|
+
[Sun Aug/20]
|
51
|
+
Huddersfield Town 1-0 Newcastle United
|
52
|
+
Tottenham Hotspur 1-2 Chelsea FC
|
53
|
+
[Mon Aug/21]
|
54
|
+
Manchester City 1-1 Everton FC
|
55
|
+
TXT
|
56
|
+
|
57
|
+
SportDb::MatchReaderV2.parse( txt )
|
58
|
+
end # method test_read_i
|
59
|
+
|
14
60
|
|
61
|
+
def xxx_test_read_ii
|
15
62
|
SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
|
16
63
|
SportDb.create_all ## build schema
|
17
64
|
|
@@ -33,5 +80,5 @@ class TestReader < MiniTest::Test
|
|
33
80
|
recs = SportDb::MatchReaderV2.read( path )
|
34
81
|
# path = "../../../openfootball/england/2017-18/1-premierleague-ii.txt"
|
35
82
|
#recs = SportDb::MatchReaderV2.read( path )
|
36
|
-
end # method
|
83
|
+
end # method test_read_ii
|
37
84
|
end # class TestReader
|
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
|
+
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: 2019-11-
|
11
|
+
date: 2019-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sportdb-config
|