sportdb 0.9.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/Manifest.txt +12 -55
  2. data/Rakefile +11 -10
  3. data/bin/sportdb +1 -2
  4. data/config/fixtures.de.yml +42 -0
  5. data/config/fixtures.en.yml +52 -0
  6. data/config/fixtures.es.yml +44 -0
  7. data/config/fixtures.pt.yml +44 -0
  8. data/lib/sportdb/cli/main.rb +189 -0
  9. data/lib/sportdb/cli/opts.rb +15 -69
  10. data/lib/sportdb/data/fixtures.rb +205 -0
  11. data/lib/sportdb/{keys.rb → data/keys.rb} +9 -2
  12. data/lib/sportdb/data/models.rb +43 -0
  13. data/lib/sportdb/deleter.rb +27 -0
  14. data/lib/sportdb/lang.rb +265 -0
  15. data/lib/sportdb/models/event.rb +0 -34
  16. data/lib/sportdb/reader.rb +322 -78
  17. data/lib/sportdb/stats.rb +28 -0
  18. data/lib/sportdb/utils.rb +90 -13
  19. data/lib/sportdb/version.rb +1 -1
  20. data/lib/sportdb.rb +49 -198
  21. data/tasks/test.rb +163 -0
  22. metadata +46 -71
  23. data/data/america/2011.rb +0 -36
  24. data/data/america/2011.txt +0 -110
  25. data/data/america/2011.yml +0 -30
  26. data/data/america/teams.txt +0 -26
  27. data/data/at/2011_12/bl.rb +0 -30
  28. data/data/at/2011_12/bl.txt +0 -79
  29. data/data/at/2011_12/cup.rb +0 -66
  30. data/data/at/2012_13/bl.rb +0 -33
  31. data/data/at/2012_13/bl.txt +0 -198
  32. data/data/at/2012_13/cup.rb +0 -111
  33. data/data/at/2012_13/cup.txt +0 -89
  34. data/data/at/badges.rb +0 -22
  35. data/data/at/teams.txt +0 -88
  36. data/data/cl/2011_12/cl.rb +0 -88
  37. data/data/cl/2011_12/el.rb +0 -65
  38. data/data/cl/2012_13/cl.rb +0 -324
  39. data/data/cl/badges.rb +0 -68
  40. data/data/cl/teams.txt +0 -46
  41. data/data/copa/sud_2012_13.rb +0 -38
  42. data/data/copa/sud_2012_13.txt +0 -49
  43. data/data/copa/teams.txt +0 -35
  44. data/data/de/2012_13/bl.rb +0 -38
  45. data/data/de/2012_13/bl.txt +0 -216
  46. data/data/de/teams.txt +0 -23
  47. data/data/en/2012_13/pl.rb +0 -39
  48. data/data/en/2012_13/pl.txt +0 -291
  49. data/data/en/teams.txt +0 -26
  50. data/data/es/teams.txt +0 -8
  51. data/data/euro/2008.rb +0 -30
  52. data/data/euro/2008.txt +0 -114
  53. data/data/euro/2012.rb +0 -25
  54. data/data/euro/2012.txt +0 -114
  55. data/data/euro/teams.txt +0 -36
  56. data/data/leagues.rb +0 -68
  57. data/data/mx/apertura_2012.rb +0 -35
  58. data/data/mx/apertura_2012.txt +0 -106
  59. data/data/mx/teams.txt +0 -20
  60. data/data/nfl/teams.txt +0 -46
  61. data/data/nhl/teams.txt +0 -40
  62. data/data/ro/l1_2012_13.rb +0 -137
  63. data/data/ro/teams.txt +0 -26
  64. data/data/seasons.rb +0 -22
  65. data/data/world/2010.rb +0 -93
  66. data/data/world/2010.txt +0 -215
  67. data/data/world/quali_2012_13_america.rb +0 -25
  68. data/data/world/quali_2012_13_america.txt +0 -41
  69. data/data/world/quali_2012_13_europe.rb +0 -32
  70. data/data/world/quali_2012_13_europe_c.txt +0 -85
  71. data/data/world/quali_2012_13_europe_i.txt +0 -74
  72. data/data/world/teams.txt +0 -25
  73. data/lib/sportdb/cli/runner.rb +0 -147
  74. data/lib/sportdb/loader.rb +0 -82
  75. data/lib/sportdb/templater.rb +0 -81
  76. data/templates/fixtures.rb.erb +0 -51
data/Manifest.txt CHANGED
@@ -3,62 +3,19 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  bin/sportdb
6
- data/america/2011.rb
7
- data/america/2011.txt
8
- data/america/2011.yml
9
- data/america/teams.txt
10
- data/at/2011_12/bl.rb
11
- data/at/2011_12/bl.txt
12
- data/at/2011_12/cup.rb
13
- data/at/2012_13/bl.rb
14
- data/at/2012_13/bl.txt
15
- data/at/2012_13/cup.rb
16
- data/at/2012_13/cup.txt
17
- data/at/badges.rb
18
- data/at/teams.txt
19
- data/cl/2011_12/cl.rb
20
- data/cl/2011_12/el.rb
21
- data/cl/2012_13/cl.rb
22
- data/cl/badges.rb
23
- data/cl/teams.txt
24
- data/copa/sud_2012_13.rb
25
- data/copa/sud_2012_13.txt
26
- data/copa/teams.txt
27
- data/de/2012_13/bl.rb
28
- data/de/2012_13/bl.txt
29
- data/de/teams.txt
30
- data/en/2012_13/pl.rb
31
- data/en/2012_13/pl.txt
32
- data/en/teams.txt
33
- data/es/teams.txt
34
- data/euro/2008.rb
35
- data/euro/2008.txt
36
- data/euro/2012.rb
37
- data/euro/2012.txt
38
- data/euro/teams.txt
39
- data/leagues.rb
40
- data/mx/apertura_2012.rb
41
- data/mx/apertura_2012.txt
42
- data/mx/teams.txt
43
- data/nfl/teams.txt
44
- data/nhl/teams.txt
45
- data/ro/l1_2012_13.rb
46
- data/ro/teams.txt
47
- data/seasons.rb
48
- data/world/2010.rb
49
- data/world/2010.txt
50
- data/world/quali_2012_13_america.rb
51
- data/world/quali_2012_13_america.txt
52
- data/world/quali_2012_13_europe.rb
53
- data/world/quali_2012_13_europe_c.txt
54
- data/world/quali_2012_13_europe_i.txt
55
- data/world/teams.txt
6
+ config/fixtures.de.yml
7
+ config/fixtures.en.yml
8
+ config/fixtures.es.yml
9
+ config/fixtures.pt.yml
56
10
  lib/sportdb.rb
11
+ lib/sportdb/cli/main.rb
57
12
  lib/sportdb/cli/opts.rb
58
- lib/sportdb/cli/runner.rb
59
13
  lib/sportdb/console.rb
60
- lib/sportdb/keys.rb
61
- lib/sportdb/loader.rb
14
+ lib/sportdb/data/fixtures.rb
15
+ lib/sportdb/data/keys.rb
16
+ lib/sportdb/data/models.rb
17
+ lib/sportdb/deleter.rb
18
+ lib/sportdb/lang.rb
62
19
  lib/sportdb/models/badge.rb
63
20
  lib/sportdb/models/city.rb
64
21
  lib/sportdb/models/country.rb
@@ -76,7 +33,7 @@ lib/sportdb/models/season.rb
76
33
  lib/sportdb/models/team.rb
77
34
  lib/sportdb/reader.rb
78
35
  lib/sportdb/schema.rb
79
- lib/sportdb/templater.rb
36
+ lib/sportdb/stats.rb
80
37
  lib/sportdb/utils.rb
81
38
  lib/sportdb/version.rb
82
- templates/fixtures.rb.erb
39
+ tasks/test.rb
data/Rakefile CHANGED
@@ -4,11 +4,6 @@ require './lib/sportdb/version.rb'
4
4
  ## NB: plugin (hoe-manifest) not required; just used for future testing/development
5
5
  Hoe::plugin :manifest # more options for manifests (in the future; not yet)
6
6
 
7
- ###########
8
- #### NB: if you try this script at home
9
- # you need to create a (symbolic) link to the sport.db fixtures
10
- # e.g. use ln -s ../sport.db data or similar
11
-
12
7
 
13
8
  Hoe.spec 'sportdb' do
14
9
 
@@ -28,17 +23,23 @@ Hoe.spec 'sportdb' do
28
23
  # self.history_file = 'History.md'
29
24
 
30
25
  self.extra_deps = [
26
+ ['worlddb', '~> 1.0.1'], # NB: worlddb already includes
27
+ # - commander
28
+ # - logutils
29
+ # - textutils
30
+
31
+ ## 3rd party
32
+ ['commander', '~> 4.1.3'] # remove? -- already included as dep in worlddb
33
+
31
34
  ## ['activerecord', '~> 3.2'], # NB: will include activesupport,etc.
32
- ['worlddb', '~> 0.6.8']
33
35
  ### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
34
36
  ]
35
37
 
36
38
  self.licenses = ['Public Domain']
37
39
 
38
- #
39
- # self.spec_extras = {
40
- # :required_ruby_version => '>= 1.9.2'
41
- # }
40
+ self.spec_extras = {
41
+ :required_ruby_version => '>= 1.9.2'
42
+ }
42
43
 
43
44
  self.post_install_message =<<EOS
44
45
  ******************************************************************************
data/bin/sportdb CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'sportdb'
4
-
5
- SportDB.main
4
+ SportDB.main
@@ -0,0 +1,42 @@
1
+ ###########################
2
+ # known keywords for fixtures
3
+
4
+
5
+ group: Gruppe
6
+ matchday: Spieltag
7
+ round: Runde
8
+ stage: Gruppenphase|Qualifikation|Play-off|Finalrunde|K.-o.-Phase
9
+
10
+
11
+ ### Knock out rounds
12
+
13
+ round32: Sechzehntelfinale|1/16 Finale
14
+ round16: Achtelfinale|1/8 Finale
15
+ quarterfinals: Viertelfinale|1/4 Finale
16
+ semifinals: Halbfinale|Semifinale|1/2 Finale
17
+ thirdplace: Spiel um Platz 3
18
+ final: Finale|Endspiel
19
+
20
+ ### Pair matches/games if marked with leg1 n leg2
21
+
22
+ leg1: Hin|Hinspiel|Hinspiele
23
+ leg2: Rück|Rückspiel|Rückspiele
24
+
25
+
26
+ #######################
27
+ # months of year
28
+
29
+ january: Jänner|Januar
30
+ february: Feber|Februar
31
+ march: März
32
+ april: April
33
+ may: Mai
34
+ june: Juni
35
+ july: Juli
36
+ august: August
37
+ september: September
38
+ october: Oktober
39
+ november: November
40
+ december: Dezember
41
+
42
+
@@ -0,0 +1,52 @@
1
+ ###########################
2
+ # known keywords for fixtures
3
+
4
+
5
+ group: Group
6
+ matchday: Matchday
7
+ round: Round
8
+
9
+ stage: Stage|Phase|Rounds
10
+ # e.g.
11
+ # Group stage
12
+ # Play off stage|Play-off stage
13
+ # Knockout stage|Knockout stages
14
+ # First stage
15
+ # Second stage
16
+ # Qualifying rounds
17
+
18
+
19
+
20
+
21
+ ### Knockout rounds
22
+
23
+ round32: Round of 32|Last 32
24
+ round16: Round of 16|Last 16
25
+ quarterfinals: Quarterfinals|Quarter-finals|Quarters|Quarterfinal # todo: check if singular Quaterfinal is possible??
26
+ semifinals: Semifinals|Semi-finals|Semis
27
+ thirdplace: Third-place play-off|Third place play-off|Third place|3rd place match
28
+ final: Final|Finals
29
+
30
+ ### Pair matches/games if marked with leg1 n leg2
31
+
32
+ leg1: 1st leg|1st Leg|First leg # todo: check for automatica ignore case - why? why not?
33
+ leg2: 2nd leg|2nd Leg|Second leg
34
+
35
+
36
+ #######################
37
+ # months of year
38
+
39
+ january: January
40
+ february: February
41
+ march: March
42
+ april: April
43
+ may: May
44
+ june: June
45
+ july: July
46
+ august: August
47
+ september: September
48
+ october: October
49
+ november: November
50
+ december: December
51
+
52
+
@@ -0,0 +1,44 @@
1
+ ###########################
2
+ # known keywords for fixtures
3
+
4
+
5
+ group: Grupo
6
+ matchday: Jornada
7
+ round: Fecha
8
+
9
+ stage: Primera fase|Segunda fase|Fase de grupos|Fase final
10
+
11
+
12
+ ### Knock out rounds
13
+
14
+ round32: Dieciseisavos de final|16vos de final
15
+ round16: Octavos|Octavos de final|8vos de final
16
+ quarterfinals: Cuartos|Cuartos de final|4tos de final
17
+ semifinals: Semifinales|Semifinal
18
+ thirdplace: Tercer lugar
19
+ final: Final
20
+
21
+ ### Pair matches/games if marked with leg1 n leg2
22
+
23
+ leg1: Ida
24
+ leg2: Vuelta
25
+
26
+
27
+
28
+ #######################
29
+ # months of year
30
+
31
+ january: enero
32
+ february: febrero
33
+ march: marzo
34
+ april: abril
35
+ may: mayo
36
+ june: junio
37
+ july: julio
38
+ august: agosto
39
+ september: septiembre
40
+ october: octubre
41
+ november: noviembre
42
+ december: diciembre
43
+
44
+
@@ -0,0 +1,44 @@
1
+ ###########################
2
+ # known keywords for fixtures
3
+
4
+
5
+ group: Grupo # Grupo
6
+ matchday: # Jornada
7
+ round: # Fecha
8
+
9
+ stage: Primeira Fase|Segunda Fase # Primera fase|Segunda fase|Fase de grupos|Fase final
10
+
11
+
12
+ ### Knock out rounds
13
+
14
+ round32: # Dieciseisavos de final|16vos de final
15
+ round16: Oitavas-de-final # Octavos|Octavos de final|8vos de final
16
+ quarterfinals: Quartas-de-final # Cuartos|Cuartos de final|4tos de final
17
+ semifinals: Semifinais # Semifinales|Semifinal
18
+ thirdplace: # Tercer lugar
19
+ final: Final # Final
20
+
21
+ ### Pair matches/games if marked with leg1 n leg2
22
+
23
+ leg1: Ida # Ida
24
+ leg2: Volta # Vuelta
25
+
26
+
27
+
28
+ #######################
29
+ # months of year
30
+
31
+ january: janeiro # enero
32
+ february: fevereiro # febrero
33
+ march: março # marzo
34
+ april: abril # abril
35
+ may: maio # mayo
36
+ june: junho # junio
37
+ july: julho # julio
38
+ august: # agosto
39
+ september: # septiembre
40
+ october: # octubre
41
+ november: # noviembre
42
+ december: # diciembre
43
+
44
+
@@ -0,0 +1,189 @@
1
+ # encoding: utf-8
2
+
3
+ require 'commander/import'
4
+
5
+ # our own code / additional for cli only
6
+
7
+ require 'sportdb/cli/opts'
8
+
9
+
10
+ program :name, 'sportdb'
11
+ program :version, SportDB::VERSION
12
+ program :description, "sport.db command line tool, version #{SportDB::VERSION}"
13
+
14
+
15
+ # default_command :help
16
+ default_command :load
17
+
18
+ program :help_formatter, Commander::HelpFormatter::TerminalCompact
19
+
20
+ ## program :help, 'Examples', 'yada yada -try multi line later'
21
+
22
+ =begin
23
+ ### add to help use new sections
24
+
25
+ Examples:
26
+ sportdb cl/teams cl/2012_13/cl # import champions league (cl)
27
+ sportdb --create # create database schema
28
+
29
+ More Examples:
30
+ sportdb # show stats (table counts, table props)
31
+ sportdb -i ../sport.db/db cl/teams cl/2012_13/cl # import champions league (cl) in db folder
32
+
33
+ Further information:
34
+ http://geraldb.github.com/sport.db
35
+ =end
36
+
37
+
38
+ ## todo: find a better name e.g. change to settings? config? safe_opts? why? why not?
39
+ myopts = SportDB::Opts.new
40
+
41
+ ### global option (required)
42
+ ## todo: add check that path is valid?? possible?
43
+
44
+ global_option '-i', '--include PATH', String, "Data path (default is #{myopts.data_path})"
45
+ global_option '-d', '--dbpath PATH', String, "Database path (default is #{myopts.db_path})"
46
+ global_option '-n', '--dbname NAME', String, "Database name (datault is #{myopts.db_name})"
47
+
48
+
49
+ def connect_to_db( options )
50
+ puts SportDB.banner
51
+
52
+ puts "working directory: #{Dir.pwd}"
53
+
54
+ db_config = {
55
+ :adapter => 'sqlite3',
56
+ :database => "#{options.db_path}/#{options.db_name}"
57
+ }
58
+
59
+ puts "Connecting to db using settings: "
60
+ pp db_config
61
+
62
+ ActiveRecord::Base.establish_connection( db_config )
63
+ end
64
+
65
+
66
+ command :create do |c|
67
+ c.syntax = 'sportdb create [options]'
68
+ c.description = 'Create DB schema'
69
+ c.action do |args, options|
70
+ myopts.merge_commander_options!( options.__hash__ )
71
+ connect_to_db( myopts )
72
+
73
+ LogDB.create
74
+ WorldDB.create
75
+ SportDB.create
76
+ puts 'Done.'
77
+ end # action
78
+ end # command create
79
+
80
+ command :setup do |c|
81
+ c.syntax = 'sportdb setup [options]'
82
+ c.description = "Create DB schema 'n' load all data"
83
+
84
+ c.option '--world', 'Populate world tables'
85
+ ## todo: use --world-include - how? find better name?
86
+ c.option '--worldinclude PATH', String, 'World data path'
87
+
88
+ c.option '--sport', 'Populate sport tables'
89
+ c.option '--delete', 'Delete all records'
90
+
91
+ c.action do |args, options|
92
+ myopts.merge_commander_options!( options.__hash__ )
93
+ connect_to_db( myopts )
94
+
95
+ if options.world.present? || options.sport.present?
96
+
97
+ ## todo: check order for reference integrity
98
+ # not really possible to delete world data if sport data is present
99
+ # delete sport first
100
+
101
+ if options.delete.present?
102
+ SportDB.delete! if options.sport.present?
103
+ WorldDB.delete! if options.world.present?
104
+ end
105
+
106
+ if options.world.present?
107
+ WorldDB.read_all( myopts.world_data_path )
108
+ end
109
+ if options.sport.present?
110
+ SportDB.read_all( myopts.data_path )
111
+ end
112
+
113
+ else # assume "plain" regular setup
114
+ LogDB.create
115
+ WorldDB.create
116
+ SportDB.create
117
+
118
+ WorldDB.read_all( myopts.world_data_path )
119
+ SportDB.read_all( myopts.data_path )
120
+ end
121
+ puts 'Done.'
122
+ end # action
123
+ end # command setup
124
+
125
+ command :load do |c|
126
+ ## todo: how to specify many fixutes <>... ??? in syntax
127
+ c.syntax = 'sportdb load [options] FIXTURE...'
128
+ c.description = 'Load fixtures'
129
+
130
+ c.option '-e', '--event KEY', String, 'Event to load'
131
+ c.option '--delete', 'Delete all records'
132
+
133
+ c.action do |args, options|
134
+ myopts.merge_commander_options!( options.__hash__ )
135
+ connect_to_db( myopts )
136
+
137
+ SportDB.delete! if options.delete.present?
138
+
139
+ logger = LogUtils::Logger.new
140
+
141
+ reader = SportDB::Reader.new( logger )
142
+
143
+ args.each do |arg|
144
+ name = arg # File.basename( arg, '.*' )
145
+
146
+ if myopts.event.present?
147
+ ## fix: rename to load_event_fixtures_w... or similar
148
+ reader.load_fixtures_with_include_path( myopts.event, name, myopts.data_path )
149
+ else
150
+ ## fix> add a convenience method for loading single fixture
151
+ ary = []
152
+ ary << name
153
+ reader.load_with_include_path( ary, myopts.data_path )
154
+ end
155
+ end # each arg
156
+
157
+ puts 'Done.'
158
+ end
159
+ end # command load
160
+
161
+
162
+ command :stats do |c|
163
+ c.syntax = 'sportdb stats [options]'
164
+ c.description = 'Show stats'
165
+ c.action do |args, options|
166
+ myopts.merge_commander_options!( options.__hash__ )
167
+ connect_to_db( myopts )
168
+
169
+ SportDB.stats
170
+
171
+ puts 'Done.'
172
+ end
173
+ end
174
+
175
+
176
+ command :test do |c|
177
+ c.syntax = 'sportdb test [options]'
178
+ c.description = 'Debug/test command suite'
179
+ c.action do |args, options|
180
+ puts "hello from test command"
181
+ puts "args (#{args.class.name}):"
182
+ pp args
183
+ puts "options:"
184
+ pp options
185
+ puts "options.__hash__:"
186
+ pp options.__hash__
187
+ puts 'Done.'
188
+ end
189
+ end
@@ -2,91 +2,33 @@ module SportDB
2
2
 
3
3
  class Opts
4
4
 
5
- def create=(boolean)
6
- @create = boolean
7
- end
8
-
9
- def create?
10
- return false if @create.nil? # default create flag is false
11
- @create == true
12
- end
13
-
14
- def setup=(boolean)
15
- @setup = boolean
16
- end
5
+ def merge_commander_options!( options = {} )
6
+ @db_path = options[:dbpath] if options[:dbpath].present?
7
+ @db_name = options[:dbname] if options[:dbname].present?
17
8
 
18
- def setup?
19
- return false if @setup.nil? # default setup flag is false
20
- @setup == true
21
- end
9
+ @data_path = options[:include] if options[:include].present?
10
+ @event = options[:event] if options[:event].present?
22
11
 
23
- def sport=(boolean)
24
- @sport = boolean
12
+ @world_data_path = options[:worldinclude] if options[:worldinclude].present?
25
13
  end
26
14
 
27
- def sport?
28
- return false if @sport.nil? # default sport flag is false
29
- @sport == true
30
- end
31
-
32
-
33
- def world=(boolean)
34
- @world = boolean
35
- end
36
15
 
37
- def world?
38
- return false if @world.nil? # default populate world tables flag is false
39
- @world == true
16
+ def db_path
17
+ @db_path || '.'
40
18
  end
41
19
 
42
-
43
- def generate=(boolean)
44
- @generate = boolean
20
+ def db_name
21
+ @db_name || 'sport.db'
45
22
  end
46
23
 
47
- def generate?
48
- return false if @generate.nil? # default generate flag is false
49
- @generate == true
50
- end
51
-
52
24
  def event=(value)
53
25
  @event = value
54
26
  end
55
-
27
+
56
28
  def event
57
29
  @event # NB: option has no default; return nil ## || '.'
58
- end
59
-
60
-
61
- def delete=(boolean)
62
- @delete = boolean
63
30
  end
64
31
 
65
- def delete?
66
- return false if @delete.nil? # default create flag is false
67
- @delete == true
68
- end
69
-
70
-
71
- # use loader? (that is, built-in seed data)
72
- def load=(boolean)
73
- @load = boolean
74
- end
75
-
76
- def load?
77
- return false if @load.nil? # default create flag is false
78
- @load == true
79
- end
80
-
81
-
82
- def output_path=(value)
83
- @output_path = value
84
- end
85
-
86
- def output_path
87
- @output_path || '.'
88
- end
89
-
90
32
 
91
33
  def data_path=(value)
92
34
  @data_path = value
@@ -97,6 +39,10 @@ class Opts
97
39
  end
98
40
 
99
41
 
42
+ def world_data_path
43
+ @world_data_path # NB: option has no default; return nil
44
+ end
45
+
100
46
  end # class Opts
101
47
 
102
48
  end # module SportDB