Skip to content

Instantly share code, notes, and snippets.

@kachok
Created January 25, 2012 04:03
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 kachok/1674638 to your computer and use it in GitHub Desktop.
Save kachok/1674638 to your computer and use it in GitHub Desktop.
Stats on bikes "hidden" moves in CaBi data
# "hidden" move - bike move started in bike station, different from the one where bike was actually left in previous trip
# 0 ['Duration', 'Start date', 'End date', 'Start station', 'End station', 'Bike#', 'Member Type']
# 1 ['0h 7min. 48sec.', '12/31/2011 23:55', '1/1/2012 0:03', '18th & M St NW (31221)', '10th & U St NW (31111)', 'W01319', 'Registered']
f=open ("2011-1st-quarter.csv")
tracking={}
member_types={}
total=0
mismatch=0
for i, line in enumerate(f):
if i==0:
#skip SCV headers
continue
total=total+1
line=line.rstrip('\n')
duration, start_date, end_date, start_station, end_station, bike, member_type = line.split(',')
if member_type in member_types:
member_types[member_type]=member_types[member_type]+1
else:
member_types[member_type]=1
if bike in tracking:
if tracking[bike]["start_station"]!=end_station:
print bike
print "new ", tracking[bike]["start_date"], tracking[bike]["start_station"]
print "old " ,end_date, end_station
print "------"
#print bike, tracking[bike]["end_station"], start_station
#print bike, {"duration":duration, "start_date":start_date, "end_date":end_date, "start_station":start_station, "end_station":end_station, "member_type":member_type}
#print bike, tracking[bike]
mismatch=mismatch+1
tracking[bike]={"duration":duration, "start_date":start_date, "end_date":end_date, "start_station":start_station, "end_station":end_station, "member_type":member_type}
else:
tracking[bike]={"duration":duration, "start_date":start_date, "end_date":end_date, "start_station":start_station, "end_station":end_station, "member_type":member_type}
#if bike=='W00746':
# print line
print total, mismatch, float(mismatch)/float(total)
print member_types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment