{{{id=10| obadata is from the 44 bus from Kevin's house, headed eastbound to campus from fremont, 45th and fremonta ave. obadata4 is the route 4 headed from downtown to queen anne, relatively ear the end of the line, near Tim's domicile, queen anne ave and blaine st obadata30 is the route 30 on westlake ave N and crockett st head toward the u district, about halfway through the route /// }}} {{{id=6| %hide obadata = [35000, 24000, 58000, 49000, -23000, -7000, 67000, 14000, 21000, -13000, 33000, 15000, 18000, -2000, 13000, 577000, 566000, 566000, 566000, 566000, 47000, 81000, 54000, 34000, 7000, -32000, 11000, 66000, 11000, 62000, 37000, 21000, -5000, 11000, -68000, -55000, -8000, -53000, -43000, -64000, -248000, -291000, -336000, -79000, -117000, -142000, -219000, -226000, -180000, -194000, 3000, 10000, -165000, -183000, -253000, -147000, -98000, -127000, 21000, 94000, -156000, -276000, -313000, -554000, -34000, -45000, -56000, -84000, -171000, -194000, -189000, -431000, -514000, -338000, -397000, -168000, -194000, -25000, 82000, 43000, -63000, 49000, 30000, -39000, -286000, -315000, -225000, -128000, -521000, 26000, -508000, -564000, -214000, -172000, -324000, -204000, -44000, -12000, -97000, -58000, -76000, -84000, -101000, -51000, -296000, -318000, 19000, -23000, -136000, -164000, 82000, -72000, -83000, -114000, -188000, -86000, -67000, -458000, -499000, -24000, -36000, -169000, -362000, 30000, 35000, -489000, -609000, -684000, 45000, 9000, -129000, -170000, -234000, -364000, 51000, 22000, -40000, -56000, 32000, 38000, -254000, -300000, -314000, -346000, -91000, -176000, -259000, -312000, -180000, -237000, -173000, -244000, -569000, -124000, -189000, -428000, -160000, -188000, -97000, -169000, -55000, -64000, -250000, -281000, -341000, -349000, -326000, -240000, -201000, -400000, -165000, -259000, -339000, -381000, -164000, -177000, 58000, 48000, -149000, -292000, -329000, -411000, -483000, -480000, -244000, -52000, -404000, -451000, -317000, -356000, -293000, -419000, -471000, -70000, -137000, -153000, -263000, -255000, -246000, -248000, 14000, -30000, 98000, 25000, 97000, -46000, -66000, -142000, -70000, -172000, -135000, -82000, -254000, -110000, -118000, 30000, -12000, -86000, -432000, -508000, -56000, -40000, -311000, -365000, -538000, -584000, -684000, -59000, -33000, 170000, 189000, -109000, -90000, -85000, -49000, -226000, -260000, -312000, -312000, -978000] obadata4 = [-14000, -5000, -355000, -367000, -426000, 4000, -150000, -70000, -399000, -994000, -1611000, -738000, -587000, -587000, -635000, -657000, -683000, -1014000, -1014000, -1480000, -1366000, -37000, -40000, 107000, 38000, 49000, -38000, -111000, -15000, -69000, -117000, -135000, -217000, 21000, 2000, -118000, -186000, -315000, -464000, -603000, -724000, -249000, -348000, -146000, -182000, -274000, -261000, -311000, -266000, -382000, -412000, -159000, -504000, -685000, -710000, -777000, -126000, -218000, -306000, 67000, -16000, -300000, -361000, 51000, -110000, -209000, -120000, -221000, -261000, 30000, -98000, -196000, -130000, -296000, -336000, -438000, -133000, -312000, -339000, -397000, -435000, -552000, -132000, -143000, 100000, 71000, 71000, -195000, -246000, -343000, -467000, -331000, -442000, -541000, -34000, -62000, -151000, -244000, -360000, -47000, -99000, -209000, -311000, -161000, -227000, -481000, -600000, -631000, -605000, -741000, -741000, 8000, -83000, -128000, -533000, -623000, -675000, -212000, -293000, -186000, -320000, -265000, -351000, -354000, -432000, -86000, -141000, -187000, -215000] obadata30 = [-88000, -136000, -214000, -138000, -87000, -204000, -290000, -310000, -193000, -547000, -259000, -331000, -390000, -281000, -324000, -393000, -417000, -563000, -502000, -658000, -244000, -290000, -242000, -225000, -258000, -370000, -436000, -86000, -160000, -178000, -167000, -195000, -275000, -438000, -523000, -63000, -646000, 94000, 127000, 113000, -20000, -107000, -230000, -286000, -435000, -94000, -136000, -249000, -272000, -246000, -108000, -218000, -536000, -238000, -284000, -13000, 16000, -69000, -104000, -196000, -317000, -401000, -89000, -94000, 41000, -266000, -284000, -856000, -408000, -401000, -271000, -419000, -571000, 21000, -217000, -332000, -463000, -410000, -374000, -331000, -63000, -203000, -399000, -251000, -334000, -107000, -199000, 16000, 45000, -296000, -272000, -105000, -142000, -92000, 130000, 43000, -477000, -547000, -658000, -335000, -364000, -105000, -229000, -236000, -47000, -39000, -189000, -241000, 77000, -27000, -42000] obadata_cut = [x/1000 for x in obadata] obadata4_cut = [x/1000 for x in obadata4] obadata30_cut = [x/1000 for x in obadata30] /// }}}

Confidence Interval

{{{id=2| @interact def CI(data = input_box(default=obadata, label="Data List", type=list), conflevel = slider(50,100,1, default=90, label="Confidence Level (as %)")): n = len(data) y = mean(data) se = std(data)/sqrt(n) M = RealDistribution('t', n-1) ts = M.cum_distribution_function_inv((conflevel/100 + 1)/2) average = float(sum(data))/float(len(data))/1000 average = round(average, 2) word = "" if average >= 0: word += "seconds early" else: word += "seconds late" print "On average, the bus is %s %s, but..."%(abs(average),word) print left = "" right = "" if N(y-ts*se) >= 0: left += "%s seconds early and "%(round(abs(N(y-ts*se)/1000),2)) else: left += "%s seconds late and "%(round(abs(N(y-ts*se)/1000),2)) if N(y+ts*se) >= 0: right += "%s seconds early."%(round(abs(N(y+ts*se)/1000),2)) else: right += "%s seconds late."%(round(abs(N(y+ts*se)/1000),2)) conf = "%s"%(conflevel) + "%" print "You can be %s confident that your bus will be between %s%s"%(conf, left, right) #return (N(y-ts*se), N(y + ts*se)) /// }}}

Bar Chart

{{{id=3| from sage.plot.bar_chart import BarChart list = obadata i = 0 while i < len(list): list[i] = int(list[i]) i += 1 list2 = [x/1000 for x in list] xlabel = text bar_chart(list2) #hmmm, this kinda sucks for plotting. /// }}}

Histogram

{{{id=4| list = obadata i = 0 while i < len(list): list[i] = int(list[i]) i += 1 list2 = [x/1000 for x in list] finance.TimeSeries(list2).plot_histogram() /// }}}

Route Comparison l

{{{id=5| def compare_routes(rt1=[], rt2=[], rt3=[]): import numpy import pylab pylab.clf() import numpy as np import matplotlib.pyplot as plt def early(ls): return [x for x in ls if x > 0] def late(ls): return [x for x in ls if x <= 0] early1 = early(rt1) early2 = early(rt2) early3 = early(rt3) late1 = late(rt1) late2 = late(rt2) late3 = late(rt3) rtearlymeans = (float(abs(mean(early1))),float(abs(mean(early2))),float(abs(mean(early3)))) rtearlyStd = (float(abs(std(early1, bias=True))),float(std(early2, bias=True)),float(std(early3, bias=True))) rtlatemeans = (float(abs(mean(late1))),float(abs(mean(late2))),float(abs(mean(late3)))) rtlateStd = (float(abs(std(late1, bias=True))),float(std(late2, bias=True)),float(std(late3, bias=True))) plt.clf() N = 3 ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars fig = plt.figure() ax = fig.add_subplot(111) rects1 = ax.bar(ind, rtearlymeans, width, color='orange', yerr=rtearlyStd) rects2 = ax.bar(ind+width, rtlatemeans, width, color='blue', yerr=rtlateStd) # add some ax.set_ylabel('Seconds') ax.set_title('Route Comparisons') ax.set_xticks(ind+width) ax.set_xticklabels( ('The "44"', 'The "4"', 'The "30"') ) ax.legend( (rects1[0], rects2[0]), ('Early', 'Late') ) def autolabel(rects): # attach some text labels for rect in rects: height = rect.get_height() ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height), ha='center', va='bottom') autolabel(rects1) autolabel(rects2) plt.savefig('a.png') pylab.savefig('a.png') compare_routes(obadata_cut, obadata4_cut, obadata30_cut) /// }}} {{{id=11| import time def get_range(filename, start, end): start = time.mktime(time.struct_time((2010, start[0], start[1], start[2], start[3], 0, 0, 0, 1))) end = time.mktime(time.struct_time((2010, end[0], end[1], end[2], end[3], 0, 0,0 ,1))) f = open(filename, 'r') dict = {} for line in f: key = int(line.split(' ')[1]) if start <= key < end: dict[key] = int(line.split(' ')[2].rstrip()) / 1000 return dict /// }}}

Time Interval Based Scatter Plot

{{{id=12| import os,time,matplotlib @interact def plot_range(filename=DATA + 'obadata (1).txt',start_month=range(1,12),start_day=range(1,31),start_hour=range(24),start_min=range(60),end_month=range(1,12),end_day=range(1,31),end_hour=range(24),end_min=range(60)): start = (start_month, start_day, start_hour, start_min) end = (end_month, end_day, end_hour, end_min) dict = get_range(filename, start, end) keys = dict.keys() x=[];y=[] for key in keys: x.append(key);y.append(dict[key]) try: show(scatter_plot([[x,y]],marker='s')) except ValueError: print 'Please enter valid values.' /// }}} {{{id=13| /// }}}