Skip to content

Instantly share code, notes, and snippets.

@P1n3appl3
Created March 7, 2017 18:45
Show Gist options
  • Save P1n3appl3/90895d2b5586461be63b06fb9878f693 to your computer and use it in GitHub Desktop.
Save P1n3appl3/90895d2b5586461be63b06fb9878f693 to your computer and use it in GitHub Desktop.
Access TBA's api to add up point totals from different sources for FRC SteamWork
import tbapi
# usage:
# pip install tbapi
# replace TEAM_NAME with your team name
# set current date to a string with the format YYYY-MM-DD
# run
# example results with date as "2017-03-06"
# Matches 1840
# fuel 6355 climb 228300 rotors 345540 penalties 29785
#
# Averages
# fuel 3 climb 124 rotors 187 penalties 16
parser = tbapi.TBAParser(TEAM_NAME, "total/average point counter", 1.0)
eventList = parser.get_event_list('2017')
matchCount = 0
totalFuel = 0
totalRotor = 0
totalClimb = 0
totalPentalty = 0
currentDate = "YYYY-MM-DD"
count = 0
for i in eventList:
count += 1
if i.start_date < currentDate:
matches = parser.get_event_matches("2017" + i.event_code)
print i.name
for j in matches:
if j.score_breakdown is not None:
matchCount += 1
scores = j.score_breakdown
for k in ['blue', 'red']:
totalFuel += scores[k]['autoFuelPoints'] + scores[k]['teleopFuelPoints']
totalClimb += scores[k]['teleopTakeoffPoints']
totalRotor += scores[k]['autoRotorPoints'] + scores[k]['teleopRotorPoints']
totalPentalty += scores[k]['foulPoints']
print "\nMatches", matchCount
print "fuel", totalFuel,
print "climb", totalClimb,
print "rotors", totalRotor,
print "penalties", totalPentalty, '\n'
print "Averages"
print "fuel", totalFuel/matchCount,
print "climb", totalClimb/matchCount,
print "rotors", totalRotor/matchCount,
print "penalties", totalPentalty/matchCount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment