In [1]:
import sys
sys.version
Out[1]:
In [6]:
%matplotlib inline
import random
import sys
import array
import collections
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from django.db.models import Q
import runner
import runner.models
from IPython.display import Markdown as md
name = DerbyEvent.objects.get(id=5).event_name
md("# Results for %s" % name)
AOL (formerly "WEBELOS II")- no enterants this year ### Golden Eagle Pinewood Derby info http://www.goldeneaglekc.org/pinewood-derby
Note there is a $7 fee to cover their costs (includes a fee the school charges for janitorial services)
There were a couple of glitches that slowed things down, both addressed for next year:
Here are some photos from the race and workshop. I only took a few at the races, no time! https://photos.app.goo.gl/9X3RBULjGHX7uWWg1
In [375]:
race_key = {}
# print('Race id:name')
for race in Race.objects.all():
race_key[race.name] = race.id
# print(f'{race.id}:{race.name}')
chase_cars = []
# print("\nChase cars:")
for car in Racer.objects.filter(name__contains='Chase'):
chase_cars.append(car.id)
# print(car)
In [377]:
def get_lane_times(race_id):
''' Return dict of {racer_id: [lane, secs]}'''
if race_id is None:
print('race_ids must be an int')
return None
racer = collections.defaultdict(list)
race = Race.objects.get(id=race_id)
for run in race.run_set.all():
for rp in run.runplace_set.all():
racer[rp.racer_id].append([rp.lane, rp.seconds])
return racer
def plot_by_lane(ax, results, title):
for r, v in results.items():
name = Racer.objects.get(id=r).name
data = zip(*v) # unzip, of sorts
l = list(data)
x = list(l[0])
y = list(l[1])
_ = ax.scatter(x, y, label=name)
_ = ax.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.)
_ = ax.set_title(f'Racer Finish Times by Lane = {title}')
_ = ax.set_xlabel('lane')
_ = ax.set_ylabel('secs')
_ = ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
def plot_by_racer(ax, results, title):
c = range(len(results.keys()))
for r, v in results.items():
x = []
y = []
name = Racer.objects.get(id=r).name
for t in v:
x.append(r)
y.append(t[1])
_ = ax.scatter(x, y, label=f'{r}:{name}')
_ = ax.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.)
_ = ax.set_title(f'Racer Finish Times by Car = {title}')
_ = ax.set_xlabel('racer')
_ = ax.set_ylabel('secs')
_ = ax.set_xticks(x, minor=True)
_ = ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
fig, ax = plt.subplots(nrows=4, ncols=2, figsize=(20, 25))
###################################################################
event = 'Cub Primary Races'
racer = get_lane_times(race_key[event])
# Add the races we ran with just Colt's car
r2 = get_lane_times(race_key["Colt's Races"])
# remove the 5 ghost cars from the results
for id in chase_cars:
_ = r2.pop(id, None)
racer.update(r2)
plot_by_lane(ax[0,0], racer, event)
plot_by_racer(ax[0,1], racer, event)
###################################################################
event = 'Wildcard Round'
racer = get_lane_times(race_key[event])
plot_by_lane(ax[1,0], racer, event)
plot_by_racer(ax[1,1], racer, event)
###################################################################
event = 'Pack Finals'
racer = get_lane_times(race_key[event])
plot_by_lane(ax[2,0], racer, event)
plot_by_racer(ax[2,1], racer, event)
###################################################################
event = 'Open Division'
racer = get_lane_times(race_key[event])
plot_by_lane(ax[3,0], racer, event)
plot_by_racer(ax[3,1], racer, event)
###################################################################
_ = fig.suptitle(f'Pack 180 Pinewood Derby, January 20, 2018')
_ = plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,
wspace=0.35)
Here are some additional notes and numbers:
Lanes in use: 6
Number of race participants: 13
Overall race stats:
Fastest run time: 2.832 seconds
Fastest run speed: 345 MPH
Average run time: 3.051 seconds
Average run speed: 322 MPH
Slowest run time: 4.478 seconds
Slowest run speed: 217 MPH
Late entrant races against 5 'ghost cars'
Lanes in use: 6
Number of race participants: 6
Overall race stats:
Fastest run time: 2.884 seconds
Fastest run speed: 339 MPH
Average run time: 3.146 seconds
Average run speed: 313 MPH
Slowest run time: 3.665 seconds
Slowest run speed: 270 MPH
One run
Lanes in use: 4
Number of race participants: 4
Overall race stats:
Fastest run time: 2.931 seconds
Fastest run speed: 335 MPH
Average run time: 2.992 seconds
Average run speed: 328 MPH
Slowest run time: 3.093 seconds
Slowest run speed: 318 MPH
Lanes in use: 5
Number of race participants: 5
Overall race stats:
Fastest run time: 2.855 seconds
Fastest run speed: 343 MPH
Average run time: 2.914 seconds
Average run speed: 336 MPH
Slowest run time: 3.007 seconds
Slowest run speed: 327 MPH
Lanes in use: 6
Number of race participants: 6
Overall race stats:
Fastest run time: 2.928 seconds
Fastest run speed: 335 MPH
Average run time: 2.986 seconds
Average run speed: 329 MPH
Slowest run time: 3.060 seconds
Slowest run speed: 322 MPH