Skip to content

Instantly share code, notes, and snippets.

@miketheman
Created May 24, 2012 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketheman/2779423 to your computer and use it in GitHub Desktop.
Save miketheman/2779423 to your computer and use it in GitHub Desktop.
Rinxter penalties data study
# Tested with ruby 1.9.3, some issues in prior versions
# ruby magic
require 'json'
require 'net/http'
require 'pp'
# standards
@rx_ds_url = "http://rinxter.net/wftda/ds"
@rx_league = "GGRD"
@rx_league_id = 1
@rx_seasons = ["2010", "2011", "2012"]
@rx_teamNames = ["BROOKLYN", "MANHATTAN", "QUEENS", "BRONX"]
@bk_boutIds1 = []
@bk_boutIds2 = []
def make_api_call(params)
uri = URI(@rx_ds_url)
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
return res.body if res.is_a?(Net::HTTPSuccess)
end
def get_home_bouts(team)
# Get all the team's bouts for the last seasons
@rx_seasons.each do |season|
params = { :leagueId => @rx_league_id,
:season => season,
:type => "boutList"
}
retObj = JSON.load(make_api_call(params))
retObj.each do |entry|
if entry['team1'] == team and entry['sanction'] == "League"
@bk_boutIds1.push("id" => entry['id'], "date" => entry['date'])
elsif entry['team2'] == team and entry['sanction'] == "League"
@bk_boutIds2.push("id" => entry['id'], "date" => entry['date'])
end
end
end
end
# place team name here
get_home_bouts("BRONX")
# struct = {date: 2010-05-01, totMinors: 10, totMajors: 5}
struct = []
@bk_boutIds1.each do |bout|
params = { :boutId => bout['id'] ,
:type => "boutPenaltySummary",
:output => "obj"
}
retObj = JSON.load(make_api_call(params))
struct.push("date" => bout['date'], "totMinors" => retObj[-1]['team1min'], "totMajors" => retObj[-1]['team1maj'])
end
@bk_boutIds2.each do |bout|
params = { :boutId => bout['id'] ,
:type => "boutPenaltySummary",
:output => "obj"
}
retObj = JSON.load(make_api_call(params))
struct.push("date" => bout['date'], "totMinors" => retObj[-1]['team2min'], "totMajors" => retObj[-1]['team2maj'])
end
# Build me some CSV, manually processing in Excel for now
struct.each do |entry|
puts entry['date'] + "," + entry['totMinors'] + "," + entry['totMajors']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment