Created
June 9, 2015 15:13
-
-
Save noam87/12a29671a20f279677ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScoreChangeEvents | |
class << self | |
def all | |
{ football: football, soccer: soccer, baseball: baseball } | |
end | |
def save(foo = all) | |
File.write( | |
'foo', | |
"Occurrance Rate:\n\nFootball: #{foo[:football].count} / #{Football::Event.count}\n\nSoccer: #{foo[:soccer].count} / #{Soccer::Event.count}\n\nBaseball: #{foo[:baseball].count} / #{Baseball::Event.count}\n\n```js\n#{JSON.pretty_generate foo}\n```") | |
end | |
def football | |
obj = {} | |
Football::Event.all.each { |e| | |
obj[e.id] = { summaries: e.box_score.score_summaries.map { |s| | |
{ home: s.home_score, away: s.away_score } unless s.home_score == 0 and s.away_score == 0 } | |
} if e.box_score | |
} | |
obj.delete_if { |k,v| v[:summaries].compact.empty? == true } | |
obj.delete_if { |k,v| | |
val = true | |
v[:summaries].each_with_index { |s, i| | |
[:home, :away].each { |k2| | |
if i != 0 | |
val = false if s[k2] < v[:summaries][i - 1][k2] | |
end | |
} | |
} | |
val | |
} | |
obj | |
end | |
def soccer | |
obj = {} | |
Soccer::Event.all.each { |e| | |
obj[e.id] = { action_goals: e.box_score.action_goals.map { |s| | |
{ home: s.home_score_after, away: s.away_score_after } unless (s.home_score_after == 0 and s.away_score_after == 0) or ([s.home_score_after, s.away_score_after].include?(nil)) } | |
} if e.box_score | |
} | |
obj.delete_if { |k,v| v[:action_goals].compact.empty? == true } | |
obj.delete_if { |k,v| | |
val = true | |
v[:action_goals].each_with_index { |s, i| | |
[:home, :away].each { |k2| | |
if i != 0 | |
val = false if s[k2] < v[:action_goals][i - 1][k2] | |
end | |
} | |
} | |
val | |
} | |
obj | |
end | |
def baseball | |
obj = {} | |
Baseball::Event.all.each { |e| | |
obj[e.id] = { play_by_play_events: e.play_by_play_events.map { |s| | |
{ home: s.home_score, away: s.away_score } unless (s.home_score == 0 and s.away_score == 0) or ([s.home_score, s.away_score].include?(nil)) | |
}.compact | |
} if e.play_by_play_events.count > 0 | |
} | |
obj.delete_if { |k,v| v[:play_by_play_events].empty? == true } | |
obj.delete_if { |k,v| | |
val = true | |
v[:play_by_play_events].each_with_index { |s, i| | |
[:home, :away].each { |k2| | |
if i != 0 | |
begin | |
val = false if s[k2] < v[:play_by_play_events][i - 1][k2] | |
rescue | |
binding.pry | |
end | |
end | |
} | |
} | |
val | |
} | |
obj | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Occurrance Rate:
Football: 2 / 13630
http://www.cbssports.com/collegefootball/gametracker/recap/NCAAF_20140913_UK@FLA
http://sports.yahoo.com/news/csu-pueblo-over-sam-houston-030845949--ncaaf.html
Both games happened on same day. Both college games. I don't see mention of nullified score.
Soccer: 0 / 19862
Baseball: 412 / 28721
However, if one looks at the baseball score below (scroll down until you see the commented arrows on the right), it looks more like these occurrences are errors in the data, and not legitimate score nullifications.
Raw