Skip to content

Commit

Permalink
Changes for 2013
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Bottiglieri committed Mar 26, 2013
1 parent 9241f2b commit 3324882
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
48 changes: 45 additions & 3 deletions grabber.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
import twitter
import json
from matchstore import MatchStore
import sys, string, os

min2012 = 158306092244418561 # First meaningful tweet in 2012
mins = {}
mins[2013] = 305870085921320960 # First meaningful tweet in 2013
mins[2012] = 158306092244418561 # First meaningful tweet in 2012
max2011 = 132877548332924929 # Last meaningful tweet in 2011


def get2013MatchData(status) :
#FRCTXDA TY E MC 16 RF 120 BF 96 RA 231 3522 2936 BA 3802 704 4354 RC 40 BC 30 RFP 3 BFP 0 RAS 36 BAS 30 RTS 41 BTS 36
i = status.text.split()
match = {}
match['year'] = 2013
match['event'] = i[0][4:]
match['type'] = i[2]
match['number'] = int(i[4])
match['red_final'] = int(i[6])
match['blue_final'] = int(i[8])
red_teams = [ int(i[10]), int(i[11]), int(i[12]) ]
match['red_alliance'] = red_teams
blue_teams = [ int(i[14]), int(i[15]), int(i[16]) ]
match['blue_alliance'] = blue_teams
match['red_climb'] = int(i[18])
match['blue_climb'] = int(i[20])
match['red_fouls'] = int(i[22])
match['blue_fouls'] = int(i[24])
match['red_auto'] = int(i[26])
match['blue_auto'] = int(i[28])
match['red_teleop'] = int(i[30])
match['blue_teleop'] = int(i[32])
match['t_id'] = s.id
match['date'] = s.created_at
return match

def get2012MatchData(status) :
i = status.text.split()
match = {}
Expand Down Expand Up @@ -55,20 +85,32 @@ def get2011MatchData(status) :
api = twitter.Api()
ms = MatchStore()


running = True
pageLength = 100
i=0
curPage = 1

lastIDFetched = ms.getLatestMatchID()
lastIDFetched = 0
if len(sys.argv) > 1:
possible_year = int(sys.argv[1])
if possible_year in [2011,2012,2013]:
lastIDFetched = mins[possible_year]

if lastIDFetched == 0:
ms.getLatestMatchID()

print "Starting to fetch from Tweet ID: ", lastIDFetched

while running :
statuses = api.GetUserTimeline("frcfms", since_id=lastIDFetched, count=pageLength, page=curPage)
for s in statuses :
if s.id > min2012:
if s.id > mins[2012] and s.id < mins[2013]:
m = get2012MatchData(s)
ms.addMatch(m)
if s.id > mins[2013]:
m = get2013MatchData(s)
ms.addMatch(m)
elif s.id < max2011:
m = get2011MatchData(s)
ms.addMatch(m)
Expand Down
12 changes: 7 additions & 5 deletions opr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import argparse
import sys



# Find a value in a list
def find(f, seq):
"""Return first item in sequence where f(item) == True."""
Expand Down Expand Up @@ -58,9 +60,9 @@ def findOPR(type, event, year):
red = m['red_alliance']

if type == "adjusted" or type == "scalescore":
rf = m['red_final'] - m['red_bonus'] - m['blue_fouls']
bf = m['blue_final'] - m['blue_bonus'] - m['red_fouls']
if type == "scalescore":
rf = m['red_final'] - m['red_climb'] - m['blue_fouls']
bf = m['blue_final'] - m['blue_climb'] - m['red_fouls']
if type == "scalescore" and year == "2102":
rf += m['coopertition'] * 5
bf += m['coopertition'] * 5
else :
Expand Down Expand Up @@ -110,11 +112,11 @@ def findOPR(type, event, year):
conn = pymongo.Connection()

if len(sys.argv) < 3:
year="2012"
year="2013"
else :
year=sys.argv[2]

for t in ['final', 'hybrid', 'teleop', 'fouls', 'bonus', 'adjusted', 'scalescore']:
for t in ['final', 'auto', 'teleop', 'fouls', 'climb', 'adjusted', 'scalescore']:
filename = "out/" + year + "_" + event + "-" + t + ".csv"
print "Finding", t, "OPR score :", filename
oprs = findOPR(t, event, year)
Expand Down

0 comments on commit 3324882

Please sign in to comment.