Skip to content

Instantly share code, notes, and snippets.

@AlphaSheep
Last active July 20, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlphaSheep/5b8c3fdbab93904f6eac to your computer and use it in GitHub Desktop.
Save AlphaSheep/5b8c3fdbab93904f6eac to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
'''
A graph generator for Rubik's cube times.
This code is a mess. It was never supposed to get this long. I'm sorry.
Copyright (c) 2015 Brendan Gray
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty.
'''
import pylab
from datetime import datetime
def d(datestr):
return datetime.strptime(datestr, "%Y/%m/%d %H:%M:%S")
def t(timestr):
return datetime.strptime(timestr, "%M:%S.%f")
dates = []
mean100dates = []
mean1000dates = []
ao5dates = []
ao12dates = []
singles = []
ao5 = []
ao12 = []
mean100 = []
mean1000 = []
pb_single = []
pb_Ao5 = []
pb_Ao12 = []
with open("times.tsv") as timeFile:
rawData = timeFile.readlines()
for line in rawData:
elements = line.strip("\n").split("\t")
if len(elements[0])>0:
date = datetime.strptime(elements[0], "%Y/%m/%d %H:%M:%S")
dates.append(date)
singles.append(datetime.strptime(elements[1], "%M:%S.%f"))
pb_single.append(datetime.strptime(elements[6], "%M:%S.%f"))
if len(elements[7])>0:
ao5dates.append(date)
ao5.append(datetime.strptime(elements[2], "%M:%S.%f"))
pb_Ao5.append(datetime.strptime(elements[7], "%M:%S.%f"))
if len(elements[8])>0:
ao12dates.append(date)
ao12.append(datetime.strptime(elements[3], "%M:%S.%f"))
pb_Ao12.append(datetime.strptime(elements[8], "%M:%S.%f"))
if len(elements[4])>0:
mean100dates.append(date)
mean100.append(datetime.strptime(elements[4], "%M:%S.%f"))
if len(elements[5])>0:
mean1000dates.append(date)
mean1000.append(datetime.strptime(elements[5], "%M:%S.%f"))
compDates = ["2014/11/23 10:00:00",
"2014/11/23 13:00:00",
"2015/02/21 11:00:00",
"2015/03/28 14:00:00",
"2015/03/28 16:00:00",
"2015/06/27 12:00:00",
"2015/06/27 16:00:00",
"2015/08/08 11:00:00",
"2015/08/08 14:00:00",
"2015/08/08 16:00:00",
"2015/08/29 10:00:00",
"2015/08/29 15:00:00",
"2015/11/29 10:00:00",
"2015/11/29 13:00:00",
"2015/12/06 10:00:00",
"2015/12/06 13:00:00",
"2015/12/06 16:00:00",
"2016/02/13 10:00:00",
"2016/06/19 10:00:00",
"2016/06/19 13:00:00",
"2016/06/26 10:00:00",
"2016/06/26 13:00:00",
"2016/06/26 16:00:00"]
compTimes = ["0:34.55", "0:33.08", "0:45.96", "0:37.69", "0:24.88",
"0:32.00", "0:30.34", "0:27.71", "0:25.36", "0:26.75",
"0:40.86", "0:25.81", "0:25.44", "0:32.08", "0:36.50",
"0:24.81", "0:28.47", "0:27.86", "0:22.81", "0:31.94",
"0:24.25", "0:25.81", "0:29.81", "0:26.11", "0:25.69",
"0:31.16", "0:21.34", "0:22.90", "0:23.09", "0:27.25",
"0:25.05", "0:20.97", "0:22.41", "0:21.77", "0:22.50",
"0:21.43", "0:19.77", "0:22.53", "0:23.15", "0:22.21",
"0:22.72", "0:31.68", "0:21.31", "0:15.71", "0:21.05",
"0:20.41", "0:19.93", "0:25.16", "0:20.05", "0:19.83",
"0:21.61", "0:22.68", "0:20.38", "0:17.38", "0:24.54",
"0:22.47", "0:19.96", "0:19.30", "0:24.13", "0:20.91",
"0:23.27", "0:18.09", "0:15.30", "0:19.05", "0:18.52",
"0:23.58", "0:20.43", "0:18.63", "0:20.31", "0:26.90",
"0:20.65", "0:17.65", "0:16.13", "0:22.34", "0:20.72",
"0:22.28", "0:19.33", "0:18.53", "0:19.13", "0:23.96",
"0:27.41", "0:24.94", "0:23.03", "0:17.86", "0:17.93",
"0:21.88", "0:21.58", "0:19.41", "0:19.52", "0:16.77",
"0:20.55", "0:27.16", "0:19.09", "0:17.68", "0:18.47",
"0:19.05", "0:23.19", "0:21.78", "0:19.65", "0:22.28",
"0:21.88", "0:24.09", "0:16.34", "0:19.97", "0:19.25",
"0:22.53", "0:19.93", "0:19.47", "0:21.22", "0:22.13",
"0:18.61", "0:17.66", "0:15.03", "0:23.31", "0:24.58"]
# "0:.", "0:.", "0:.", "0:.", "0:.",
while len(compDates)<len(compTimes):
compDates.append('')
for i in range(len(compTimes)-1,-1,-1):
compDates[i] = d(compDates[i//5])
compTimes[i] = t(compTimes[i])
fig = pylab.figure()
fig.patch.set_facecolor([.1,.1,.1])
graylevel = 0.5
singlecol = [0,1,0]
#pylab.plot(dates, singles,'x',color=singlecol, label="3x3 Single times")
pylab.plot(dates, singles,'.',mfc=singlecol, mec=[0,0,0], label="Single times", alpha=0.15)
pylab.plot(mean100dates,mean100,'-', color=[0,1,0], linewidth=3, label="Mean of 100")
pylab.plot(mean1000dates,mean1000,'-', color=[1,0,0], linewidth=2, label="Mean of 1000")
pylab.plot(dates,pb_single,'-', color=[0,1,.5], linewidth=1, label="Best Single")
#pylab.plot(ao5dates,ao5,'g.', linewidth=1, label="3x3 Avg of 5")
#pylab.plot(ao12dates,ao12,'g--', linewidth=1, label="3x3 Avg of 12")
pylab.plot(ao5dates,pb_Ao5,'b-', linewidth=1, label="3x3 PB Avg of 5")
#pylab.plot(ao12dates,pb_Ao12,'g-', linewidth=1, label="3x3 PB Avg of 12")
pylab.plot(compDates,compTimes,'o',mfc=[1,.5,0], mec="black", label="3x3 Official competition times")
#pylab.annotate('OCLL+CPLL+EPLL', xy=(d("2014/07/05 12:00:00"),t("1:15.00")), xytext=(d("2014/08/05 12:00:00"),t("1:20.00")),
# arrowprops=dict(arrowstyle="simple", fc="white"), ha="center", va="center",
# bbox=dict(boxstyle="square",fc="white"))
#pylab.annotate('OCLL+PLL', xy=(d("2014/08/20 12:00:00"),t("0:48.00")), xytext=(d("2014/08/15 12:00:00"),t("1:00.00")),
# arrowprops=dict(arrowstyle="simple", fc="white"), ha="center", va="center",
# bbox=dict(boxstyle="square",fc="white"))
#pylab.annotate('COLL+EPLL', xy=(d("2015/02/15 12:00:00"),t("0:28.00")), xytext=(d("2015/01/20 12:00:00"),t("0:50.00")),
# arrowprops=dict(arrowstyle="simple", fc="white"), ha="center", va="center",
# bbox=dict(boxstyle="square",fc="white"))
if False:
pylab.annotate('Johannesburg 2014', xy=(d("2014/11/23 12:00:00"),t("0:22.00")), xytext=(d("2014/11/23 12:00:00"),t("0:16.00")),
arrowprops=dict(arrowstyle="wedge", fc=[0.5,0.5,0.5]), ha="center", va="center",
bbox=dict(boxstyle="round4",fc=[.3,.3,.3],alpha=0.7), color=[1,1,1])
pylab.annotate('Pops Toys\nSummer 2015', xy=(d("2015/02/21 12:00:00"),t("0:20.00")), xytext=(d("2015/02/01 12:00:00"),t("0:10.00")),
arrowprops=dict(arrowstyle="wedge", fc=[0.5,0.5,0.5]), ha="center", va="center",
bbox=dict(boxstyle="round4",fc=[.3,.3,.3],alpha=0.7), color=[1,1,1])
pylab.annotate('Tuks Open 2015', xy=(d("2015/03/28 12:00:00"),t("0:20.00")), xytext=(d("2015/04/05 12:00:00"),t("0:05.00")),
arrowprops=dict(arrowstyle="wedge", fc=[0.5,0.5,0.5]), ha="center", va="center",
bbox=dict(boxstyle="round4",fc=[.3,.3,.3],alpha=0.7), color=[1,1,1])
pylab.annotate('Tuks Winter\n2015', xy=(d("2015/06/27 12:00:00"),t("0:19.00")), xytext=(d("2015/06/15 12:00:00"),t("0:10.00")),
arrowprops=dict(arrowstyle="wedge", fc=[0.5,0.5,0.5]), ha="center", va="center",
bbox=dict(boxstyle="round4",fc=[.3,.3,.3],alpha=0.7), color=[1,1,1])
pylab.annotate('Pretoria\nScience\nWeek 2015', xy=(d("2015/08/08 12:00:00"),t("0:14.00")), xytext=(d("2015/08/10 12:00:00"),t("0:04.00")),
arrowprops=dict(arrowstyle="wedge", fc=[0.5,0.5,0.5]), ha="center", va="center",
bbox=dict(boxstyle="round4",fc=[.3,.3,.3],alpha=0.7), color=[1,1,1])
pylab.grid('on')
leg = pylab.legend(loc="lower left", fontsize=9)#, fancybox=True)
leg.get_frame().set_facecolor([.3,.3,.3])
leg.get_frame().set_alpha(0.5)
for text in leg.get_texts():
text.set_color("white")
pylab.grid(b=True, which='major', color=[.3,.3,.3], linestyle='-', linewidth=1)
pylab.grid(b=True, which='minor', color=[.3,.3,.3], linestyle=':')
ax1 = pylab.gca()
ax1.set_axis_bgcolor([0.05,0.05,0.05])
ax1.xaxis.set_major_formatter(pylab.DateFormatter('%b %Y'))
ax1.xaxis.set_major_locator(pylab.MonthLocator(interval=4))
ax1.xaxis.set_minor_formatter(pylab.DateFormatter(''))
ax1.xaxis.set_minor_locator(pylab.MonthLocator(interval=1))
ax1.yaxis.set_major_formatter(pylab.DateFormatter('%M:%S.00'))
ax1.yaxis.set_major_locator(pylab.SecondLocator(interval=10))
ax1.yaxis.set_minor_formatter(pylab.DateFormatter(''))
ax1.yaxis.set_minor_locator(pylab.SecondLocator(interval=2))
dateLimits = [d("2014/06/01 12:00:00"),d("2016/08/01 12:00:00")]
pylab.ylim([t("0:00.00"),t("1:00.00")])
pylab.xlim(dateLimits)
ax2 = pylab.gcf().add_subplot(111, sharey=ax1, frameon=False)
ax2.yaxis.tick_right()
ax2.xaxis.set_ticks([])
ax1.tick_params(axis='both', which='major', labelsize=9, colors="white")
ax1.tick_params(axis='both', which='minor', labelsize=9, colors="white")
ax2.tick_params(axis='both', which='major', labelsize=9, colors="white")
ax2.tick_params(axis='both', which='minor', labelsize=9, colors="white")
fig.savefig('times-jul2016.png', facecolor=fig.get_facecolor(), edgecolor='none')
#pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment