sportdb 1.8.27 → 1.8.28

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.
Files changed (35) hide show
  1. data/Manifest.txt +0 -21
  2. data/lib/sportdb/calc.rb +96 -26
  3. data/lib/sportdb/models/stats/alltime_standing.rb +5 -3
  4. data/lib/sportdb/schema.rb +2 -1
  5. data/lib/sportdb/service.rb +9 -21
  6. data/lib/sportdb/service/public/style.css +0 -17
  7. data/lib/sportdb/service/public/style.css.scss +1 -27
  8. data/lib/sportdb/service/server.rb +10 -6
  9. data/lib/sportdb/service/views/_version.erb +2 -3
  10. data/lib/sportdb/service/views/index.erb +1 -141
  11. data/lib/sportdb/service/views/layout.erb +1 -4
  12. data/lib/sportdb/version.rb +1 -1
  13. data/test/test_standings.rb +30 -1
  14. metadata +26 -47
  15. data/lib/sportdb/service/public/football/js/football/api.js +0 -63
  16. data/lib/sportdb/service/public/football/js/football/plugin.js +0 -36
  17. data/lib/sportdb/service/public/football/js/football/widget.js +0 -169
  18. data/lib/sportdb/service/public/football/js/libs/jquery-2.0.2.min.js +0 -6
  19. data/lib/sportdb/service/public/football/js/libs/require-2.1.6.js +0 -2045
  20. data/lib/sportdb/service/public/football/js/libs/underscore-1.4.4.min.js +0 -1
  21. data/lib/sportdb/service/public/football/js/text.js +0 -373
  22. data/lib/sportdb/service/public/football/js/utils.js +0 -80
  23. data/lib/sportdb/service/public/football/matchday-jquery.html +0 -57
  24. data/lib/sportdb/service/public/football/matchday-template.html +0 -106
  25. data/lib/sportdb/service/public/football/matchday.html +0 -76
  26. data/lib/sportdb/service/public/football/templates/event.html +0 -6
  27. data/lib/sportdb/service/public/football/templates/games.html +0 -29
  28. data/lib/sportdb/service/public/football/templates/rounds-long.html +0 -11
  29. data/lib/sportdb/service/public/football/templates/rounds-short.html +0 -16
  30. data/lib/sportdb/service/public/football/templates/rounds-today.html +0 -8
  31. data/lib/sportdb/service/version.rb +0 -6
  32. data/lib/sportdb/service/views/_football_head.erb +0 -21
  33. data/lib/sportdb/service/views/_football_live.erb +0 -32
  34. data/lib/sportdb/service/views/_football_today.erb +0 -20
  35. data/lib/sportdb/service/views/_usage.erb +0 -25
@@ -70,31 +70,10 @@ lib/sportdb/readers/team.rb
70
70
  lib/sportdb/readers/track.rb
71
71
  lib/sportdb/schema.rb
72
72
  lib/sportdb/service.rb
73
- lib/sportdb/service/public/football/js/football/api.js
74
- lib/sportdb/service/public/football/js/football/plugin.js
75
- lib/sportdb/service/public/football/js/football/widget.js
76
- lib/sportdb/service/public/football/js/libs/jquery-2.0.2.min.js
77
- lib/sportdb/service/public/football/js/libs/require-2.1.6.js
78
- lib/sportdb/service/public/football/js/libs/underscore-1.4.4.min.js
79
- lib/sportdb/service/public/football/js/text.js
80
- lib/sportdb/service/public/football/js/utils.js
81
- lib/sportdb/service/public/football/matchday-jquery.html
82
- lib/sportdb/service/public/football/matchday-template.html
83
- lib/sportdb/service/public/football/matchday.html
84
- lib/sportdb/service/public/football/templates/event.html
85
- lib/sportdb/service/public/football/templates/games.html
86
- lib/sportdb/service/public/football/templates/rounds-long.html
87
- lib/sportdb/service/public/football/templates/rounds-short.html
88
- lib/sportdb/service/public/football/templates/rounds-today.html
89
73
  lib/sportdb/service/public/style.css
90
74
  lib/sportdb/service/public/style.css.scss
91
75
  lib/sportdb/service/server.rb
92
- lib/sportdb/service/version.rb
93
76
  lib/sportdb/service/views/_debug.erb
94
- lib/sportdb/service/views/_football_head.erb
95
- lib/sportdb/service/views/_football_live.erb
96
- lib/sportdb/service/views/_football_today.erb
97
- lib/sportdb/service/views/_usage.erb
98
77
  lib/sportdb/service/views/_version.erb
99
78
  lib/sportdb/service/views/debug.erb
100
79
  lib/sportdb/service/views/index.erb
@@ -12,17 +12,41 @@ module StandingsHelper
12
12
 
13
13
  ## todo:
14
14
  ## add team_id to struct - why? why not? - saves a db lookup?
15
- ## add appearances (event) count or similar - add to struct or use an extension?
16
- ## == use recs for number of (stats) records?
17
- Stats = Struct.new(
18
- :pos,
19
- :played,
20
- :won,
21
- :lost,
22
- :drawn,
23
- :goals_for,
24
- :goals_against,
25
- :pts )
15
+ class Stats
16
+ attr_accessor :pos, :played, :won, :lost, :drawn,
17
+ :goals_for, :goals_against, :pts,
18
+ :recs
19
+
20
+ def initialize
21
+ @pos = nil # use 0? why? why not?
22
+ @played = 0
23
+ @won = 0
24
+ @lost = 0
25
+ @drawn = 0
26
+ @goals_for = 0
27
+ @goals_against = 0
28
+ @pts = 0
29
+ @recs = 0
30
+ # note: appearances (event) count or similar
31
+ # is recs counter (number of (stats) records)
32
+ end
33
+
34
+ def add( rec )
35
+ ### fix: add plus + operator too!
36
+
37
+ # note: will NOT update/add pos (ranking)
38
+ self.played += rec.played
39
+ self.won += rec.won
40
+ self.lost += rec.lost
41
+ self.drawn += rec.drawn
42
+ self.goals_for += rec.goals_for
43
+ self.goals_against += rec.goals_against
44
+ self.pts += rec.pts
45
+ self.recs += rec.recs
46
+
47
+ self # return self stats rec
48
+ end # method add
49
+ end # class Stats
26
50
 
27
51
 
28
52
  def self.calc( games, opts={} )
@@ -36,6 +60,7 @@ module StandingsHelper
36
60
  end
37
61
 
38
62
 
63
+
39
64
  def self.calc_for_events( events, opts={} )
40
65
 
41
66
  ## todo:
@@ -48,21 +73,59 @@ module StandingsHelper
48
73
  recs = calc_stats( event.games )
49
74
 
50
75
  recs.each do |team_key, rec|
51
- alltime_rec = alltime_recs[ team_key ] || Stats.new( 0, 0, 0, 0, 0, 0, 0, 0 )
76
+ alltime_rec = alltime_recs[ team_key ] || Stats.new
52
77
 
53
78
  ## add stats values
54
- alltime_rec.played += rec.played
55
- alltime_rec.won += rec.won
56
- alltime_rec.lost += rec.lost
57
- alltime_rec.drawn += rec.drawn
58
- alltime_rec.goals_for += rec.goals_for
59
- alltime_rec.goals_against += rec.goals_against
60
- alltime_rec.pts += rec.pts
61
-
79
+ alltime_rec.add( rec )
80
+
62
81
  alltime_recs[ team_key ] = alltime_rec
63
82
  end
64
83
  end
65
84
 
85
+
86
+ ### fix:
87
+ # - make merge team into a helper method (for reuse)
88
+
89
+ ## check for merging teams
90
+ # e.g. all time world cup
91
+ # Germany incl. West Germany
92
+ # Russia incl. Soviet Union etc.
93
+
94
+ # todo: change opts para to :includes instead of :merge ? why? why not??
95
+
96
+ merge = opts[:merge]
97
+ if merge
98
+ puts " merging teams (stats records):"
99
+ pp merge
100
+
101
+ merge.each do |k,v|
102
+ # note: assume key is destition team key and
103
+ # value is source team key e.g. 'GER' => 'FRG'
104
+ # or array (for mulitple teamss e.g. 'GER' => ['FRG','GDR']
105
+ team_key_dest = k.to_s
106
+
107
+ if v.kind_of? Array
108
+ team_keys_src = v
109
+ else
110
+ team_keys_src = [v] # turn single value arg into array w/ single item
111
+ end
112
+ team_keys_src = team_keys_src.map { |src| src.to_s } # turn all to string (might be symbol)
113
+
114
+ alltime_rec_dest = alltime_recs[ team_key_dest ] || Stats.new
115
+
116
+ team_keys_src.each do |team_key_src|
117
+ alltime_rec_src = alltime_recs[ team_key_src]
118
+
119
+ if alltime_rec_src # stats record found?
120
+ alltime_rec_dest.add( alltime_rec_src ) # add stats values
121
+ alltime_recs.delete( team_key_src ) # remove old src entry
122
+ end
123
+ end
124
+
125
+ alltime_recs[ team_key_dest ] = alltime_rec_dest
126
+ end
127
+ end
128
+
66
129
  ## update pos (that is, ranking e.g. 1.,2., 3. etc.)
67
130
  alltime_recs= update_ranking( alltime_recs )
68
131
 
@@ -73,26 +136,33 @@ module StandingsHelper
73
136
 
74
137
 
75
138
  def self.calc_stats( games, opts={} )
76
-
139
+
77
140
  ## fix:
78
141
  # passing in e.g. pts for win (3? 2? etc.)
79
142
  # default to 3 for now
80
-
143
+
144
+ # note:
145
+ # returns stats records w/ stats records counter always set to one (recs==1)
146
+
81
147
  recs = {}
82
148
 
83
149
  games.each_with_index do |g,i| # note: index(i) starts w/ zero (0)
84
150
  puts " [#{i+1}] #{g.team1.title} - #{g.team2.title} #{g.score_str}"
85
151
  unless g.over?
86
- puts " skipping match - not yet over (play_at date in the future)"
152
+ puts " !!!! skipping match - not yet over (play_at date in the future)"
87
153
  next
88
154
  end
89
155
  unless g.complete?
90
- puts " skipping match - scores incomplete"
156
+ puts " !!!! skipping match - scores incomplete"
91
157
  next
92
158
  end
93
159
 
94
- rec1 = recs[ g.team1.key ] || Stats.new( 0, 0, 0, 0, 0, 0, 0, 0 )
95
- rec2 = recs[ g.team2.key ] || Stats.new( 0, 0, 0, 0, 0, 0, 0, 0 )
160
+ rec1 = recs[ g.team1.key ] || Stats.new
161
+ rec2 = recs[ g.team2.key ] || Stats.new
162
+
163
+ ## set stats records counter to one if new (first) record update
164
+ rec1.recs = 1 if rec1.recs == 0
165
+ rec2.recs = 1 if rec2.recs == 0
96
166
 
97
167
  rec1.played += 1
98
168
  rec2.played += 1
@@ -11,9 +11,9 @@ class AlltimeStanding < ActiveRecord::Base
11
11
  has_many :entries, class_name: 'SportDb::Model::AlltimeStandingEntry', foreign_key: 'alltime_standing_id', :dependent => :delete_all
12
12
 
13
13
 
14
- def recalc_for_league!( league )
14
+ def recalc_for_league!( league, opts={} )
15
15
 
16
- recs = StandingsHelper.calc_for_events( league.events )
16
+ recs = StandingsHelper.calc_for_events( league.events, opts )
17
17
 
18
18
  ## - remove (if exit) old entries and add new entries
19
19
  entries.delete_all # note: assoc dependent set to :delete_all (defaults to :nullify)
@@ -21,6 +21,7 @@ class AlltimeStanding < ActiveRecord::Base
21
21
  recs.each do |team_key,rec|
22
22
 
23
23
  team = Team.find_by_key!( team_key )
24
+ ### note: we also add rec.recs (appearance counter) - not included w/ group or event standings, for example
24
25
  entries.create!(
25
26
  team_id: team.id,
26
27
  pos: rec.pos,
@@ -30,7 +31,8 @@ class AlltimeStanding < ActiveRecord::Base
30
31
  lost: rec.lost,
31
32
  goals_for: rec.goals_for,
32
33
  goals_against: rec.goals_against,
33
- pts: rec.pts )
34
+ pts: rec.pts,
35
+ recs: rec.recs )
34
36
  end
35
37
  end # method recalc_for_league!
36
38
 
@@ -366,7 +366,8 @@ create_table :alltime_standing_entries do |t|
366
366
  t.integer :goals_for # todo: find a short name - gf? why? why not?
367
367
  t.integer :goals_against # todo: find a shorter name - ga? why? why not?
368
368
  t.integer :pts
369
- t.string :comments
369
+ t.integer :recs # note: specific to alltime - stats records counter (e.g. appearance counter)
370
+ t.string :comments
370
371
  t.timestamps
371
372
  end
372
373
 
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # e.g. config.ru:
5
5
  # require './boot'
6
- # run SportDb::Service::Server
6
+ # run SportDb::Server
7
7
 
8
8
 
9
9
  # 3rd party libs/gems
@@ -13,30 +13,18 @@ require 'sinatra/base'
13
13
 
14
14
  # our own code
15
15
 
16
- require 'sportdb/service/version'
17
16
 
17
+ require 'sportdb/service/server'
18
18
 
19
- module SportDb::Service
20
-
21
- def self.banner
22
- "sportdb-service #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] on Sinatra/#{Sinatra::VERSION} (#{ENV['RACK_ENV']})"
23
- end
24
-
25
- ### fix: move to SportDb
26
- def self.root
27
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
28
- end
29
-
30
- =begin
31
- def self.config_path
32
- ## needed? use default db connection?
33
- "#{root}/config"
34
- end
35
- =end
36
19
 
20
+ ### for legacy old code e.g. SportDb::Service::Server - remove later - do NOT use
21
+ ## remove module Service (obsolete)
22
+ module SportDb
23
+ module Service
24
+ Server = SportDb::Server
25
+ end # module Service
37
26
  end # module SportDb
38
27
 
39
- require 'sportdb/service/server'
40
28
 
41
29
  # say hello
42
- puts SportDb::Service.banner
30
+ puts SportDb::Server.banner
@@ -11,23 +11,6 @@ a {
11
11
  a:visited {
12
12
  color: black; }
13
13
 
14
- .params {
15
- color: green;
16
- font-style: italic;
17
- font-weight: bold; }
18
-
19
- pre {
20
- background-color: #F3F3F3;
21
- border-bottom: 1px solid #BBBBBB;
22
- border-top: 1px solid #BBBBBB;
23
- padding: 4px; }
24
-
25
- .football-widget {
26
- background-color: lime;
27
- border: 1px solid green;
28
- padding: 4px; }
29
- .football-widget ul {
30
- list-style-type: none; }
31
14
 
32
15
  .version {
33
16
  text-align: center;
@@ -1,8 +1,6 @@
1
1
 
2
-
3
2
  $base-font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
4
3
 
5
-
6
4
  body
7
5
  {
8
6
  font-family: $base-font-family;
@@ -23,30 +21,6 @@ a {
23
21
  }
24
22
 
25
23
 
26
- .params {
27
- color: green;
28
- font-style: italic;
29
- font-weight: bold;
30
- }
31
-
32
- pre {
33
- background-color: #F3F3F3;
34
- border-bottom: 1px solid #BBBBBB;
35
- border-top: 1px solid #BBBBBB;
36
- padding: 4px;
37
- }
38
-
39
-
40
- .football-widget {
41
- background-color: lime;
42
- border: 1px solid green;
43
- padding: 4px;
44
-
45
- ul {
46
- list-style-type: none;
47
- }
48
- }
49
-
50
24
  /////////////////////////
51
25
  // version / powered_by
52
26
 
@@ -60,4 +34,4 @@ pre {
60
34
  font-size: 12px;
61
35
  color: grey
62
36
  }
63
- }
37
+ }
@@ -1,8 +1,13 @@
1
1
 
2
- module SportDb::Service
2
+ module SportDb
3
+
3
4
 
4
5
  class Server < Sinatra::Base
5
6
 
7
+ def self.banner
8
+ "sportdb-service/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] on Sinatra/#{Sinatra::VERSION} (#{ENV['RACK_ENV']})"
9
+ end
10
+
6
11
  ######
7
12
  # allow cross site json requests (e.g. url posting on rubyflow - avoid crash!!)
8
13
  # see
@@ -11,8 +16,8 @@ class Server < Sinatra::Base
11
16
 
12
17
  disable :protection
13
18
 
14
- PUBLIC_FOLDER = "#{SportDb::Service.root}/lib/sportdb/service/public"
15
- VIEWS_FOLDER = "#{SportDb::Service.root}/lib/sportdb/service/views"
19
+ PUBLIC_FOLDER = "#{SportDb.root}/lib/sportdb/service/public"
20
+ VIEWS_FOLDER = "#{SportDb.root}/lib/sportdb/service/views"
16
21
 
17
22
  puts "[boot] setting sportdb api public folder to: #{PUBLIC_FOLDER}"
18
23
  puts "[boot] setting sportdb api views folder to: #{VIEWS_FOLDER}"
@@ -25,7 +30,7 @@ class Server < Sinatra::Base
25
30
  #####################
26
31
  # Models
27
32
 
28
- include SportDb::Models
33
+ include Models
29
34
 
30
35
  ##################
31
36
  # Helpers
@@ -176,5 +181,4 @@ end
176
181
 
177
182
  end # class Server
178
183
 
179
-
180
- end # module SportDb::Service
184
+ end # module SportDb
@@ -1,8 +1,7 @@
1
1
  <div class='version'>
2
2
  <a href="http://groups.google.com/group/opensport">Questions? Comments?</a> |
3
- <a href="https://github.com/geraldb/world.db">world.db/<%= WorldDB::VERSION %></a>,
4
- <a href="https://github.com/geraldb/sport.db">sport.db/<%= SportDB::VERSION %></a>,
5
- <a href="https://github.com/geraldb/sport.db.api">sport.db.api/<%= SportDB::Service::VERSION %></a> -
3
+ <a href="https://github.com/geraldb/world.db.ruby">world.db/<%= WorldDb::VERSION %></a>,
4
+ <a href="https://github.com/geraldb/sport.db.ruby">sport.db/<%= SportDb::VERSION %></a> -
6
5
  <span>Ruby/<%= "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}/#{RUBY_PLATFORM})" %> on</span>
7
6
  <span>Sinatra/<%= Sinatra::VERSION %> (<%= ENV['RACK_ENV'] %>)</span>
8
7
  </div>
@@ -1,146 +1,6 @@
1
1
  <h1>sport.db HTTP JSON(P) API</h1>
2
2
 
3
- <%= erb :'_football_today' %>
4
-
5
-
6
- <h2>Examples</h2>
7
-
8
- <% example_event_keys = ['world.confed.2013', 'en.2012_13', 'de.2012_13', 'euro.2012', 'world.2010']
9
- example_round_pos = [ 4, 2, 5, 1, 20 ]
10
- example_round_label = [ '4th Round (=> Semi-finals)', '2nd Round', '5th Round', '1st Round', '20th Round (=> Final)' ]
11
- %>
12
-
13
- <h3>List all teams for an event (league+season) <code>/event/<span class='params'>:key</span>/teams</code></h3>
14
-
15
- <table>
16
- <% example_event_keys.each do |event_key|
17
- event = Event.find_by_key!( event_key.tr('_', '/') )
18
- %>
19
- <tr>
20
- <td>
21
- <code>
22
- <a href='<%= url("/event/#{event_key}/teams") %>'>
23
- /event/<span class='params'><%= event_key %></span>/teams
24
- </a>
25
- </code>
26
- </td>
27
- <td>
28
- <%= event.full_title %>
29
- </td>
30
- </tr>
31
- <% end %>
32
- </table>
33
-
34
- <h3>List all rounds for an event (league+season) <code>/event/<span class='params'>:key</span>/rounds</code></h3>
35
-
36
- <table>
37
- <% example_event_keys.each do |event_key|
38
- event = Event.find_by_key!( event_key.tr('_', '/') )
39
- %>
40
- <tr>
41
- <td>
42
- <code>
43
- <a href='<%= url("/event/#{event_key}/rounds") %>'>
44
- /event/<span class='params'><%= event_key %></span>/rounds
45
- </a>
46
- </code>
47
- </td>
48
- <td>
49
- <%= event.full_title %>
50
- </td>
51
- </tr>
52
- <% end %>
53
- </table>
54
-
55
-
56
- <h3>List all rounds for today or a date <code>/rounds/<span class='params'>today|:YYYY.MM.DD</span></code></h3>
57
-
58
- <table>
59
- <tr>
60
- <td>
61
- <code>
62
- <a href='<%= url("/rounds/today") %>'>
63
- /rounds/<span class='params'>today</span>
64
- </a>
65
- </code>
66
- </td>
67
- <td>
68
- All rounds scheduled for today
69
- </td>
70
- </tr>
71
- <tr>
72
- <td>
73
- <code>
74
- <a href='<%= url("/rounds/2013.6.30") %>'>
75
- /rounds/<span class='params'>2013.6.30</span>
76
- </a>
77
- </code>
78
- </td>
79
- <td>
80
- All rounds scheduled for July 30th, 2013
81
- </td>
82
- </tr>
83
- </table>
84
-
85
-
86
-
87
- <h3>List all games in a round for an event (league+season) <code>/event/<span class='params'>:key</span>/round/<span class='params'>:pos|today</code></h3>
88
-
89
-
90
- <table>
91
- <% example_event_keys.each_with_index do |event_key, index|
92
- event = Event.find_by_key!( event_key.tr('_', '/') )
93
- %>
94
- <tr>
95
- <td>
96
- <code>
97
- <a href='<%= url("/event/#{event_key}/round/#{example_round_pos[index]}") %>'>
98
- /event/<span class='params'><%= event_key %></span>/round/<span class='params'><%= example_round_pos[index] %></span>
99
- </a>
100
- </code>
101
- </td>
102
- <td>
103
- <%= event.full_title %> - <%= example_round_label[index] %>
104
- </td>
105
- </tr>
106
- <% end %>
107
-
108
- <tr>
109
- <td>
110
- <code>
111
- <a href='<%= url("/event/de.2013_14/round/today") %>'>
112
- /event/<span class='params'>de.2013_14</span>/round/<span class='params'>today</span>
113
- </a>
114
- </code>
115
- </td>
116
- <td>
117
- Deutsche Bundesliga 2013/14 - all games for today's round (or if no round scheduled for today the last one or if no last one the next upcoming one).
118
- </td>
119
- </tr>
120
- </table>
121
-
122
-
123
-
124
- <%= erb :'_usage' %>
125
-
126
- <%= erb :'_football_live' %>
127
-
128
-
129
- <h2>About</h2>
130
-
131
- <h3>What's <code>sport.db</code>?</h3>
132
-
133
- <p>
134
- A free open sports database &amp; schema. <a href='https://github.com/geraldb/sport.db'>More &raquo;</a>
135
- </p>
136
-
137
- <h3>What's <code>sport.db.api</code>?</h3>
138
-
139
- <p>
140
- A free open source web service in Ruby w/ Sinatra. <a href='https://github.com/geraldb/sport.db.api'>More &raquo;</a>
141
- </p>
142
-
143
3
 
144
4
  <% if params[:debug].present? %>
145
5
  <%= erb :'_debug' %>
146
- <% end %>
6
+ <% end %>