The goal of this Notebook is to parse the execl autolib historic file provided in you autolib account profil. I choose to show 3 different histogram: - time spent in the autolib - rent cost - the distances traveled (as the crow flies) Notebook developped by Olivier Dadoun (March 2015 odadoun@gmail.com,dadoun.net) Do not hesitate if you have any questions or comments Feel free to use, copy or modify this notebook

This is the only variable you need to hack ...

In [48]:
mon_historique = "historique-2015-03-13-22-22-28.xlsx"
#mon_historique ="Ben_historique-2015-03-30-13-31-25.xlsx"
In [49]:
import datetime
import xlrd
In [4]:
%matplotlib inline
In [5]:
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
In [6]:
from geopy.geocoders import Nominatim
from geopy.distance import vincenty
In [50]:
wb = xlrd.open_workbook(mon_historique,encoding_override="utf_16_le")
In [51]:
print wb.sheet_names()
[u'Sheet']

In [52]:
sh = wb.sheet_by_name(u'Sheet')
In [53]:
day = sh.col_values(0)
date = sh.col_values(1)
time = sh.col_values(2)
xls_duration = sh.col_values(3)
name = sh.col_values(4)
street_departure = sh.col_values(5)
street_arrival = sh.col_values(6)
# column 7 is not important 
cost = sh.col_values(8)
In [54]:
#Due to stupid exel date !
#convert in python date more intelligent !
day_time = []
for i in range(1,len(xls_duration)):
    year, month, day, hour, minute, second = xlrd.xldate_as_tuple(xls_duration[i], wb.datemode)
    split_date=date[i].replace("/"," ").split()
    py_date = datetime.datetime(int(split_date[2]), int(split_date[1]), int(split_date[0])\
                                , hour, minute, second)
    day_time.append(py_date)
In [55]:
minute_in_autolib = []
for i in range(len(day_time)):
    minute_in_autolib.append(day_time[i].hour*60. + day_time[i].minute)
In [56]:
geolocator = Nominatim()
time_out=20
location = geolocator.geocode("175 5th Avenue NYC",timeout=time_out)
distance = []
couple_data_arrival = []
couple_data_departure = []
for i in range(1,len(street_departure)):
    position_comma=street_departure[i].find(",")
    #departure
    street_name_departure=street_departure[i][0:position_comma]
    city_name_departure=street_departure[i][position_comma+7:]
    location_departure = geolocator.geocode(street_name_departure+","+city_name_departure,timeout=time_out)

    position_comma=street_arrival[i].find(",")
    #arrival
    street_name_arrival=street_arrival[i][0:position_comma]
    city_name_arrival=street_arrival[i][position_comma+7:]
    location_arrival = geolocator.geocode(street_name_arrival+","+city_name_arrival,timeout=time_out)
    
    if(location_departure != None and location_arrival != None and location_departure != location_arrival ):
        departure=(location_departure.latitude, location_departure.longitude)
        arrival=(location_arrival.latitude, location_arrival.longitude)
        distance.append(vincenty(departure, arrival).kilometers)
        couple_data_departure.append((location_departure.latitude,location_departure.longitude))
        couple_data_arrival.append((location_arrival.latitude,location_arrival.longitude))
#        print street_name_departure,city_name_departure,"--",\
#        street_name_arrival,city_name_arrival,"---",vincenty(departure, arrival).kilometers
In [57]:
def stat(x):
    return sum(x), sum(x)/size(x)

f, axarr = plt.subplots(1,3,figsize=(15,6))
text="Quelques statistiques apres "+ str(size(minute_in_autolib))+" locations autolib."
plt.suptitle(text, size=16)
bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.75)


n, bins, patches = axarr[0].hist(minute_in_autolib, 50, facecolor='green', alpha=0.5)
axarr[0].set_title('Duree des locations')
axarr[0].set_xlabel('minutes')
axarr[0].set_ylabel('Nombre de fois')
text="Duree totale = %.2f mn\nMoyenne = %.2f mn par location"%stat(minute_in_autolib)
axarr[0].text(0.7*max(bins),0.85*max(n), text, ha="center", va="center", size=10, bbox=bbox_props)
                
n, bins, patches = axarr[1].hist(cost[1:], 50, facecolor='red', alpha=0.5)
axarr[1].set_title('Prix (abonnement mensuel non inclus)')
axarr[1].set_xlabel('euros')
text="Depense totale des locations= %.2f euros\nMean = %.2f euros"%stat(cost[1:])
axarr[1].text(0.7*max(bins),0.85*max(n), text, ha="center", va="center", size=10, bbox=bbox_props)

n, bins, patches = axarr[2].hist(distance, 50, facecolor='blue', alpha=0.5)
axarr[2].set_title("Distance parcourue (a vol d\'oiseau)")
axarr[2].set_xlabel("km")
text="Distance totale = %.2f km\nMoyenne = %.2f km par location"%stat(distance)
axarr[2].text(0.7*max(bins),0.85*max(n), text, ha="center", va="center", size=10, bbox=bbox_props)
 
output=mon_historique + ".pdf"
f.savefig(output)
In [74]:
import gmaps
map = gmaps.heatmap(couple_data_departure,point_radius=10., \
                    max_intensity= 20,height='300px', width='600px')
gmaps.display(map)