Skip to content

Instantly share code, notes, and snippets.

@willhardy
Created July 23, 2011 12:28
Show Gist options
  • Save willhardy/1101370 to your computer and use it in GitHub Desktop.
Save willhardy/1101370 to your computer and use it in GitHub Desktop.
Cadel versus Schleck
After 167 of 167 riders:
Andy Schleck's predicted time is 60:05 (based on 2010 TDF ride for yellow, mean - 0.5 std.dev)
Cadel's predicted time is 58:22 (based on 2008 TDF ride for yellow, mean - 1.3 std.dev)
Cadel would be faster by 1:43
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from math import sqrt
from urllib2 import urlopen
def meanstdv(x):
""" Returns the mean and standard deviation of the given values.
From <http://www.physics.rutgers.edu/~masud/computing/WPark_recipes_in_python.html>
"""
n, mean, std = len(x), 0, 0
for a in x:
mean = mean + a
mean = mean / float(n)
for a in x:
std = std + (a - mean)**2
std = sqrt(std / float(n-1))
return mean, std
def secs(x):
if ":" in x:
h,m,s = x.split(":")
return int(h,10)*3600 + int(m,10)*60 + int(s,10)
def schleck(mean,std):
return int(mean - (0.5 * std))
def cadel(mean,std):
return int(mean - (1.3 * std))
def get_current_times():
f = urlopen("http://www.letour.fr/2011/TDF/LIVE/us/2000/chrono/25.html")
return [secs(x[28:-6]) for x in f.readlines() if 'col_5' in x][2:]
times = get_current_times()
mean, stddev = meanstdv(times)
st = schleck(mean, stddev)
cd = cadel(mean, stddev)
print "After %d of 167 riders:" % len(times)
print " Andy Schleck's predicted time is %d:%02d (based on 2010 TDF ride for yellow, mean - 0.5 std.dev)" % divmod(st, 60)
print " Cadel's predicted time is %d:%02d (based on 2008 TDF ride for yellow, mean - 1.3 std.dev)" % divmod(cd, 60)
print " Cadel would be faster by %d:%02d" % divmod(st - cd, 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment