sportdb 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,7 @@ db/at/2012_13/cup.rb
14
14
  db/at/2012_13/cup.txt
15
15
  db/at/2012_13/cup_fixtures.rb
16
16
  db/at/badges.rb
17
+ db/at/cities.rb
17
18
  db/at/teams.rb
18
19
  db/cities.rb
19
20
  db/cl/2011_12/cl.rb
@@ -25,6 +26,7 @@ db/countries.rb
25
26
  db/de/2012_13/bl.rb
26
27
  db/de/2012_13/bl.txt
27
28
  db/de/2012_13/bl_fixtures.rb
29
+ db/de/cities.rb
28
30
  db/de/teams.rb
29
31
  db/en/2012_13/pl.rb
30
32
  db/en/2012_13/pl.txt
@@ -66,6 +68,7 @@ lib/sportdb/models/group.rb
66
68
  lib/sportdb/models/group_team.rb
67
69
  lib/sportdb/models/league.rb
68
70
  lib/sportdb/models/prop.rb
71
+ lib/sportdb/models/region.rb
69
72
  lib/sportdb/models/round.rb
70
73
  lib/sportdb/models/season.rb
71
74
  lib/sportdb/models/team.rb
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ at = Country.find_by_key!( 'at' )
4
+
5
+
6
+ ## 9 Bundeslaender
7
+
8
+ regions_at = [
9
+ ['wien', 'Wien'], # Wien
10
+ ['noe', 'NÖ'], # Niederösterreich
11
+ ['ooe', 'OÖ'], # Oberösterreich
12
+ ['bgld', 'Bgld.'], # Burgenland
13
+ ['stmk', 'Stmk.'], # Steiermark
14
+ ['sbg', 'Sbg.'], # Salzburg
15
+ ['ktn', 'Ktn.'], # Kärnten
16
+ ['tirol', 'Tirol'], # Tirol
17
+ ['vbg', 'Vbg.'] # Vorarlberg
18
+ ]
19
+
20
+ Region.create_from_ary!( regions_at, country: at )
21
+
22
+ cities_at = [
23
+ ['wien', 'Wien|Vienna', 'region:wien'],
24
+
25
+ ['stpoelten', 'St. Pölten', 'region:noe'],
26
+ ['moedling', 'Mödling|Moedling', 'region:noe'],
27
+ ['wrneustadt', 'Wiener Neustadt|Wr. Neustadt', 'region:noe'],
28
+ ['horn', 'Horn', 'region:noe'],
29
+
30
+ ['linz', 'Linz', 'region:ooe'],
31
+ ['ried', 'Ried', 'region:ooe'],
32
+
33
+ ['mattersburg', 'Mattersburg', 'region:bgld'],
34
+
35
+ ['graz', 'Graz', 'region:stmk'],
36
+ ['hartberg', 'Hartberg', 'region:stmk'],
37
+ ['kapfenberg', 'Kapfenberg', 'region:stmk'],
38
+
39
+ ['salzburg', 'Salzburg', 'region:sbg'],
40
+ ['groedig', 'Grödig', 'region:sbg'],
41
+
42
+ ['wolfsberg', 'Wolfsberg', 'region:ktn'],
43
+
44
+ ['innsbruck', 'Innsbruck', 'region:tirol'],
45
+
46
+ ['altach', 'Altach', 'region:vbg'],
47
+ ['lustenau', 'Lustenau', 'region:vbg']
48
+ ]
49
+
50
+ City.create_from_ary!( cities_at, country: at )
51
+
52
+
53
+ Prop.create!( key: 'db.at.cities.version', value: '1' )
@@ -15,16 +15,16 @@ bl = [
15
15
  ]
16
16
 
17
17
  ersteliga = [
18
- [ 'ksv', 'Kapfenberger SV 1919', 'Erste Liga/Stmk.', 'KSV' ],
19
- [ 'altach', 'SCR Altach', 'Erste Liga/Vbg.', 'ALT' ],
20
- [ 'austrial', 'SC Austria Lustenau', 'Erste Liga/Vbg.', 'LUS' ],
21
- [ 'stpoelten', 'SKN St. Pölten', 'Erste Liga/NÖ', 'POE' ],
22
- [ 'linz', 'FC Blau-Weiß Linz', 'Erste Liga/OÖ', 'BWL' ],
23
- [ 'groedig', 'SV Grödig', 'Erste Liga/Sbg.', 'GRO' ],
24
- [ 'lustenau', 'FC Lustenau 1907|FC Lustenau', 'Erste Liga/Vbg.', 'LUS' ],
25
- [ 'vienna', 'Vienna FC 1894', 'Erste Liga/Wien', 'VIE' ],
26
- [ 'hartberg', 'TSV Hartberg', 'Erste Liga/Stmk.', 'HAR' ],
27
- [ 'horn', 'SV Horn', 'Erste Liga/NÖ', 'HOR' ]
18
+ [ 'ksv', 'Kapfenberger SV 1919', 'Erste Liga/Stmk.', 'KSV', 'city:kapfenberg'],
19
+ [ 'altach', 'SCR Altach', 'Erste Liga/Vbg.', 'ALT', 'city:altach' ],
20
+ [ 'austrial', 'SC Austria Lustenau', 'Erste Liga/Vbg.', 'LUS', 'city:lustenau' ],
21
+ [ 'stpoelten', 'SKN St. Pölten', 'Erste Liga/NÖ', 'POE', 'city:stpoelten' ],
22
+ [ 'linz', 'FC Blau-Weiß Linz', 'Erste Liga/OÖ', 'BWL', 'city:linz' ],
23
+ [ 'groedig', 'SV Grödig', 'Erste Liga/Sbg.', 'GRO', 'city:groedig' ],
24
+ [ 'lustenau', 'FC Lustenau 1907|FC Lustenau', 'Erste Liga/Vbg.', 'LUS', 'city:lustenau' ],
25
+ [ 'vienna', 'Vienna FC 1894', 'Erste Liga/Wien', 'VIE', 'city:wien' ],
26
+ [ 'hartberg', 'TSV Hartberg', 'Erste Liga/Stmk.', 'HAR', 'city:hartberg' ],
27
+ [ 'horn', 'SV Horn', 'Erste Liga/NÖ', 'HOR', 'city:horn' ]
28
28
  ]
29
29
 
30
30
  rlwest = [
@@ -1,26 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
 
4
-
5
- ### todo/fix: add regions (Stmk., NOE, OOE, etc,)
6
-
7
- cities_at = [
8
- ['wien', 'Wien|Vienna'],
9
- ['innsbruck', 'Innsbruck'],
10
- ['moedling', 'Mödling|Moedling'],
11
- ['salzburg', 'Salzburg'],
12
- ['graz', 'Graz'],
13
- ['linz', 'Linz'],
14
- ['mattersburg', 'Mattersburg'],
15
- ['ried', 'Ried'],
16
- ['wrneustadt', 'Wiener Neustadt|Wr. Neustadt'],
17
- ['wolfsberg', 'Wolfsberg']
18
- ]
19
-
20
- at = Country.find_by_key!( 'at' )
21
- City.create_from_ary!( cities_at, country: at )
22
-
23
-
24
4
  cities_en = [
25
5
  ['manchester', 'Manchester'],
26
6
  ['london', 'London'],
@@ -41,31 +21,6 @@ en = Country.find_by_key!( 'en' )
41
21
  City.create_from_ary!( cities_en, country: en )
42
22
 
43
23
 
44
- cities_de = [
45
- ['hoffenheim', 'Hoffenheim'],
46
- ['nuernberg', 'Nürnberg'],
47
- ['stuttgart', 'Stuttgart'],
48
- ['augsburg', 'Augsburg'],
49
- ['wolfsburg', 'Wolfsburg'],
50
- ['fuerth', 'Fürth'],
51
- ['muenchen', 'München'],
52
- ['gelsenkirchen', 'Gelsenkirchen'],
53
- ['dortmund', 'Dortmund'],
54
- ['frankfurt', 'Frankfurt'],
55
- ['hannover', 'Hannover'],
56
- ['leverkusen', 'Leverkusen'],
57
- ['duesseldorf', 'Düsseldorf'],
58
- ['hamburg', 'Hamburg'],
59
- ['mainz', 'Mainz'],
60
- ['mgladbach', "Mönchengladbach|M'gladbach" ],
61
- ['freiburg', 'Freiburg'],
62
- ['bremen', 'Bremen']
63
- ]
64
-
65
- de = Country.find_by_key!( 'de' )
66
- City.create_from_ary!( cities_de, country: de )
67
-
68
-
69
24
  cities_es = [
70
25
  ['bilbao', 'Bilbao'],
71
26
  ['valencia', 'Valencia'],
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ de = Country.find_by_key!( 'de' )
4
+
5
+ cities_de = [
6
+ ['hoffenheim', 'Hoffenheim'],
7
+ ['nuernberg', 'Nürnberg'],
8
+ ['stuttgart', 'Stuttgart'],
9
+ ['augsburg', 'Augsburg'],
10
+ ['wolfsburg', 'Wolfsburg'],
11
+ ['fuerth', 'Fürth'],
12
+ ['muenchen', 'München'],
13
+ ['gelsenkirchen', 'Gelsenkirchen'],
14
+ ['dortmund', 'Dortmund'],
15
+ ['frankfurt', 'Frankfurt'],
16
+ ['hannover', 'Hannover'],
17
+ ['leverkusen', 'Leverkusen'],
18
+ ['duesseldorf', 'Düsseldorf'],
19
+ ['hamburg', 'Hamburg'],
20
+ ['mainz', 'Mainz'],
21
+ ['mgladbach', "Mönchengladbach|M'gladbach" ],
22
+ ['freiburg', 'Freiburg'],
23
+ ['bremen', 'Bremen']
24
+ ]
25
+
26
+ City.create_from_ary!( cities_de, country: de )
27
+
28
+
29
+ Prop.create!( key: 'db.de.cities.version', value: '1' )
@@ -1,24 +1,48 @@
1
1
  # encoding: utf-8
2
2
 
3
- League.create!( key: 'at', title: 'Österr. Bundesliga', club: true )
4
- League.create!( key: 'at.cup', title: 'ÖFB Cup', club: true )
3
+ #############################
4
+ ## national leagues & cups
5
5
 
6
- League.create!( key: 'cl', title: 'Champions League', club: true )
7
- League.create!( key: 'el', title: 'Europa League', club: true )
6
+ at = Country.find_by_key!( 'at' )
7
+ de = Country.find_by_key!( 'de' )
8
+ en = Country.find_by_key!( 'en' )
9
+ ro = Country.find_by_key!( 'ro' )
10
+ mx = Country.find_by_key!( 'mx' )
8
11
 
9
- League.create!( key: 'de', title: 'Deutsche Bundesliga', club: true )
10
- League.create!( key: 'en', title: 'English Premier League', club: true )
11
- League.create!( key: 'ro', title: 'Romania Liga 1', club: true )
12
12
 
13
- League.create!( key: 'mx.apertura', title: 'México Primera División Apertura', club: true )
13
+ leagues_club = [
14
+ [ 'at', 'Österr. Bundesliga', at ],
15
+ [ 'at.cup', 'ÖFB Cup', at ],
16
+ [ 'de', 'Deutsche Bundesliga', de ],
17
+ [ 'en', 'English Premier League', en ],
18
+ [ 'ro', 'Romania Liga 1', ro ],
19
+ [ 'mx.apertura', 'México Primera División Apertura', mx ]
20
+ ]
14
21
 
22
+ League.create_from_ary!( leagues_club, club: true )
15
23
 
16
24
 
17
- League.create!( key: 'euro', title: 'Euro', club: false )
25
+ ########################################
26
+ ## international leagues w/ football clubs teams
18
27
 
19
- League.create!( key: 'wm', title: 'World Cup', club: false ) ## change key to world??
20
- League.create!( key: 'wmq', title: 'World Cup Quali', club: false )
28
+ leagues_club_intl = [
29
+ [ 'cl', 'Champions League' ],
30
+ [ 'el', 'Europa League' ]
31
+ ]
21
32
 
33
+ League.create_from_ary!( leagues_club_intl, club: true )
34
+
35
+
36
+ #######################################
37
+ ## internationl tournaments & cups w/ national teams
38
+
39
+ leagues_intl = [
40
+ [ 'euro', 'Euro' ],
41
+ [ 'wm', 'World Cup' ], ## change key to world??
42
+ [ 'wmq', 'World Cup Quali' ]
43
+ ]
44
+
45
+ League.create_from_ary!( leagues_intl, club: false )
22
46
 
23
47
 
24
48
 
@@ -34,6 +34,7 @@ require 'sportdb/models/group'
34
34
  require 'sportdb/models/group_team'
35
35
  require 'sportdb/models/league'
36
36
  require 'sportdb/models/prop'
37
+ require 'sportdb/models/region'
37
38
  require 'sportdb/models/round'
38
39
  require 'sportdb/models/season'
39
40
  require 'sportdb/models/team'
@@ -101,6 +102,7 @@ module SportDB
101
102
  Round.delete_all
102
103
  Prop.delete_all
103
104
  Country.delete_all
105
+ Region.delete_all
104
106
  City.delete_all
105
107
  Badge.delete_all
106
108
  League.delete_all
@@ -121,7 +121,7 @@ EOS
121
121
  puts "Stats:"
122
122
  puts " #{Event.count} events / #{Round.count} rounds / #{Group.count} groups"
123
123
  puts " #{League.count} leagues / #{Season.count} seasons"
124
- puts " #{Country.count} countries / #{City.count} cities"
124
+ puts " #{Country.count} countries / #{Region.count} regions / #{City.count} cities"
125
125
  puts " #{Team.count} teams"
126
126
  puts " #{Game.count} games"
127
127
  puts " #{Badge.count} badges"
@@ -4,6 +4,7 @@ class City < ActiveRecord::Base
4
4
  self.table_name = 'cities'
5
5
 
6
6
  belongs_to :country, :class_name => 'Country', :foreign_key => 'country_id'
7
+ belongs_to :region, :class_name => 'Region', :foreign_key => 'country_id'
7
8
 
8
9
  has_many :teams, :class_name => 'Team', :foreign_key => 'city_id'
9
10
 
@@ -11,8 +12,6 @@ class City < ActiveRecord::Base
11
12
  def self.create_from_ary!( cities, more_values={} )
12
13
  cities.each do |values|
13
14
 
14
- ## todo/fix: split optional synonyms from title (see team for example)
15
-
16
15
  ## key & title & country required
17
16
  attr = {
18
17
  key: values[0]
@@ -32,6 +31,10 @@ class City < ActiveRecord::Base
32
31
  values[2..-1].each do |value|
33
32
  if value.is_a? Country
34
33
  attr[ :country_id ] = value.id
34
+ elsif value =~ /^region:/ ## region:
35
+ value_region_key = value[7..-1] ## cut off region: prefix
36
+ value_region = Region.find_by_key!( value_region_key )
37
+ attr[ :region_id ] = value_region.id
35
38
  else
36
39
  # issue warning: unknown type for value
37
40
  end
@@ -4,8 +4,10 @@ module SportDB::Models
4
4
  class Country < ActiveRecord::Base
5
5
  self.table_name = 'countries'
6
6
 
7
- has_many :cities, :class_name => 'City', :foreign_key => 'country_id'
8
- has_many :teams, :class_name => 'Team', :foreign_key => 'country_id'
7
+ has_many :regions, :class_name => 'Region', :foreign_key => 'country_id'
8
+ has_many :cities, :class_name => 'City', :foreign_key => 'country_id'
9
+ has_many :teams, :class_name => 'Team', :foreign_key => 'country_id'
10
+ has_many :leagues, :class_name => 'League', :foreign_key => 'country_id'
9
11
 
10
12
  def self.create_from_ary!( countries )
11
13
  countries.each do |values|
@@ -6,6 +6,7 @@ class Event < ActiveRecord::Base
6
6
  belongs_to :season
7
7
 
8
8
  has_many :rounds, :order => 'pos' # all (fix and flex) rounds
9
+ has_many :games, :through => :rounds
9
10
 
10
11
  has_many :groups, :order => 'pos'
11
12
 
@@ -8,8 +8,32 @@ class League < ActiveRecord::Base
8
8
  ## league (cup/conference/series/etc.) + season (year) = event
9
9
 
10
10
  has_many :events
11
-
12
- ### has_many :seasons ## through events add
11
+ has_many :seasons, :through => :events
12
+
13
+
14
+ def self.create_from_ary!( leagues, more_values={} )
15
+ leagues.each do |values|
16
+
17
+ ## key & title required
18
+ attr = {
19
+ key: values[0],
20
+ title: values[1]
21
+ }
22
+
23
+ attr = attr.merge( more_values )
24
+
25
+ ## check for optional values
26
+ values[2..-1].each do |value|
27
+ if value.is_a? Country
28
+ attr[ :country_id ] = value.id
29
+ else
30
+ # issue warning: unknown type for value
31
+ end
32
+ end
33
+
34
+ League.create!( attr )
35
+ end # each league
36
+ end
13
37
 
14
38
  end # class League
15
39
 
@@ -0,0 +1,38 @@
1
+ module SportDB::Models
2
+
3
+ class Region < ActiveRecord::Base
4
+
5
+ belongs_to :country, :class_name => 'Country', :foreign_key => 'country_id'
6
+
7
+ has_many :cities, :class_name => 'City', :foreign_key => 'region_id'
8
+ has_many :teams, :through => :cities
9
+
10
+
11
+ def self.create_from_ary!( regions, more_values={} )
12
+ regions.each do |values|
13
+
14
+ ## key & title & country required
15
+ attr = {
16
+ key: values[0],
17
+ title: values[1]
18
+ }
19
+
20
+ attr = attr.merge( more_values )
21
+
22
+ ## check for optional values
23
+ values[2..-1].each do |value|
24
+ if value.is_a? Country
25
+ attr[ :country_id ] = value.id
26
+ else
27
+ # issue warning: unknown type for value
28
+ end
29
+ end
30
+
31
+ Region.create!( attr )
32
+ end # each region
33
+ end
34
+
35
+ end # class Region
36
+
37
+
38
+ end # module Models::SportDB
@@ -20,11 +20,19 @@ create_table :countries do |t|
20
20
  t.timestamps
21
21
  end
22
22
 
23
+ create_table :regions do |t|
24
+ t.string :title, :null => false
25
+ t.string :key, :null => false
26
+ t.references :country, :null => false
27
+ t.timestamps
28
+ end
29
+
23
30
  create_table :cities do |t|
24
31
  t.string :title, :null => false
25
32
  t.string :key, :null => false
26
33
  t.string :synonyms # comma separated list of synonyms
27
34
  t.references :country, :null => false
35
+ t.references :region # optional for now
28
36
  t.timestamps
29
37
  end
30
38
 
@@ -149,10 +157,10 @@ create_table :seasons do |t| ## also used for years
149
157
  end
150
158
 
151
159
  create_table :leagues do |t| ## also for cups/conferences/tournaments/world series/etc.
152
- t.string :key, :null => false
153
- t.string :title, :null => false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
154
- ## t.references :country, :null => false ### todo: create "virtual" country for international leagues e.g. use int? or world (ww?)/europe (eu)/etc. similar? already taken??
155
- t.boolean :club, :null => false, :default => false # club teams or national teams?
160
+ t.string :key, :null => false
161
+ t.string :title, :null => false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
162
+ t.references :country ## optional for now , :null => false ### todo: create "virtual" country for international leagues e.g. use int? or world (ww?)/europe (eu)/etc. similar? already taken??
163
+ t.boolean :club, :null => false, :default => false # club teams or national teams?
156
164
  ## todo: add t.boolean :national flag? for national teams?
157
165
  ## t.boolean :international, :null => false, :default => false # national league or international?
158
166
  ## t.boolean :cup ## or regular season league??
@@ -1,4 +1,4 @@
1
1
 
2
2
  module SportDB
3
- VERSION = '0.5.3'
3
+ VERSION = '0.5.4'
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 3
10
- version: 0.5.3
9
+ - 4
10
+ version: 0.5.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer
@@ -97,6 +97,7 @@ files:
97
97
  - db/at/2012_13/cup.txt
98
98
  - db/at/2012_13/cup_fixtures.rb
99
99
  - db/at/badges.rb
100
+ - db/at/cities.rb
100
101
  - db/at/teams.rb
101
102
  - db/cities.rb
102
103
  - db/cl/2011_12/cl.rb
@@ -108,6 +109,7 @@ files:
108
109
  - db/de/2012_13/bl.rb
109
110
  - db/de/2012_13/bl.txt
110
111
  - db/de/2012_13/bl_fixtures.rb
112
+ - db/de/cities.rb
111
113
  - db/de/teams.rb
112
114
  - db/en/2012_13/pl.rb
113
115
  - db/en/2012_13/pl.txt
@@ -149,6 +151,7 @@ files:
149
151
  - lib/sportdb/models/group_team.rb
150
152
  - lib/sportdb/models/league.rb
151
153
  - lib/sportdb/models/prop.rb
154
+ - lib/sportdb/models/region.rb
152
155
  - lib/sportdb/models/round.rb
153
156
  - lib/sportdb/models/season.rb
154
157
  - lib/sportdb/models/team.rb