sportdb-importers 1.0.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 +7 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +11 -0
- data/README.md +50 -0
- data/Rakefile +31 -0
- data/lib/sportdb/importers/import.rb +126 -0
- data/lib/sportdb/importers/version.rb +26 -0
- data/lib/sportdb/importers.rb +68 -0
- data/test/helper.rb +27 -0
- data/test/test_club.rb +162 -0
- data/test/test_import.rb +55 -0
- data/test/test_version.rb +20 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf896cfb7ec92171a5238fcb3b9b434dca7fa651
|
4
|
+
data.tar.gz: ed14f81d52b1487f869d7a0a2574d5b6104cefcc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1420fc54d8b03f8ba7467fa3fc6cac2e18c3f2529316012e4f1400288470cca691c9abb2459d5e07fc097b0ffedc6b8c48e6e2e47d2dc31564604b836b4c2214
|
7
|
+
data.tar.gz: 16132b877f95ca4f41e78d153dc5de9633f2d766ba60e0b1a50708bd59819c237be1b1372d2d053e39cb2a7202ed46cc1f356553c55c45c0ae2b543b87b4318b
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# sportdb-importers - tools 'n' scripts for importing sports (football) data in alternate (text) formats incl. comma-separated values (csv) format"
|
2
|
+
|
3
|
+
|
4
|
+
* home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
|
5
|
+
* bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
|
6
|
+
* gem :: [rubygems.org/gems/sportdb-importers](https://rubygems.org/gems/sportdb-importers)
|
7
|
+
* rdoc :: [rubydoc.info/gems/sportdb-importers](http://rubydoc.info/gems/sportdb-importers)
|
8
|
+
* forum :: [opensport](http://groups.google.com/group/opensport)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Let's import all datafiles for all seasons (from 1888-89 to today)
|
15
|
+
for [England](https://github.com/footballcsv/england), use:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
require 'sportdb/importers'
|
19
|
+
|
20
|
+
## note: requires a local copy of the football.db clubs datasets
|
21
|
+
## see https://github.com/openfootball/clubs
|
22
|
+
SportDb::Import.config.clubs_dir = './clubs'
|
23
|
+
|
24
|
+
|
25
|
+
SportDb.connect( adapter: 'sqlite3',
|
26
|
+
database: './eng.db' )
|
27
|
+
|
28
|
+
SportDb.create_all ## build database schema / tables
|
29
|
+
|
30
|
+
|
31
|
+
## note: requires a local copy of the football.csv england datasets
|
32
|
+
## see https://github.com/footballcsv/england
|
33
|
+
pack = CsvPackage.new( './england' )
|
34
|
+
pack.import
|
35
|
+
```
|
36
|
+
|
37
|
+
That's it.
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The `sportdb-importers` scripts are dedicated to the public domain.
|
43
|
+
Use it as you please with no restrictions whatsoever.
|
44
|
+
|
45
|
+
|
46
|
+
## Questions? Comments?
|
47
|
+
|
48
|
+
Send them along to the
|
49
|
+
[Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
|
50
|
+
Thanks!
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/sportdb/importers/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'sportdb-importers' do
|
5
|
+
|
6
|
+
self.version = SportDb::Importers::VERSION
|
7
|
+
|
8
|
+
self.summary = "sportdb-importers - tools 'n' scripts for importing sports (football) data in alternate (text) formats incl. comma-separated values (csv) format"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = ['https://github.com/sportdb/sport.db']
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'opensport@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
|
20
|
+
self.licenses = ['Public Domain']
|
21
|
+
|
22
|
+
self.extra_deps = [
|
23
|
+
['sportdb-text', '>= 0.4.0'],
|
24
|
+
['sportdb-sync', '>= 1.0.0'],
|
25
|
+
]
|
26
|
+
|
27
|
+
self.spec_extras = {
|
28
|
+
required_ruby_version: '>= 2.2.2'
|
29
|
+
}
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
|
2
|
+
## todo/fix: rename to CsvEventImporter or EventImporter !!! returns Event!!
|
3
|
+
class CsvEventImporter ## todo/fix/check: rename to CsvMatchReader and CsvMatchReader to CsvMatchParser - why? why not?
|
4
|
+
|
5
|
+
def self.read( path, league:, season:,
|
6
|
+
headers: nil )
|
7
|
+
txt = File.open( path, 'r:utf-8' ) {|f| f.read }
|
8
|
+
parse( txt, league: league, season: season,
|
9
|
+
headers: headers )
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse( txt, league:, season:,
|
13
|
+
headers: nil )
|
14
|
+
new( txt, league: league, season: season,
|
15
|
+
headers: headers ).parse
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def initialize( txt, league:, season:, headers: nil )
|
20
|
+
@txt = txt
|
21
|
+
@headers = headers
|
22
|
+
|
23
|
+
raise ArgumentError("string expected for league; got #{league.class.name}") unless league.is_a? String
|
24
|
+
raise ArgumentError("string expected for season; got #{season.class.name}") unless season.is_a? String
|
25
|
+
|
26
|
+
## try mapping of league here - why? why not?
|
27
|
+
@league = SportDb::Import.catalog.leagues.find!( league )
|
28
|
+
@season = SportDb::Import::Season.new( season )
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def parse
|
33
|
+
## todo/fix: add headers options (pass throughto CsvMatchReader)
|
34
|
+
## add filters too why? why not?
|
35
|
+
|
36
|
+
## todo/fix:
|
37
|
+
## add normalize: false/mapping: false flag for NOT mapping club/team names
|
38
|
+
## make normalize: false the default, anyways - why? why not?
|
39
|
+
opts = {}
|
40
|
+
opts[:headers] = @headers if @headers
|
41
|
+
|
42
|
+
matches = CsvMatchReader.parse( @txt, **opts )
|
43
|
+
|
44
|
+
matchlist = SportDb::Import::Matchlist.new( matches )
|
45
|
+
|
46
|
+
team_names = matchlist.teams ## was: find_teams_in_matches_txt( matches_txt )
|
47
|
+
puts "#{team_names.size} teams:"
|
48
|
+
pp team_names
|
49
|
+
|
50
|
+
## note: allows duplicates - will return uniq struct recs in teams
|
51
|
+
teams = SportDb::Import.catalog.teams.find_by!( name: team_names,
|
52
|
+
league: @league )
|
53
|
+
## build mapping - name => team struct record
|
54
|
+
team_mappings = team_names.zip( teams ).to_h
|
55
|
+
|
56
|
+
pp team_mappings
|
57
|
+
|
58
|
+
|
59
|
+
#######
|
60
|
+
# start with database updates / sync here
|
61
|
+
|
62
|
+
event_rec = SportDb::Sync::Event.find_or_create_by( league: @league,
|
63
|
+
season: @season )
|
64
|
+
|
65
|
+
## todo/fix:
|
66
|
+
## add check if event has teams
|
67
|
+
## if yes - only double check and do NOT create / add teams
|
68
|
+
## number of teams must match (use teams only for lookup/alt name matches)
|
69
|
+
|
70
|
+
## note: allows duplicates - will return uniq db recs in teams
|
71
|
+
## and mappings from names to uniq db recs
|
72
|
+
|
73
|
+
## todo/fix: rename to team_recs_cache or team_cache - why? why not?
|
74
|
+
|
75
|
+
# maps struct record "canonical" team name to active record db record!!
|
76
|
+
## note: use "canonical" team name as hash key for now (and NOT the object itself) - why? why not?
|
77
|
+
team_recs = SportDb::Sync::Team.find_or_create( team_mappings.values.uniq )
|
78
|
+
|
79
|
+
## todo/fix/check:
|
80
|
+
## add check if event has teams
|
81
|
+
## if yes - only double check and do NOT create / add teams
|
82
|
+
## number of teams must match (use teams only for lookup/alt name matches)
|
83
|
+
|
84
|
+
## add teams to event
|
85
|
+
## todo/fix: check if team is alreay included?
|
86
|
+
## or clear/destroy_all first!!!
|
87
|
+
event_rec.teams = team_recs ## todo/check/fix: use team_ids instead - why? why not?
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
## add catch-all/unclassified "dummy" round
|
92
|
+
round_rec = SportDb::Model::Round.create!(
|
93
|
+
event_id: event_rec.id,
|
94
|
+
title: 'Matchday ??? / Missing / Catch-All', ## find a better name?
|
95
|
+
pos: 999,
|
96
|
+
start_at: event_rec.start_at.to_date
|
97
|
+
)
|
98
|
+
|
99
|
+
## add matches
|
100
|
+
matches.each do |match|
|
101
|
+
team1_rec = SportDb::Sync::Team.cache[ team_mappings[match.team1].name ]
|
102
|
+
team2_rec = SportDb::Sync::Team.cache[ team_mappings[match.team2].name ]
|
103
|
+
|
104
|
+
if match.date.nil?
|
105
|
+
puts "!!! WARN: skipping match - play date missing!!!!!"
|
106
|
+
pp match
|
107
|
+
else
|
108
|
+
rec = SportDb::Model::Game.create!(
|
109
|
+
team1_id: team1_rec.id,
|
110
|
+
team2_id: team2_rec.id,
|
111
|
+
round_id: round_rec.id,
|
112
|
+
pos: 999, ## make optional why? why not? - change to num?
|
113
|
+
play_at: Date.strptime( match.date, '%Y-%m-%d' ),
|
114
|
+
score1: match.score1,
|
115
|
+
score2: match.score2,
|
116
|
+
score1i: match.score1i,
|
117
|
+
score2i: match.score2i,
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end # each match
|
121
|
+
|
122
|
+
event_rec # note: return event database record
|
123
|
+
end # method parse
|
124
|
+
|
125
|
+
end # class CsvEventImporter
|
126
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
module SportDb
|
6
|
+
module Importers
|
7
|
+
|
8
|
+
MAJOR = 1 ## todo: namespace inside version or something - why? why not??
|
9
|
+
MINOR = 0
|
10
|
+
PATCH = 0
|
11
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
12
|
+
|
13
|
+
def self.version
|
14
|
+
VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.banner
|
18
|
+
"sportdb-importers/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.root
|
22
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )
|
23
|
+
end
|
24
|
+
|
25
|
+
end # module Importers
|
26
|
+
end # module SportDb
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
## 3rd party gemss
|
5
|
+
require 'sportdb/text'
|
6
|
+
require 'sportdb/sync'
|
7
|
+
|
8
|
+
|
9
|
+
###
|
10
|
+
# our own code
|
11
|
+
require 'sportdb/importers/version' # let version always go first
|
12
|
+
require 'sportdb/importers/import'
|
13
|
+
|
14
|
+
|
15
|
+
class CsvPackage
|
16
|
+
## (re)open class - note: adds more machinery; see sportdb-text for first/original/base definition
|
17
|
+
|
18
|
+
def import( start: nil )
|
19
|
+
## start - season e.g. 1993/94 to start (skip older seasons)
|
20
|
+
## note: assume package holds country/national (club) league
|
21
|
+
# use for importing german bundesliga, english premier league, etc.
|
22
|
+
|
23
|
+
entries = find_entries_by_season
|
24
|
+
pp entries
|
25
|
+
|
26
|
+
entries.each_with_index do |(season_key, datafiles),i|
|
27
|
+
|
28
|
+
puts "season [#{i+1}] >#{season_key}<:"
|
29
|
+
|
30
|
+
## todo/fix: use a "generic" filter_season helper for easy reuse
|
31
|
+
## filter_season( clause, season_key )
|
32
|
+
## or better filter = SeasonFilter.new( clause )
|
33
|
+
## filter.skip? filter.include? ( season_sason_key )?
|
34
|
+
## fiteer.before?( season_key ) etc.
|
35
|
+
## find some good method names!!!!
|
36
|
+
if start
|
37
|
+
start_year = start[0..3].to_i
|
38
|
+
season_start_year = season_key[0..3].to_i
|
39
|
+
if season_start_year < start_year
|
40
|
+
puts "skip #{season_start_year} before #{start_year}"
|
41
|
+
next
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
datafiles.each do |datafile,j|
|
46
|
+
path = expand_path( datafile )
|
47
|
+
## note: assume datafile basename (without extension) is the league key
|
48
|
+
## e.g. eng.1, eng.3a, eng.3b, at.1, champs, world, etc.
|
49
|
+
league_key = File.basename( datafile, File.extname( datafile ) ) ## get basename WITHOUT extension
|
50
|
+
|
51
|
+
pp [path, season_key, league_key]
|
52
|
+
|
53
|
+
event = CsvEventImporter.read( path, league: league_key,
|
54
|
+
season: season_key )
|
55
|
+
|
56
|
+
puts "added #{event.title}"
|
57
|
+
puts " #{event.teams.size} teams"
|
58
|
+
puts " #{event.rounds.size} rounds"
|
59
|
+
puts " #{event.games.size} games"
|
60
|
+
end # each datafile
|
61
|
+
end # each season
|
62
|
+
end # method import
|
63
|
+
|
64
|
+
end # class CsvPackage
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
puts SportDb::Importers.banner # say hello
|
data/test/helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## note: use the local version of sportdb gems
|
2
|
+
$LOAD_PATH.unshift( File.expand_path( '../sportdb-formats/lib' ))
|
3
|
+
$LOAD_PATH.unshift( File.expand_path( '../sportdb-config/lib' ))
|
4
|
+
$LOAD_PATH.unshift( File.expand_path( '../sportdb-text/lib' ))
|
5
|
+
$LOAD_PATH.unshift( File.expand_path( '../sportdb-models/lib' ))
|
6
|
+
$LOAD_PATH.unshift( File.expand_path( '../sportdb-sync/lib' ))
|
7
|
+
|
8
|
+
|
9
|
+
## minitest setup
|
10
|
+
|
11
|
+
require 'minitest/autorun'
|
12
|
+
|
13
|
+
|
14
|
+
## our own code
|
15
|
+
require 'sportdb/importers'
|
16
|
+
|
17
|
+
|
18
|
+
## use (switch to) "external" datasets
|
19
|
+
SportDb::Import.config.leagues_dir = "../../../openfootball/leagues"
|
20
|
+
SportDb::Import.config.clubs_dir = "../../../openfootball/clubs"
|
21
|
+
|
22
|
+
|
23
|
+
COUNTRIES = SportDb::Import.catalog.countries
|
24
|
+
LEAGUES = SportDb::Import.catalog.leagues
|
25
|
+
CLUBS = SportDb::Import.catalog.clubs
|
26
|
+
TEAMS = SportDb::Import.catalog.teams
|
27
|
+
|
data/test/test_club.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_club.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class TestClub < MiniTest::Test
|
9
|
+
|
10
|
+
def test_eng_i
|
11
|
+
## todo/fix:
|
12
|
+
## add guest1_country_id (optional) to league (e.g. wales for english premier leaguage)
|
13
|
+
## (e.g. canada for mls)
|
14
|
+
## (e.g. liechtenstein for swiss superleague) etc.
|
15
|
+
## why? why not?
|
16
|
+
|
17
|
+
## fetch English Premiere League
|
18
|
+
league = LEAGUES.find!( 'ENG' )
|
19
|
+
|
20
|
+
team_names = [
|
21
|
+
'Manchester City',
|
22
|
+
'Arsenal',
|
23
|
+
'Liverpool',
|
24
|
+
'Cardiff',
|
25
|
+
]
|
26
|
+
|
27
|
+
recs = TEAMS.find_by!( name: team_names,
|
28
|
+
league: league )
|
29
|
+
|
30
|
+
assert_equal 4, recs.size
|
31
|
+
|
32
|
+
assert_equal 'Manchester City FC', recs[0].name
|
33
|
+
## assert_equal 'Manchester', recs[0].city.name
|
34
|
+
assert_equal 'England', recs[0].country.name
|
35
|
+
|
36
|
+
assert_equal 'Arsenal FC', recs[1].name
|
37
|
+
## assert_equal 'London', recs[1].city.name
|
38
|
+
assert_equal 'England', recs[1].country.name
|
39
|
+
|
40
|
+
assert_equal 'Cardiff City FC', recs[3].name
|
41
|
+
## assert_equal 'Cardiff', recs[3].city.name
|
42
|
+
assert_equal 'Wales', recs[3].country.name
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def test_eng_ii
|
47
|
+
headers = {
|
48
|
+
date: 'Date',
|
49
|
+
team1: 'HomeTeam',
|
50
|
+
team2: 'AwayTeam',
|
51
|
+
score1: 'FTHG',
|
52
|
+
score2: 'FTAG',
|
53
|
+
score1i: 'HTHG',
|
54
|
+
score2i: 'HTAG'
|
55
|
+
}
|
56
|
+
|
57
|
+
matches = CsvMatchReader.read( "#{SportDb::Test.data_dir}/england/2017-18/E0.csv",
|
58
|
+
headers: headers
|
59
|
+
)
|
60
|
+
|
61
|
+
## pp matches[0..2]
|
62
|
+
|
63
|
+
matchlist = SportDb::Import::Matchlist.new( matches )
|
64
|
+
team_names = matchlist.teams
|
65
|
+
puts "#{team_names.size} team names:"
|
66
|
+
pp team_names
|
67
|
+
=begin
|
68
|
+
20 team names:
|
69
|
+
["Arsenal",
|
70
|
+
"Bournemouth",
|
71
|
+
"Brighton",
|
72
|
+
"Burnley",
|
73
|
+
"Chelsea",
|
74
|
+
"Crystal Palace",
|
75
|
+
"Everton",
|
76
|
+
"Huddersfield",
|
77
|
+
"Leicester",
|
78
|
+
"Liverpool",
|
79
|
+
"Man City",
|
80
|
+
"Man United",
|
81
|
+
"Newcastle",
|
82
|
+
"Southampton",
|
83
|
+
"Stoke",
|
84
|
+
"Swansea",
|
85
|
+
"Tottenham",
|
86
|
+
"Watford",
|
87
|
+
"West Brom",
|
88
|
+
"West Ham"]
|
89
|
+
=end
|
90
|
+
|
91
|
+
|
92
|
+
## fetch English Premiere League
|
93
|
+
league = LEAGUES.find!( 'ENG' )
|
94
|
+
|
95
|
+
recs = TEAMS.find_by!( name: team_names,
|
96
|
+
league: league )
|
97
|
+
|
98
|
+
assert_equal 20, recs.size
|
99
|
+
|
100
|
+
assert_equal 'Arsenal FC', recs[0].name
|
101
|
+
## assert_equal '?', recs[0].city.name
|
102
|
+
assert_equal 'England', recs[0].country.name
|
103
|
+
|
104
|
+
assert_equal 'AFC Bournemouth', recs[1].name
|
105
|
+
## assert_equal '?', recs[1].city.name
|
106
|
+
assert_equal 'England', recs[1].country.name
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def test_at
|
111
|
+
headers = {
|
112
|
+
## season: 'Season', ## check if season required / needed???
|
113
|
+
date: 'Date',
|
114
|
+
team1: 'Home',
|
115
|
+
team2: 'Away',
|
116
|
+
score1: 'HG',
|
117
|
+
score2: 'AG',
|
118
|
+
}
|
119
|
+
|
120
|
+
matches = CsvMatchReader.read( "#{SportDb::Test.data_dir}/austria/AUT.csv",
|
121
|
+
headers: headers,
|
122
|
+
filters: { 'Season' => '2016/2017' }
|
123
|
+
)
|
124
|
+
|
125
|
+
## pp matches[0..2]
|
126
|
+
|
127
|
+
matchlist = SportDb::Import::Matchlist.new( matches )
|
128
|
+
team_names = matchlist.teams
|
129
|
+
puts "#{team_names.size} team names:"
|
130
|
+
pp team_names
|
131
|
+
=begin
|
132
|
+
10 team names:
|
133
|
+
["AC Wolfsberger",
|
134
|
+
"Admira",
|
135
|
+
"Altach",
|
136
|
+
"Austria Vienna",
|
137
|
+
"Mattersburg",
|
138
|
+
"Rapid Vienna",
|
139
|
+
"Ried",
|
140
|
+
"Salzburg",
|
141
|
+
"St. Polten",
|
142
|
+
"Sturm Graz"]
|
143
|
+
=end
|
144
|
+
|
145
|
+
## fetch Österr. Bundesliga
|
146
|
+
league = LEAGUES.find!( 'AT' )
|
147
|
+
|
148
|
+
recs = TEAMS.find_by!( name: team_names,
|
149
|
+
league: league )
|
150
|
+
|
151
|
+
assert_equal 10, recs.size
|
152
|
+
|
153
|
+
assert_equal 'Wolfsberger AC', recs[0].name
|
154
|
+
## assert_equal '?', recs[0].city.name
|
155
|
+
assert_equal 'Austria', recs[0].country.name
|
156
|
+
|
157
|
+
assert_equal 'FC Admira Wacker Mödling', recs[1].name
|
158
|
+
## assert_equal '?', recs[1].city.name
|
159
|
+
assert_equal 'Austria', recs[1].country.name
|
160
|
+
end
|
161
|
+
|
162
|
+
end # class TestClub
|
data/test/test_import.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_import.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestImport < MiniTest::Test
|
11
|
+
|
12
|
+
def setup
|
13
|
+
SportDb.connect( adapter: 'sqlite3',
|
14
|
+
database: ':memory:' )
|
15
|
+
SportDb.create_all ## build schema
|
16
|
+
|
17
|
+
## turn on logging to console
|
18
|
+
## ActiveRecord::Base.logger = Logger.new(STDOUT)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def test_eng
|
23
|
+
## fix/todo:
|
24
|
+
## use Event.read_csv - why? why not?
|
25
|
+
## Event.parse_csv - why? why not?
|
26
|
+
|
27
|
+
headers = {
|
28
|
+
date: 'Date',
|
29
|
+
team1: 'HomeTeam',
|
30
|
+
team2: 'AwayTeam',
|
31
|
+
score1: 'FTHG',
|
32
|
+
score2: 'FTAG',
|
33
|
+
score1i: 'HTHG',
|
34
|
+
score2i: 'HTAG'
|
35
|
+
}
|
36
|
+
|
37
|
+
event_rec = CsvEventImporter.read( "#{SportDb::Test.data_dir}/england/2017-18/E0.csv",
|
38
|
+
headers: headers,
|
39
|
+
league: 'ENG', ## fetch English Premiere League
|
40
|
+
season: '2017/18'
|
41
|
+
)
|
42
|
+
|
43
|
+
assert_equal 20, event_rec.teams.count
|
44
|
+
assert_equal 380, event_rec.games.count
|
45
|
+
|
46
|
+
rec = event_rec.games.first
|
47
|
+
assert_equal 'Arsenal FC', rec.team1.name
|
48
|
+
assert_equal 'Leicester City FC', rec.team2.name
|
49
|
+
assert_equal 4, rec.score1
|
50
|
+
assert_equal 3, rec.score2
|
51
|
+
assert_equal 2, rec.score1i
|
52
|
+
assert_equal 2, rec.score2i
|
53
|
+
end
|
54
|
+
|
55
|
+
end # class TestImport
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_version.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestVersion < MiniTest::Test
|
11
|
+
|
12
|
+
def test_version
|
13
|
+
pp SportDb::Importers::VERSION
|
14
|
+
pp SportDb::Importers.banner
|
15
|
+
pp SportDb::Importers.root
|
16
|
+
|
17
|
+
assert true
|
18
|
+
end
|
19
|
+
|
20
|
+
end # class TestVersion
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sportdb-importers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sportdb-text
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sportdb-sync
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hoe
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.16'
|
69
|
+
description: sportdb-importers - tools 'n' scripts for importing sports (football)
|
70
|
+
data in alternate (text) formats incl. comma-separated values (csv) format
|
71
|
+
email: opensport@googlegroups.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- CHANGELOG.md
|
76
|
+
- Manifest.txt
|
77
|
+
- README.md
|
78
|
+
files:
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Manifest.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/sportdb/importers.rb
|
84
|
+
- lib/sportdb/importers/import.rb
|
85
|
+
- lib/sportdb/importers/version.rb
|
86
|
+
- test/helper.rb
|
87
|
+
- test/test_club.rb
|
88
|
+
- test/test_import.rb
|
89
|
+
- test/test_version.rb
|
90
|
+
homepage: https://github.com/sportdb/sport.db
|
91
|
+
licenses:
|
92
|
+
- Public Domain
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options:
|
96
|
+
- "--main"
|
97
|
+
- README.md
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 2.2.2
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.5.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: sportdb-importers - tools 'n' scripts for importing sports (football) data
|
116
|
+
in alternate (text) formats incl. comma-separated values (csv) format
|
117
|
+
test_files: []
|