Skip to content

Instantly share code, notes, and snippets.

@PeterJCLaw
Created May 13, 2012 13:22
Show Gist options
  • Select an option

  • Save PeterJCLaw/2688452 to your computer and use it in GitHub Desktop.

Select an option

Save PeterJCLaw/2688452 to your computer and use it in GitHub Desktop.
Student Robotics' Priate Plunder Results Analyser
#!/usr/bin/env python
import json
import numpy
with open('dump.json') as f:
data = json.load(f)
BASE = 'org.srobo'
class Best(object):
def __init__(self):
self.teams = set()
self.value = None
def update(self, maybe, team):
if self.value < maybe:
self.value = maybe
self.teams = set([team])
elif self.value == maybe:
self.teams.add(team)
def __repr__(self):
if len(self.teams) > 1:
last = self.teams.pop()
teams = ", ".join(self.teams) + " & " + last
else:
teams = self.teams.pop()
return str(self.value) + " by " + teams
matchList = data[BASE+'.matches']['value']
scoreData = dict()
missingData = []
for mid in xrange(len(matchList)):
match = json.loads(matchList[mid])
teams = match['teams']
for zone in xrange(len(teams)):
team = teams[zone]
if not scoreData.has_key(team):
scoreData[team] = []
key = BASE+'.scores.match.{0}.{1}'.format(mid, zone)
try:
score = data[key]['value']
except KeyError:
missingData.append(key)
continue
# print score
scoreData[team].append(score)
#print scoreData
print "Missing Data:", missingData
allGamePoints = []
maxBuckets = Best()
maxBucketTokens = Best()
maxRobotTokens = Best()
highestGamePoints = Best()
highestAvgGamePoints = Best()
def scoresList(data, which):
return [int(s[which]) for s in data]
for team, scores in scoreData.iteritems():
gamePoints = scoresList(scores, 'game_points')
buckets = scoresList(scores, 'nbuckets')
robotTokens = scoresList(scores, 'trobot')
bucketTokens = scoresList(scores, 'tbucket')
avgGamePoints = numpy.average(gamePoints)
stdDevPoints = numpy.std(gamePoints)
allGamePoints += gamePoints
maxBuckets.update(max(buckets), team)
maxBucketTokens.update(max(bucketTokens), team)
maxRobotTokens.update(max(robotTokens), team)
highestGamePoints.update(max(gamePoints), team)
highestAvgGamePoints.update(avgGamePoints, team)
print team, "\t", gamePoints, "\t: %.3f @ %.3f" % (avgGamePoints, stdDevPoints)
gameCount = ( len(matchList) * 4 - len(missingData) ) / 4.0
print "All Game Points:", sum(allGamePoints)
print "Game Count: %d" % gameCount
print "Average Game Points: %.3f" % numpy.average(allGamePoints)
print "Std. dev. of Game Points: %.3f" % numpy.std(allGamePoints)
#print "Most Buckets in a Game:", maxBuckets
print "Most Tokens in a Bucket:", maxBucketTokens
print "Most Tokens in a Robot:", maxRobotTokens
print "Highest Game Points:", highestGamePoints
print "Highest Average Game Points:", highestAvgGamePoints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment