sportdb 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,119 @@
1
+ # encoding: utf-8
2
+
3
+ ####################################################################
4
+ # generiert am 2012-10-28 16:08:22 +0100
5
+ # using sportdb 0.4.3 on Ruby 1.9.3 (2012-02-16) [i686-linux]
6
+ ####################################################################
7
+
8
+
9
+ ###########################################
10
+ # World Cup Quali. Europe 2012/13
11
+
12
+
13
+
14
+ ev = Event.find_by_key!( 'wmq' )
15
+
16
+ ger = Team.find_by_key!( 'ger' )
17
+ irl = Team.find_by_key!( 'irl' )
18
+ swe = Team.find_by_key!( 'swe' )
19
+ fro = Team.find_by_key!( 'fro' )
20
+ kaz = Team.find_by_key!( 'kaz' )
21
+ aut = Team.find_by_key!( 'aut' )
22
+
23
+
24
+ r01 = Round.create!( event: ev, pos: 1, title: '1. Runde', start_at: Time.utc('2012-09-07 15:00'))
25
+ r02 = Round.create!( event: ev, pos: 2, title: '2. Runde', start_at: Time.utc('2012-09-11 15:00'))
26
+ r03 = Round.create!( event: ev, pos: 3, title: '3. Runde', start_at: Time.utc('2012-10-12 20:45'))
27
+ r04 = Round.create!( event: ev, pos: 4, title: '4. Runde', start_at: Time.utc('2012-10-16 20:45'))
28
+ r05 = Round.create!( event: ev, pos: 5, title: '5. Runde', start_at: Time.utc('2013-03-22 15:00'))
29
+ r06 = Round.create!( event: ev, pos: 6, title: '6. Runde', start_at: Time.utc('2013-03-26 15:00'))
30
+ r07 = Round.create!( event: ev, pos: 7, title: '7. Runde', start_at: Time.utc('2013-06-07 15:00'))
31
+ r08 = Round.create!( event: ev, pos: 8, title: '8. Runde', start_at: Time.utc('2013-06-11 15:00'))
32
+ r09 = Round.create!( event: ev, pos: 9, title: '9. Runde', start_at: Time.utc('2013-09-06 15:00'))
33
+ r10 = Round.create!( event: ev, pos: 10, title: '10. Runde', start_at: Time.utc('2013-09-10 15:00'))
34
+ r11 = Round.create!( event: ev, pos: 11, title: '11. Runde', start_at: Time.utc('2013-10-11 15:00'))
35
+ r12 = Round.create!( event: ev, pos: 12, title: '12. Runde', start_at: Time.utc('2013-10-15 15:00'))
36
+
37
+
38
+ games01 = [
39
+ [ ger, [3,0], fro, Time.utc('2012-09-07 15:00') ],
40
+ [ kaz, [1,2], irl, Time.utc('2012-09-07 15:00') ],
41
+ ]
42
+
43
+ games02 = [
44
+ [ aut, [1,2], ger, Time.utc('2012-09-11 15:00') ],
45
+ [ swe, [2,0], kaz, Time.utc('2012-09-11 15:00') ],
46
+ ]
47
+
48
+ games03 = [
49
+ [ irl, [1,6], ger, Time.utc('2012-10-12 20:45') ],
50
+ [ fro, [1,2], swe, Time.utc('2012-10-12 18:00') ],
51
+ [ kaz, [0,0], aut, Time.utc('2012-10-12 18:00') ],
52
+ ]
53
+
54
+ games04 = [
55
+ [ ger, [4,4], swe, Time.utc('2012-10-16 20:45') ],
56
+ [ fro, [1,4], irl, Time.utc('2012-10-16 20:00') ],
57
+ [ aut, [4,0], kaz, Time.utc('2012-10-16 20:30') ],
58
+ ]
59
+
60
+ games05 = [
61
+ [ kaz, [], ger, Time.utc('2013-03-22 15:00') ],
62
+ [ aut, [], fro, Time.utc('2013-03-22 15:00') ],
63
+ [ swe, [], irl, Time.utc('2013-03-22 15:00') ],
64
+ ]
65
+
66
+ games06 = [
67
+ [ ger, [], kaz, Time.utc('2013-03-26 15:00') ],
68
+ [ irl, [], aut, Time.utc('2013-03-26 15:00') ],
69
+ ]
70
+
71
+ games07 = [
72
+ [ irl, [], fro, Time.utc('2013-06-07 15:00') ],
73
+ [ aut, [], swe, Time.utc('2013-06-07 15:00') ],
74
+ ]
75
+
76
+ games08 = [
77
+ [ swe, [], fro, Time.utc('2013-06-11 15:00') ],
78
+ ]
79
+
80
+ games09 = [
81
+ [ ger, [], aut, Time.utc('2013-09-06 15:00') ],
82
+ [ kaz, [], fro, Time.utc('2013-09-06 15:00') ],
83
+ [ irl, [], swe, Time.utc('2013-09-06 15:00') ],
84
+ ]
85
+
86
+ games10 = [
87
+ [ fro, [], ger, Time.utc('2013-09-10 15:00') ],
88
+ [ aut, [], irl, Time.utc('2013-09-10 15:00') ],
89
+ [ kaz, [], swe, Time.utc('2013-09-10 15:00') ],
90
+ ]
91
+
92
+ games11 = [
93
+ [ ger, [], irl, Time.utc('2013-10-11 15:00') ],
94
+ [ fro, [], kaz, Time.utc('2013-10-11 15:00') ],
95
+ [ swe, [], aut, Time.utc('2013-10-11 15:00') ],
96
+ ]
97
+
98
+ games12 = [
99
+ [ swe, [], ger, Time.utc('2013-10-15 15:00') ],
100
+ [ fro, [], aut, Time.utc('2013-10-15 15:00') ],
101
+ [ irl, [], kaz, Time.utc('2013-10-15 15:00') ],
102
+ ]
103
+
104
+
105
+
106
+ Game.create_from_ary!( games01, r01 )
107
+ Game.create_from_ary!( games02, r02 )
108
+ Game.create_from_ary!( games03, r03 )
109
+ Game.create_from_ary!( games04, r04 )
110
+ Game.create_from_ary!( games05, r05 )
111
+ Game.create_from_ary!( games06, r06 )
112
+ Game.create_from_ary!( games07, r07 )
113
+ Game.create_from_ary!( games08, r08 )
114
+ Game.create_from_ary!( games09, r09 )
115
+ Game.create_from_ary!( games10, r10 )
116
+ Game.create_from_ary!( games11, r11 )
117
+ Game.create_from_ary!( games12, r12 )
118
+
119
+ Prop.create!( key: 'db.wmq.fixtures.version', value: '1' )
@@ -1,114 +1,26 @@
1
1
  # encoding: utf-8
2
2
 
3
- # note: timezone for games (play_at) is *always* CET (central european time)
4
-
5
3
  ###########################################
6
4
  ## WM 2014 - Qualification Europe Group I
7
5
 
6
+ # note: for teams see seeds/euro/teams.rb
8
7
 
9
8
  world = Event.find_by_key!( 'wmq' )
10
9
 
11
- world1 = Round.find_by_event_id_and_pos!( world.id, 1 ) # 7. Sep 2012
12
- world2 = Round.find_by_event_id_and_pos!( world.id, 2 ) # 11. """"""
13
- world3 = Round.find_by_event_id_and_pos!( world.id, 3 ) # 12. Okt 2012
14
- world4 = Round.find_by_event_id_and_pos!( world.id, 4 ) # 16. """""""
15
- world5 = Round.find_by_event_id_and_pos!( world.id, 5 ) # 22. Mär 2013
16
- world6 = Round.find_by_event_id_and_pos!( world.id, 6 ) # 26. """"""
17
- world7 = Round.find_by_event_id_and_pos!( world.id, 7 ) # 7. Jun 2013
18
- world8 = Round.find_by_event_id_and_pos!( world.id, 8 ) # 11. """""""
19
- world9 = Round.find_by_event_id_and_pos!( world.id, 9 ) # 6. Sep 2013
20
- world10 = Round.find_by_event_id_and_pos!( world.id, 10 ) # 10. """""""
21
- world11 = Round.find_by_event_id_and_pos!( world.id, 11 ) # 11. Okt 2013
22
- world12 = Round.find_by_event_id_and_pos!( world.id, 12 ) # 15. """"""""
23
-
24
-
25
- #################################3
26
- # Gruppe I
27
-
28
- # note: for teams see seeds/euro/teams.rb
10
+ team_keys_worldi = [
11
+ 'fra',
12
+ 'esp',
13
+ 'blr',
14
+ 'fin',
15
+ 'geo' ]
29
16
 
30
- fra = Team.find_by_key!( 'fra' )
31
- esp = Team.find_by_key!( 'esp' )
32
- blr = Team.find_by_key!( 'blr' )
33
- fin = Team.find_by_key!( 'fin' )
34
- geo = Team.find_by_key!( 'geo' )
17
+ world.add_teams_from_ary!( team_keys_worldi )
35
18
 
36
19
 
37
20
  worldi = Group.create!( event: world, pos: 9, title: 'Gruppe I' )
38
21
 
39
- worldi.teams << fra
40
- worldi.teams << esp
41
- worldi.teams << blr
42
- worldi.teams << fin
43
- worldi.teams << geo
44
-
45
-
46
- world.teams << fra
47
- world.teams << esp
48
- world.teams << blr
49
- world.teams << fin
50
- world.teams << geo
51
-
52
-
53
-
54
-
55
- games_world1i = [
56
- [ 1, geo, [1,0], blr, Time.cet( '2012-09-07 00:00' ) ],
57
- [ 2, fin, [0,1], fra, Time.cet( '2012-09-07 00:00' ) ]]
58
-
59
- games_world2i = [
60
- [ 3, geo, [0,1], esp, Time.cet( '2012-09-11 00:00' ) ],
61
- [ 4, fra, [3,1], blr, Time.cet( '2012-09-11 00:00' ) ]]
62
-
63
- games_world3i = [
64
- [ 5, fin, [1,1], geo, Time.cet( '2012-10-12 17:30' ) ],
65
- [ 6, blr, [0,4], esp, Time.cet( '2012-10-12 20:00' ) ]]
66
-
67
- games_world4i = [
68
- [ 7, esp, [], fra, Time.cet( '2012-10-16 21:00' ) ],
69
- [ 8, blr, [], geo, Time.cet( '2012-10-16 18:00' ) ]]
70
-
71
- games_world5i = [
72
- [ 9, fra, [], geo, Time.cet( '2013-03-22 00:00' ) ],
73
- [ 10, esp, [], fin, Time.cet( '2013-03-22 00:00' ) ]]
74
-
75
- games_world6i = [
76
- [ 11, fra, [], esp, Time.cet( '2013-03-26 00:00' ) ]]
77
-
78
- games_world7i = [
79
- [ 12, fin, [], blr, Time.cet( '2013-06-07 00:00' ) ]]
80
-
81
- games_world8i = [
82
- [ 13, blr, [], fin, Time.cet( '2013-06-11 00:00' ) ]]
83
-
84
- games_world9i = [
85
- [ 14, geo, [], fra, Time.cet( '2013-09-06 00:00' ) ],
86
- [ 15, fin, [], esp, Time.cet( '2013-09-06 00:00' ) ]]
87
-
88
- games_world10i = [
89
- [ 16, blr, [], fra, Time.cet( '2013-09-10 00:00' ) ],
90
- [ 17, geo, [], fin, Time.cet( '2013-09-10 00:00' ) ]]
91
-
92
- games_world11i = [
93
- [ 18, esp, [], blr, Time.cet( '2013-10-11 00:00' ) ]]
94
-
95
- games_world12i = [
96
- [ 19, fra, [], fin, Time.cet( '2013-10-15 00:00' ) ],
97
- [ 20, esp, [], geo, Time.cet( '2013-10-15 00:00' ) ]]
98
-
22
+ worldi.add_teams_from_ary!( team_keys_worldi )
99
23
 
100
- Game.create_from_ary!( games_world1i, world1 )
101
- Game.create_from_ary!( games_world2i, world2 )
102
- Game.create_from_ary!( games_world3i, world3 )
103
- Game.create_from_ary!( games_world4i, world4 )
104
- Game.create_from_ary!( games_world5i, world5 )
105
- Game.create_from_ary!( games_world6i, world6 )
106
- Game.create_from_ary!( games_world7i, world7 )
107
- Game.create_from_ary!( games_world8i, world8 )
108
- Game.create_from_ary!( games_world9i, world9 )
109
- Game.create_from_ary!( games_world10i, world10 )
110
- Game.create_from_ary!( games_world11i, world11 )
111
- Game.create_from_ary!( games_world12i, world12 )
112
24
 
113
25
 
114
26
  Prop.create!( key: 'db.world.quali.2012/13.i.version', value: '1' )
@@ -0,0 +1,72 @@
1
+ ###########################################
2
+ ## WM 2014 - Qualification Europe Group I
3
+
4
+ # note: timezone for games (play_at) is *always* CET (central european time)
5
+
6
+
7
+ 1. Spieltag - Fr. 7. Sep 2012
8
+
9
+ (1) geo 1:0 blr 2012-09-07 15:00
10
+ (2) fin 0:1 fra 2012-09-07 15:00
11
+
12
+
13
+ 2. Spieltag - Di. 11. Sep 2012
14
+
15
+ (3) geo 0:1 esp 2012-09-11 15:00
16
+ (4) fra 3:1 blr 2012-09-11 15:00
17
+
18
+
19
+ 3. Spieltag - Fr. 12. Okt 2012
20
+
21
+ (5) fin 1:1 geo 2012-10-12 17:30
22
+ (6) blr 0:4 esp 2012-10-12 20:00
23
+
24
+
25
+ 4. Spieltag - Di. 16. Okt 2012
26
+
27
+ (7) esp 1:1 fra 2012-10-16 21:00
28
+ (8) blr 2:0 geo 2012-10-16 18:00
29
+
30
+
31
+ 5. Spieltag - Fr. 22. Mär 2013
32
+
33
+ (9) fra - geo 2013-03-22 15:00
34
+ (10) esp - fin 2013-03-22 15:00
35
+
36
+
37
+ 6. Spieltag - Di. 26. Mär 2013
38
+
39
+ (11) fra - esp 2013-03-26 15:00
40
+
41
+
42
+ 7. Spieltag - Fr. 7. Jun 2013
43
+
44
+ (12) fin - blr 2013-06-07 15:00
45
+
46
+
47
+ 8. Spieltag - Di. 11. Jun 2013
48
+
49
+ (13) blr - fin 2013-06-11 15:00
50
+
51
+
52
+ 9. Spieltag - Fr. 6. Sep 2013
53
+
54
+ (14) geo - fra 2013-09-06 15:00
55
+ (15) fin - esp 2013-09-06 15:00
56
+
57
+
58
+ 10. Spieltag - Di. 10. Sep 2013
59
+
60
+ (16) blr - fra 2013-09-10 15:00
61
+ (17) geo - fin 2013-09-10 15:00
62
+
63
+
64
+ 11. Spieltag - Fr. 11. Okt 2013
65
+
66
+ (18) esp - blr 2013-10-11 15:00
67
+
68
+
69
+ 12. Spieltag - Di. 15. Okt 2013
70
+
71
+ (19) fra - fin 2013-10-15 15:00
72
+ (20) esp - geo 2013-10-15 15:00
@@ -97,69 +97,25 @@ EOS
97
97
  SportDB.delete!
98
98
  end
99
99
 
100
- loader = nil
101
- if opts.load?
102
- loader = Loader.new
103
- end
104
-
105
100
  if opts.event.present?
106
101
  if opts.generate?
107
- Templater.new( opts ).run( args )
102
+ Templater.new( logger ).run( opts, args ) # export/generate ruby fixtures
108
103
  else
109
- Reader.new( opts ).run( args )
104
+ Reader.new( logger ).run( opts, args ) # load/read plain text fixtures
110
105
  end
111
106
  else
112
-
113
- args.each do |arg|
114
- name = arg # File.basename( arg, '.*' )
115
-
116
- if opts.load?
117
- loader.load_fixtures( name ) # load from gem (built-in)
118
- else
119
- load_fixtures( name ) # load from file system
120
- end
121
- end
122
-
123
- dump_stats
124
- dump_props
125
-
107
+ Loader.new( logger ).run( opts, args ) # load ruby fixtures
126
108
  end
127
-
128
109
 
129
110
 
111
+ dump_stats
112
+ dump_props
113
+
130
114
  puts 'Done.'
131
115
 
132
116
  end # method run
133
117
 
134
118
 
135
- def load_fixtures( name )
136
- path = "#{opts.data_path}/#{name}.rb"
137
-
138
- puts "*** loading data '#{name}' (#{path})..."
139
-
140
- text = File.read( path )
141
-
142
- # SportDB.module_eval( text )
143
-
144
- ## evaluate in class context of SportDB::Runner
145
- ## change to loader class later
146
- self.class_eval( text )
147
-
148
- # NB: same as
149
- #
150
- # module SportDB
151
- # <code here>
152
- # end
153
-
154
- # require path
155
- # require "#{Dir.pwd}/db/#{seed}.rb"
156
-
157
- # Prop.create!( :key => "db.#{name}.version", :value => SportDB::VERSION )
158
- end
159
-
160
-
161
-
162
- ##### fix/todo: reuse between runner/loader - include w/ helper module?
163
119
  def dump_stats
164
120
  # todo: use %5d or similar to format string
165
121
  puts "Stats:"
@@ -1,4 +1,3 @@
1
-
2
1
  module SportDB
3
2
 
4
3
  class Loader
@@ -8,71 +7,73 @@ class Loader
8
7
  include SportDB::Models
9
8
 
10
9
 
11
- def initialize
12
- @logger = Logger.new(STDOUT)
13
- @logger.level = Logger::INFO
14
-
10
+ def initialize( logger=nil )
11
+ if logger.nil?
12
+ @logger = Logger.new(STDOUT)
13
+ @logger.level = Logger::INFO
14
+ else
15
+ @logger = logger
16
+ end
15
17
  end
16
18
 
17
19
  attr_reader :logger
18
20
 
19
21
 
20
- def run( args )
21
-
22
- puts SportDB.banner
22
+ def run( opts, args )
23
23
 
24
- puts "working directory: #{Dir.pwd}"
25
-
26
- ## assume active activerecord connection
27
- ##
28
-
29
24
  args.each do |arg|
30
25
  name = arg # File.basename( arg, '.*' )
31
- load_fixtures( name )
26
+
27
+ if opts.load?
28
+ load_fixtures_builtin( name )
29
+ else
30
+ load_fixtures_with_include_path( name, opts.data_path )
31
+ end
32
32
  end
33
33
 
34
- dump_stats
35
- dump_props
36
-
37
- puts 'Done.'
38
-
39
- end # method run
34
+ end # method run
40
35
 
41
36
 
37
+ def load_fixtures_with_include_path( name, include_path ) # load from file system
38
+ path = "#{include_path}/#{name}.rb"
39
+
40
+ puts "*** loading data '#{name}' (#{path})..."
42
41
 
43
- def load_fixtures( name )
42
+ code = File.read( path )
44
43
 
44
+ load_fixtures_worker( code )
45
+ end
46
+
47
+ def load_fixtures_builtin( name ) # load from gem (built-in)
45
48
  path = "#{SportDB.root}/db/#{name}.rb"
46
49
 
47
50
  puts "*** loading data '#{name}' (#{path})..."
48
51
 
49
- text = File.read( path )
52
+ code = File.read( path )
53
+
54
+ load_fixtures_worker( code )
55
+ end
56
+
50
57
 
51
- self.class_eval( text )
58
+ private
59
+ def load_fixtures_worker( code )
60
+
61
+ self.class_eval( code )
52
62
 
53
63
  # NB: same as
54
64
  #
55
65
  # module SportDB
66
+ # include SportDB::Models
56
67
  # <code here>
57
68
  # end
58
- end
59
-
60
- ##### fix/todo: reuse between runner/loader - include w/ helper module?
61
- def dump_stats
62
- # todo: use %5d or similar to format string
63
- puts "Stats:"
64
- puts " #{Event.count} events"
65
- puts " #{Team.count} teams"
66
- puts " #{Game.count} games"
67
- end
69
+
70
+
71
+ # require path
72
+ # require "#{Dir.pwd}/db/#{seed}.rb"
68
73
 
69
- def dump_props
70
- # todo: use %5 or similar to format string
71
- puts "Props:"
72
- Prop.order( 'created_at asc' ).all.each do |prop|
73
- puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
74
- end
74
+ # Prop.create!( :key => "db.#{name}.version", :value => SportDB::VERSION )
75
+
75
76
  end
76
77
 
77
78
  end # class Loader
78
- end # module SportDB
79
+ end # module SportDB
@@ -18,33 +18,55 @@ class Game < ActiveRecord::Base
18
18
  end
19
19
 
20
20
  def self.create_from_ary!( games, round, knockout=false )
21
+
22
+ ### fix:
23
+ # replace knockout=false with more attribs
24
+ # see create teams and than merge attribs
25
+
21
26
  games.each_with_index do |values,index|
22
27
 
23
- ## check if first value (that is, values[0]) is a numeric/number
24
- ## if NOT add pos automatic (counting from 1 to n)
28
+ value_pos = index+1
29
+ value_scores = []
30
+ value_teams = []
31
+ value_knockout = knockout
32
+ value_play_at = round.start_at # if no date present use it from round
33
+ value_group = nil
25
34
 
26
- if values[0].kind_of? Numeric
27
- pos = values[0]
28
- offset = 1
29
- else
30
- pos = index
31
- offset = 0
32
- end
35
+ ### lets you use arguments in any order
36
+ ## makes pos optional (if not present counting from 1 to n)
33
37
 
38
+ values.each do |value|
39
+ if value.kind_of? Numeric
40
+ value_pos = value
41
+ elsif value.kind_of?( TrueClass ) || value.kind_of?( FalseClass )
42
+ value_knockout = value
43
+ elsif value.kind_of? Array
44
+ value_scores = value
45
+ elsif value.kind_of? Team
46
+ value_teams << value
47
+ elsif value.kind_of? Group
48
+ value_group = value
49
+ elsif value.kind_of?( Date ) || value.kind_of?( Time ) || value.kind_of?( DateTime )
50
+ value_play_at = value
51
+ else
52
+ # issue an error/warning here
53
+ end
54
+ end
55
+
34
56
  Game.create!(
35
57
  :round => round,
36
- :pos => pos,
37
- :team1 => values[offset],
38
- :score1 => values[offset+1][0],
39
- :score2 => values[offset+1][1],
40
- :score3 => values[offset+1][2],
41
- :score4 => values[offset+1][3],
42
- :score5 => values[offset+1][4],
43
- :score6 => values[offset+1][5],
44
- :team2 => values[offset+2],
45
- :play_at => values[offset+3],
46
- :group => values[offset+4], # Note: group is optional (may be null/nil)
47
- :knockout => knockout )
58
+ :pos => value_pos,
59
+ :team1 => value_teams[0],
60
+ :score1 => value_scores[0],
61
+ :score2 => value_scores[1],
62
+ :score3 => value_scores[2],
63
+ :score4 => value_scores[3],
64
+ :score5 => value_scores[4],
65
+ :score6 => value_scores[5],
66
+ :team2 => value_teams[1],
67
+ :play_at => value_play_at,
68
+ :group => value_group, # Note: group is optional (may be null/nil)
69
+ :knockout => value_knockout )
48
70
  end # each games
49
71
  end
50
72