sportdb 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.markdown +5 -0
- data/Manifest.txt +19 -1
- data/Rakefile +14 -5
- data/db/at/2011_12/bl.rb +52 -53
- data/db/at/2011_12/cup.rb +14 -12
- data/db/at/2012_13/bl.rb +127 -125
- data/db/at/2012_13/cup.rb +66 -66
- data/db/at/teams.rb +3 -9
- data/db/cl/2011_12/cl.rb +11 -12
- data/db/cl/2011_12/el.rb +9 -9
- data/db/cl/2012_13/cl.rb +25 -25
- data/db/cl/teams.rb +80 -55
- data/db/countries.rb +70 -0
- data/db/de/2012_13/bl.rb +175 -0
- data/db/de/teams.rb +36 -0
- data/db/en/2012_13/pl.rb +9 -0
- data/db/en/teams.rb +40 -0
- data/db/euro/2012.rb +14 -14
- data/db/euro/teams.rb +52 -22
- data/db/mx/apertura_2012.rb +84 -84
- data/db/mx/teams.rb +4 -2
- data/db/nhl/teams.rb +50 -0
- data/db/ro/l1_2012_13.rb +134 -0
- data/db/ro/teams.rb +31 -0
- data/db/world/quali_2012_13.rb +17 -92
- data/db/world/quali_2012_13_c.rb +127 -0
- data/db/world/quali_2012_13_i.rb +114 -0
- data/lib/sportdb.rb +34 -10
- data/lib/sportdb/cli/runner.rb +12 -2
- data/lib/sportdb/loader.rb +6 -1
- data/lib/sportdb/models/country.rb +26 -0
- data/lib/sportdb/models/event.rb +19 -0
- data/lib/sportdb/models/event_team.rb +14 -0
- data/lib/sportdb/{models.rb → models/game.rb} +141 -215
- data/lib/sportdb/models/group.rb +18 -0
- data/lib/sportdb/models/group_team.rb +15 -0
- data/lib/sportdb/models/prop.rb +12 -0
- data/lib/sportdb/models/round.rb +15 -0
- data/lib/sportdb/models/team.rb +49 -0
- data/lib/sportdb/schema.rb +22 -5
- data/lib/sportdb/version.rb +1 -1
- metadata +67 -10
@@ -0,0 +1,127 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# note: timezone for games (play_at) is *always* CET (central european time)
|
4
|
+
|
5
|
+
###########################################
|
6
|
+
## WM 2014 - Qualification Europe Group C
|
7
|
+
|
8
|
+
world = Event.find_by_key!( 'wmq' )
|
9
|
+
|
10
|
+
world1 = Round.find_by_event_id_and_pos!( world.id, 1 ) # 7. Sep 2012
|
11
|
+
world2 = Round.find_by_event_id_and_pos!( world.id, 2 ) # 11. """"""
|
12
|
+
world3 = Round.find_by_event_id_and_pos!( world.id, 3 ) # 12. Okt 2012
|
13
|
+
world4 = Round.find_by_event_id_and_pos!( world.id, 4 ) # 16. """""""
|
14
|
+
world5 = Round.find_by_event_id_and_pos!( world.id, 5 ) # 22. Mär 2013
|
15
|
+
world6 = Round.find_by_event_id_and_pos!( world.id, 6 ) # 26. """"""
|
16
|
+
world7 = Round.find_by_event_id_and_pos!( world.id, 7 ) # 7. Jun 2013
|
17
|
+
world8 = Round.find_by_event_id_and_pos!( world.id, 8 ) # 11. """""""
|
18
|
+
world9 = Round.find_by_event_id_and_pos!( world.id, 9 ) # 6. Sep 2013
|
19
|
+
world10 = Round.find_by_event_id_and_pos!( world.id, 10 ) # 10. """""""
|
20
|
+
world11 = Round.find_by_event_id_and_pos!( world.id, 11 ) # 11. Okt 2013
|
21
|
+
world12 = Round.find_by_event_id_and_pos!( world.id, 12 ) # 15. """"""""
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
#################################3
|
27
|
+
# Gruppe C
|
28
|
+
|
29
|
+
# note: for teams see seeds/euro/teams.rb
|
30
|
+
|
31
|
+
ger = Team.find_by_key!( 'ger' )
|
32
|
+
fro = Team.find_by_key!( 'fro' )
|
33
|
+
irl = Team.find_by_key!( 'irl' )
|
34
|
+
kaz = Team.find_by_key!( 'kaz' )
|
35
|
+
aut = Team.find_by_key!( 'aut' )
|
36
|
+
swe = Team.find_by_key!( 'swe' )
|
37
|
+
|
38
|
+
|
39
|
+
worldc = Group.create!( event: world, pos: 3, title: 'Gruppe C' )
|
40
|
+
|
41
|
+
worldc.teams << ger
|
42
|
+
worldc.teams << fro
|
43
|
+
worldc.teams << irl
|
44
|
+
worldc.teams << kaz
|
45
|
+
worldc.teams << aut
|
46
|
+
worldc.teams << swe
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
world.teams << ger
|
51
|
+
world.teams << fro
|
52
|
+
world.teams << irl
|
53
|
+
world.teams << kaz
|
54
|
+
world.teams << aut
|
55
|
+
world.teams << swe
|
56
|
+
|
57
|
+
|
58
|
+
games_world1c = [
|
59
|
+
[ 1, ger, [3,0], fro, Time.cet( '2012-09-07 00:00' ) ],
|
60
|
+
[ 2, kaz, [1,2], irl, Time.cet( '2012-09-07 00:00' ) ]]
|
61
|
+
|
62
|
+
games_world2c = [
|
63
|
+
[ 3, aut, [1,2], ger, Time.cet( '2012-09-11 00:00' ) ],
|
64
|
+
[ 4, swe, [2,0], kaz, Time.cet( '2012-09-11 00:00' ) ]]
|
65
|
+
|
66
|
+
games_world3c = [
|
67
|
+
[ 5, irl, [1,6], ger, Time.cet( '2012-10-12 20:45' ) ],
|
68
|
+
[ 6, fro, [1,2], swe, Time.cet( '2012-10-12 18:00' ) ],
|
69
|
+
[ 7, kaz, [0,0], aut, Time.cet( '2012-10-12 18:00' ) ]]
|
70
|
+
|
71
|
+
games_world4c = [
|
72
|
+
[ 8, ger, [], swe, Time.cet( '2012-10-16 20:45' ) ],
|
73
|
+
[ 9, fro, [], irl, Time.cet( '2012-10-16 20:00' ) ],
|
74
|
+
[ 10, aut, [], kaz, Time.cet( '2012-10-16 20:30' ) ]]
|
75
|
+
|
76
|
+
games_world5c = [
|
77
|
+
[ 11, kaz, [], ger, Time.cet( '2013-03-22 00:00' ) ],
|
78
|
+
[ 12, aut, [], fro, Time.cet( '2013-03-22 00:00' ) ],
|
79
|
+
[ 13, swe, [], irl, Time.cet( '2013-03-22 00:00' ) ]]
|
80
|
+
|
81
|
+
games_world6c = [
|
82
|
+
[ 14, ger, [], kaz, Time.cet( '2013-03-26 00:00' ) ],
|
83
|
+
[ 15, irl, [], aut, Time.cet( '2013-03-26 00:00' ) ]]
|
84
|
+
|
85
|
+
games_world7c = [
|
86
|
+
[ 16, irl, [], fro, Time.cet( '2013-06-07 00:00' ) ],
|
87
|
+
[ 17, aut, [], swe, Time.cet( '2013-06-07 00:00' ) ]]
|
88
|
+
|
89
|
+
games_world8c = [
|
90
|
+
[ 18, swe, [], fro, Time.cet( '2013-06-11 00:00' ) ]]
|
91
|
+
|
92
|
+
games_world9c = [
|
93
|
+
[ 19, ger, [], aut, Time.cet( '2013-09-06 00:00' ) ],
|
94
|
+
[ 20, kaz, [], fro, Time.cet( '2013-09-06 00:00' ) ],
|
95
|
+
[ 21, irl, [], swe, Time.cet( '2013-09-06 00:00' ) ]]
|
96
|
+
|
97
|
+
games_world10c = [
|
98
|
+
[ 22, fro, [], ger, Time.cet( '2013-09-10 00:00' ) ],
|
99
|
+
[ 23, aut, [], irl, Time.cet( '2013-09-10 00:00' ) ],
|
100
|
+
[ 24, kaz, [], swe, Time.cet( '2013-09-10 00:00' ) ]]
|
101
|
+
|
102
|
+
games_world11c = [
|
103
|
+
[ 25, ger, [], irl, Time.cet( '2013-10-11 00:00' ) ],
|
104
|
+
[ 26, fro, [], kaz, Time.cet( '2013-10-11 00:00' ) ],
|
105
|
+
[ 27, swe, [], aut, Time.cet( '2013-10-11 00:00' ) ]]
|
106
|
+
|
107
|
+
games_world12c = [
|
108
|
+
[ 28, swe, [], ger, Time.cet( '2013-10-15 00:00' ) ],
|
109
|
+
[ 29, fro, [], aut, Time.cet( '2013-10-15 00:00' ) ],
|
110
|
+
[ 30, irl, [], kaz, Time.cet( '2013-10-15 00:00' ) ]]
|
111
|
+
|
112
|
+
|
113
|
+
Game.create_from_ary!( games_world1c, world1 )
|
114
|
+
Game.create_from_ary!( games_world2c, world2 )
|
115
|
+
Game.create_from_ary!( games_world3c, world3 )
|
116
|
+
Game.create_from_ary!( games_world4c, world4 )
|
117
|
+
Game.create_from_ary!( games_world5c, world5 )
|
118
|
+
Game.create_from_ary!( games_world6c, world6 )
|
119
|
+
Game.create_from_ary!( games_world7c, world7 )
|
120
|
+
Game.create_from_ary!( games_world8c, world8 )
|
121
|
+
Game.create_from_ary!( games_world9c, world9 )
|
122
|
+
Game.create_from_ary!( games_world10c, world10 )
|
123
|
+
Game.create_from_ary!( games_world11c, world11 )
|
124
|
+
Game.create_from_ary!( games_world12c, world12 )
|
125
|
+
|
126
|
+
|
127
|
+
Prop.create!( key: 'db.world.quali.2012/13.c.version', value: '1' )
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# note: timezone for games (play_at) is *always* CET (central european time)
|
4
|
+
|
5
|
+
###########################################
|
6
|
+
## WM 2014 - Qualification Europe Group I
|
7
|
+
|
8
|
+
|
9
|
+
world = Event.find_by_key!( 'wmq' )
|
10
|
+
|
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
|
29
|
+
|
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' )
|
35
|
+
|
36
|
+
|
37
|
+
worldi = Group.create!( event: world, pos: 9, title: 'Gruppe I' )
|
38
|
+
|
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
|
+
|
99
|
+
|
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
|
+
|
113
|
+
|
114
|
+
Prop.create!( key: 'db.world.quali.2012/13.i.version', value: '1' )
|
data/lib/sportdb.rb
CHANGED
@@ -19,8 +19,16 @@ require 'active_record' ## todo: add sqlite3? etc.
|
|
19
19
|
|
20
20
|
# our own code
|
21
21
|
|
22
|
-
require 'sportdb/
|
23
|
-
require 'sportdb/models'
|
22
|
+
require 'sportdb/models/country'
|
23
|
+
require 'sportdb/models/event'
|
24
|
+
require 'sportdb/models/event_team'
|
25
|
+
require 'sportdb/models/game'
|
26
|
+
require 'sportdb/models/group'
|
27
|
+
require 'sportdb/models/group_team'
|
28
|
+
require 'sportdb/models/prop'
|
29
|
+
require 'sportdb/models/round'
|
30
|
+
require 'sportdb/models/team'
|
31
|
+
require 'sportdb/schema' # NB: requires sportdb/models (include SportDB::Models)
|
24
32
|
require 'sportdb/utils'
|
25
33
|
require 'sportdb/loader'
|
26
34
|
require 'sportdb/version'
|
@@ -50,16 +58,32 @@ module SportDB
|
|
50
58
|
end
|
51
59
|
|
52
60
|
|
61
|
+
class Deleter
|
62
|
+
## todo: move into its own file???
|
63
|
+
|
64
|
+
## make models available in sportdb module by default with namespace
|
65
|
+
# e.g. lets you use Team instead of Models::Team
|
66
|
+
include SportDB::Models
|
67
|
+
|
68
|
+
def run( args=[] )
|
69
|
+
# for now delete all tables
|
70
|
+
|
71
|
+
Team.delete_all
|
72
|
+
Game.delete_all
|
73
|
+
Event.delete_all
|
74
|
+
EventTeam.delete_all
|
75
|
+
Group.delete_all
|
76
|
+
GroupTeam.delete_all
|
77
|
+
Round.delete_all
|
78
|
+
Prop.delete_all
|
79
|
+
Country.delete_all
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
53
84
|
# delete ALL records (use with care!)
|
54
85
|
def self.delete!
|
55
|
-
|
56
|
-
Game.delete_all
|
57
|
-
Event.delete_all
|
58
|
-
EventTeam.delete_all
|
59
|
-
Group.delete_all
|
60
|
-
GroupTeam.delete_all
|
61
|
-
Round.delete_all
|
62
|
-
Prop.delete_all
|
86
|
+
Deleter.new.run
|
63
87
|
end # method delete!
|
64
88
|
|
65
89
|
end # module SportDB
|
data/lib/sportdb/cli/runner.rb
CHANGED
@@ -3,6 +3,11 @@ module SportDB
|
|
3
3
|
|
4
4
|
class Runner
|
5
5
|
|
6
|
+
|
7
|
+
## make models available in sportdb module by default with namespace
|
8
|
+
# e.g. lets you use Team instead of Models::Team
|
9
|
+
include SportDB::Models
|
10
|
+
|
6
11
|
def initialize
|
7
12
|
@logger = Logger.new(STDOUT)
|
8
13
|
@logger.level = Logger::INFO
|
@@ -39,7 +44,7 @@ class Runner
|
|
39
44
|
logger.datetime_format = "%H:%H:%S"
|
40
45
|
logger.level = Logger::DEBUG
|
41
46
|
|
42
|
-
|
47
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
43
48
|
end
|
44
49
|
|
45
50
|
cmd.on_tail( "-h", "--help", "Show this message" ) do
|
@@ -119,7 +124,11 @@ EOS
|
|
119
124
|
|
120
125
|
text = File.read( path )
|
121
126
|
|
122
|
-
SportDB.module_eval( text )
|
127
|
+
# SportDB.module_eval( text )
|
128
|
+
|
129
|
+
## evaluate in class context of SportDB::Runner
|
130
|
+
## change to loader class later
|
131
|
+
self.class_eval( text )
|
123
132
|
|
124
133
|
# NB: same as
|
125
134
|
#
|
@@ -141,6 +150,7 @@ EOS
|
|
141
150
|
puts "Stats:"
|
142
151
|
puts " #{Event.count} events"
|
143
152
|
puts " #{Team.count} teams"
|
153
|
+
puts " #{Country.count} countries"
|
144
154
|
puts " #{Game.count} games"
|
145
155
|
end
|
146
156
|
|
data/lib/sportdb/loader.rb
CHANGED
@@ -3,6 +3,11 @@ module SportDB
|
|
3
3
|
|
4
4
|
class Loader
|
5
5
|
|
6
|
+
## make models available in sportdb module by default with namespace
|
7
|
+
# e.g. lets you use Team instead of Models::Team
|
8
|
+
include SportDB::Models
|
9
|
+
|
10
|
+
|
6
11
|
def initialize
|
7
12
|
@logger = Logger.new(STDOUT)
|
8
13
|
@logger.level = Logger::INFO
|
@@ -43,7 +48,7 @@ class Loader
|
|
43
48
|
|
44
49
|
text = File.read( path )
|
45
50
|
|
46
|
-
|
51
|
+
self.class_eval( text )
|
47
52
|
|
48
53
|
# NB: same as
|
49
54
|
#
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SportDB
|
2
|
+
module Models
|
3
|
+
|
4
|
+
|
5
|
+
class Country < ActiveRecord::Base
|
6
|
+
self.table_name = 'countries'
|
7
|
+
|
8
|
+
def self.create_from_ary!( countries )
|
9
|
+
countries.each do |values|
|
10
|
+
|
11
|
+
## key & title required
|
12
|
+
attr = {
|
13
|
+
:key => values[0],
|
14
|
+
:title => values[1],
|
15
|
+
:tag => values[2]
|
16
|
+
}
|
17
|
+
|
18
|
+
Country.create!( attr )
|
19
|
+
end # each country
|
20
|
+
end
|
21
|
+
|
22
|
+
end # class Country
|
23
|
+
|
24
|
+
|
25
|
+
end # module Models
|
26
|
+
end # module SportDB
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SportDB
|
2
|
+
module Models
|
3
|
+
|
4
|
+
|
5
|
+
class Event < ActiveRecord::Base
|
6
|
+
|
7
|
+
has_many :rounds, :order => 'pos' # all (fix and flex) rounds
|
8
|
+
|
9
|
+
has_many :groups, :order => 'pos'
|
10
|
+
|
11
|
+
has_many :event_teams, :class_name => 'EventTeam'
|
12
|
+
has_many :teams, :through => :event_teams
|
13
|
+
|
14
|
+
end # class Event
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
end # module Models
|
19
|
+
end # module SportDB
|
@@ -1,215 +1,141 @@
|
|
1
|
-
module SportDB
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
:
|
62
|
-
:
|
63
|
-
|
64
|
-
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:team2 =>
|
71
|
-
:play_at =>
|
72
|
-
:group =>
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
game1.next_game_id = game2.id
|
143
|
-
game1.save!
|
144
|
-
|
145
|
-
game2.prev_game_id = game1.id
|
146
|
-
game2.save!
|
147
|
-
end # each pair
|
148
|
-
end
|
149
|
-
|
150
|
-
def calc_toto12x
|
151
|
-
if score1.nil? || score2.nil?
|
152
|
-
self.toto12x = nil
|
153
|
-
elsif score1 == score2
|
154
|
-
self.toto12x = 'X'
|
155
|
-
elsif score1 > score2
|
156
|
-
self.toto12x = '1'
|
157
|
-
elsif score1 < score2
|
158
|
-
self.toto12x = '2'
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
end # class Game
|
163
|
-
|
164
|
-
|
165
|
-
class Event < ActiveRecord::Base
|
166
|
-
|
167
|
-
has_many :rounds, :order => 'pos' # all (fix and flex) rounds
|
168
|
-
|
169
|
-
has_many :groups, :order => 'pos'
|
170
|
-
|
171
|
-
has_many :event_teams, :class_name => 'EventTeam'
|
172
|
-
has_many :teams, :through => :event_teams
|
173
|
-
|
174
|
-
end # class Event
|
175
|
-
|
176
|
-
|
177
|
-
class EventTeam < ActiveRecord::Base
|
178
|
-
self.table_name = 'events_teams'
|
179
|
-
|
180
|
-
belongs_to :event
|
181
|
-
belongs_to :team
|
182
|
-
end
|
183
|
-
|
184
|
-
class Group < ActiveRecord::Base
|
185
|
-
|
186
|
-
has_many :games, :order => 'pos'
|
187
|
-
belongs_to :event
|
188
|
-
|
189
|
-
has_many :group_teams, :class_name => 'GroupTeam'
|
190
|
-
has_many :teams, :through => :group_teams
|
191
|
-
|
192
|
-
end # class Group
|
193
|
-
|
194
|
-
class GroupTeam < ActiveRecord::Base
|
195
|
-
self.table_name = 'groups_teams'
|
196
|
-
|
197
|
-
belongs_to :group
|
198
|
-
belongs_to :team
|
199
|
-
end
|
200
|
-
|
201
|
-
|
202
|
-
class Round < ActiveRecord::Base
|
203
|
-
|
204
|
-
has_many :games, :order => 'pos'
|
205
|
-
belongs_to :event
|
206
|
-
|
207
|
-
end # class Round
|
208
|
-
|
209
|
-
|
210
|
-
class Prop < ActiveRecord::Base
|
211
|
-
|
212
|
-
end # class Prop
|
213
|
-
|
214
|
-
|
215
|
-
end # module SportDB
|
1
|
+
module SportDB
|
2
|
+
module Models
|
3
|
+
|
4
|
+
|
5
|
+
class Game < ActiveRecord::Base
|
6
|
+
|
7
|
+
belongs_to :team1, :class_name => 'Team', :foreign_key => 'team1_id'
|
8
|
+
belongs_to :team2, :class_name => 'Team', :foreign_key => 'team2_id'
|
9
|
+
|
10
|
+
belongs_to :round
|
11
|
+
belongs_to :group # group is optional
|
12
|
+
|
13
|
+
before_save :calc_toto12x
|
14
|
+
|
15
|
+
|
16
|
+
def self.create_knockouts_from_ary!( games, round )
|
17
|
+
Game.create_from_ary!( games, round, true )
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create_from_ary!( games, round, knockout=false )
|
21
|
+
games.each_with_index do |values,index|
|
22
|
+
|
23
|
+
## check if first value (that is, values[0]) is a numeric/number
|
24
|
+
## if NOT add pos automatic (counting from 1 to n)
|
25
|
+
|
26
|
+
if values[0].kind_of? Numeric
|
27
|
+
pos = values[0]
|
28
|
+
offset = 1
|
29
|
+
else
|
30
|
+
pos = index
|
31
|
+
offset = 0
|
32
|
+
end
|
33
|
+
|
34
|
+
Game.create!(
|
35
|
+
: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 )
|
48
|
+
end # each games
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.create_pairs_from_ary_for_group!( pairs, group )
|
52
|
+
|
53
|
+
pairs.each do |pair|
|
54
|
+
game1_attribs = {
|
55
|
+
:round =>pair[0][5],
|
56
|
+
:pos =>pair[0][0],
|
57
|
+
:team1 =>pair[0][1],
|
58
|
+
:score1 =>pair[0][2][0],
|
59
|
+
:score2 =>pair[0][2][1],
|
60
|
+
:team2 =>pair[0][3],
|
61
|
+
:play_at =>pair[0][4],
|
62
|
+
:group =>group }
|
63
|
+
|
64
|
+
game2_attribs = {
|
65
|
+
:round =>pair[1][5],
|
66
|
+
:pos =>pair[1][0],
|
67
|
+
:team1 =>pair[1][1],
|
68
|
+
:score1 =>pair[1][2][0],
|
69
|
+
:score2 =>pair[1][2][1],
|
70
|
+
:team2 =>pair[1][3],
|
71
|
+
:play_at =>pair[1][4],
|
72
|
+
:group =>group }
|
73
|
+
|
74
|
+
game1 = Game.create!( game1_attribs )
|
75
|
+
game2 = Game.create!( game2_attribs )
|
76
|
+
|
77
|
+
# linkup games
|
78
|
+
game1.next_game_id = game2.id
|
79
|
+
game1.save!
|
80
|
+
|
81
|
+
game2.prev_game_id = game1.id
|
82
|
+
game2.save!
|
83
|
+
end # each pair
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.create_knockout_pairs_from_ary!( pairs, round1, round2 )
|
87
|
+
|
88
|
+
pairs.each do |pair|
|
89
|
+
game1_attribs = {
|
90
|
+
:round =>round1,
|
91
|
+
:pos =>pair[0][0],
|
92
|
+
:team1 =>pair[0][1],
|
93
|
+
:score1 =>pair[0][2][0],
|
94
|
+
:score2 =>pair[0][2][1],
|
95
|
+
:team2 =>pair[0][3],
|
96
|
+
:play_at =>pair[0][4] }
|
97
|
+
|
98
|
+
game2_attribs = {
|
99
|
+
:round =>round2,
|
100
|
+
:pos =>pair[1][0],
|
101
|
+
:team1 =>pair[1][1],
|
102
|
+
:score1 =>pair[1][2][0],
|
103
|
+
:score2 =>pair[1][2][1],
|
104
|
+
:score3 =>pair[1][2][2],
|
105
|
+
:score4 =>pair[1][2][3],
|
106
|
+
:score5 =>pair[1][2][4],
|
107
|
+
:score6 =>pair[1][2][5],
|
108
|
+
:team2 =>pair[1][3],
|
109
|
+
:play_at =>pair[1][4],
|
110
|
+
:knockout =>true }
|
111
|
+
|
112
|
+
game1 = Game.create!( game1_attribs )
|
113
|
+
game2 = Game.create!( game2_attribs )
|
114
|
+
|
115
|
+
# linkup games
|
116
|
+
game1.next_game_id = game2.id
|
117
|
+
game1.save!
|
118
|
+
|
119
|
+
game2.prev_game_id = game1.id
|
120
|
+
game2.save!
|
121
|
+
end # each pair
|
122
|
+
end
|
123
|
+
|
124
|
+
def calc_toto12x
|
125
|
+
if score1.nil? || score2.nil?
|
126
|
+
self.toto12x = nil
|
127
|
+
elsif score1 == score2
|
128
|
+
self.toto12x = 'X'
|
129
|
+
elsif score1 > score2
|
130
|
+
self.toto12x = '1'
|
131
|
+
elsif score1 < score2
|
132
|
+
self.toto12x = '2'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end # class Game
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
end # module Models
|
141
|
+
end # module SportDB
|