In [61]:
import emission.storage.decorations.location_queries as lq

In [62]:
reload(lq)


Out[62]:
<module 'emission.storage.decorations.location_queries' from '/Users/shankari/e-mission/e-mission-server/emission/storage/decorations/location_queries.py'>

In [63]:
%matplotlib inline

In [64]:
lq.get_uuid_list()


Out[64]:
[UUID('0763de67-f61e-3f5d-90e7-518e69793954'),
 UUID('f955cff1-8fb8-3b42-8776-6d8874e5b90a'),
 UUID('b0d937d0-70ef-305e-9563-440369012b39')]

In [65]:
import datetime as pydt

In [66]:
import pytz

In [67]:
get_dt = lambda date: pydt.datetime(2015,7,date,tzinfo=pytz.timezone("America/Los_Angeles"))

In [68]:
import emission.analysis.plotting.leaflet_osm.our_plotter as lo

In [78]:
reload(lo)


Out[78]:
<module 'emission.analysis.plotting.leaflet_osm.our_plotter' from '/Users/shankari/e-mission/e-mission-server/emission/analysis/plotting/leaflet_osm/our_plotter.py'>

In [79]:
def get_map_list(user_id, loc_filter, start_dt, end_dt):
    df = lq.get_plottable_df(user_id, loc_filter, start_dt, end_dt)
    sp = lq.get_potential_split_index(df)
    print df.formatted_time.iloc[sp]
    return lo.get_map_list(df, sp)

In [80]:
my_time_filter_map_list_21 = get_map_list(lq.get_uuid_list()[0], "time", get_dt(21), get_dt(22))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437465600000.0}}, {'data.mTime': {'$lt': 1437552000000.0}}], 'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), 'metadata.filter': 'time'} 
0      2015-07-21 08:22:15
484    2015-07-21 12:30:27
494    2015-07-21 13:21:30
523    2015-07-21 13:30:29
641    2015-07-21 14:41:11
923    2015-07-21 15:46:13
935    2015-07-21 15:54:49
1030   2015-07-21 17:38:30
1040   2015-07-21 18:07:49
1080   2015-07-21 18:19:38
1091   2015-07-21 18:47:23
1104   2015-07-21 19:00:12
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-21 08:22:15 to 2015-07-21 12:30:27 because start = 0 and end = 484
Considering trip from 2015-07-21 12:30:27 to 2015-07-21 13:21:30 because start = 484 and end = 494
Considering trip from 2015-07-21 13:21:30 to 2015-07-21 13:30:29 because start = 494 and end = 523
Considering trip from 2015-07-21 13:30:29 to 2015-07-21 14:41:11 because start = 523 and end = 641
Considering trip from 2015-07-21 14:41:11 to 2015-07-21 15:46:13 because start = 641 and end = 923
Considering trip from 2015-07-21 15:46:13 to 2015-07-21 15:54:49 because start = 923 and end = 935
Considering trip from 2015-07-21 15:54:49 to 2015-07-21 17:38:30 because start = 935 and end = 1030
Considering trip from 2015-07-21 17:38:30 to 2015-07-21 18:07:49 because start = 1030 and end = 1040
Considering trip from 2015-07-21 18:07:49 to 2015-07-21 18:19:38 because start = 1040 and end = 1080
Considering trip from 2015-07-21 18:19:38 to 2015-07-21 18:47:23 because start = 1080 and end = 1091
Considering trip from 2015-07-21 18:47:23 to 2015-07-21 19:00:12 because start = 1091 and end = 1104

In [81]:
my_dist_filter_map_list_21 = get_map_list(lq.get_uuid_list()[0], "distance", get_dt(21), get_dt(22))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437465600000.0}}, {'data.mTime': {'$lt': 1437552000000.0}}], 'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), 'metadata.filter': 'distance'} 
0     2015-07-21 08:22:15
1     2015-07-21 08:46:30
103   2015-07-21 12:30:27
106   2015-07-21 13:21:30
112   2015-07-21 13:30:29
145   2015-07-21 14:41:11
213   2015-07-21 15:46:13
216   2015-07-21 15:54:49
235   2015-07-21 17:38:30
237   2015-07-21 18:07:49
245   2015-07-21 18:19:38
247   2015-07-21 18:47:23
251   2015-07-21 19:00:12
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-21 08:22:15 to 2015-07-21 08:46:30 because start = 0 and end = 1
Ignoring trip from 2015-07-21 08:22:15 to 2015-07-21 08:46:30 because start = 0 and end = 1
Considering trip from 2015-07-21 08:46:30 to 2015-07-21 12:30:27 because start = 1 and end = 103
Considering trip from 2015-07-21 12:30:27 to 2015-07-21 13:21:30 because start = 103 and end = 106
Ignoring trip from 2015-07-21 12:30:27 to 2015-07-21 13:21:30 because start = 103 and end = 106
Considering trip from 2015-07-21 13:21:30 to 2015-07-21 13:30:29 because start = 106 and end = 112
Considering trip from 2015-07-21 13:30:29 to 2015-07-21 14:41:11 because start = 112 and end = 145
Considering trip from 2015-07-21 14:41:11 to 2015-07-21 15:46:13 because start = 145 and end = 213
Considering trip from 2015-07-21 15:46:13 to 2015-07-21 15:54:49 because start = 213 and end = 216
Ignoring trip from 2015-07-21 15:46:13 to 2015-07-21 15:54:49 because start = 213 and end = 216
Considering trip from 2015-07-21 15:54:49 to 2015-07-21 17:38:30 because start = 216 and end = 235
Considering trip from 2015-07-21 17:38:30 to 2015-07-21 18:07:49 because start = 235 and end = 237
Ignoring trip from 2015-07-21 17:38:30 to 2015-07-21 18:07:49 because start = 235 and end = 237
Considering trip from 2015-07-21 18:07:49 to 2015-07-21 18:19:38 because start = 237 and end = 245
Considering trip from 2015-07-21 18:19:38 to 2015-07-21 18:47:23 because start = 245 and end = 247
Ignoring trip from 2015-07-21 18:19:38 to 2015-07-21 18:47:23 because start = 245 and end = 247
Considering trip from 2015-07-21 18:47:23 to 2015-07-21 19:00:12 because start = 247 and end = 251

In [82]:
my_dist_filter_map_list_22 = get_map_list(lq.get_uuid_list()[0], "distance", get_dt(22), get_dt(23))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437552000000.0}}, {'data.mTime': {'$lt': 1437638400000.0}}], 'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), 'metadata.filter': 'distance'} 
0     2015-07-22 08:14:53
59    2015-07-22 09:09:00
87    2015-07-22 09:26:56
90    2015-07-22 13:16:38
122   2015-07-22 14:41:15
128   2015-07-22 14:51:49
169   2015-07-22 16:02:29
172   2015-07-22 16:08:17
191   2015-07-22 17:51:17
195   2015-07-22 18:09:52
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-22 08:14:53 to 2015-07-22 09:09:00 because start = 0 and end = 59
Considering trip from 2015-07-22 09:09:00 to 2015-07-22 09:26:56 because start = 59 and end = 87
Considering trip from 2015-07-22 09:26:56 to 2015-07-22 13:16:38 because start = 87 and end = 90
Ignoring trip from 2015-07-22 09:26:56 to 2015-07-22 13:16:38 because start = 87 and end = 90
Considering trip from 2015-07-22 13:16:38 to 2015-07-22 14:41:15 because start = 90 and end = 122
Considering trip from 2015-07-22 14:41:15 to 2015-07-22 14:51:49 because start = 122 and end = 128
Considering trip from 2015-07-22 14:51:49 to 2015-07-22 16:02:29 because start = 128 and end = 169
Considering trip from 2015-07-22 16:02:29 to 2015-07-22 16:08:17 because start = 169 and end = 172
Ignoring trip from 2015-07-22 16:02:29 to 2015-07-22 16:08:17 because start = 169 and end = 172
Considering trip from 2015-07-22 16:08:17 to 2015-07-22 17:51:17 because start = 172 and end = 191
Considering trip from 2015-07-22 17:51:17 to 2015-07-22 18:09:52 because start = 191 and end = 195

In [83]:
my_time_filter_map_list_22 = get_map_list(lq.get_uuid_list()[0], "time", get_dt(22), get_dt(23))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437552000000.0}}, {'data.mTime': {'$lt': 1437638400000.0}}], 'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), 'metadata.filter': 'time'} 
0     2015-07-22 08:14:53
181   2015-07-22 13:16:38
257   2015-07-22 14:41:15
372   2015-07-22 16:02:29
431   2015-07-22 17:51:17
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-22 08:14:53 to 2015-07-22 13:16:38 because start = 0 and end = 181
Considering trip from 2015-07-22 13:16:38 to 2015-07-22 14:41:15 because start = 181 and end = 257
Considering trip from 2015-07-22 14:41:15 to 2015-07-22 16:02:29 because start = 257 and end = 372
Considering trip from 2015-07-22 16:02:29 to 2015-07-22 17:51:17 because start = 372 and end = 431

In [84]:
import emission.analysis.plotting.leaflet_osm.ipython_helper as ipy

In [85]:
reload(ipy)


Out[85]:
<module 'emission.analysis.plotting.leaflet_osm.ipython_helper' from '/Users/shankari/e-mission/e-mission-server/emission/analysis/plotting/leaflet_osm/ipython_helper.pyc'>

In [86]:
my_zippedMaps_21 = zip(my_time_filter_map_list_21, my_dist_filter_map_list_21)
ipy.inline_maps(my_zippedMaps_21, len(my_zippedMaps_21), 2)


Out[86]:

In [17]:
my_zippedMaps_22 = zip(my_time_filter_map_list_22, my_dist_filter_map_list_22)
ipy.inline_maps(my_zippedMaps_22, len(my_zippedMaps_22), 2)


Out[17]:

In [18]:
tom_time_filter_map_list_22 = get_map_list(lq.get_uuid_list()[2], "time", get_dt(22), get_dt(23))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437552000000.0}}, {'data.mTime': {'$lt': 1437638400000.0}}], 'user_id': UUID('b0d937d0-70ef-305e-9563-440369012b39'), 'metadata.filter': 'time'} 
0     2015-07-22 08:05:53
10    2015-07-22 08:26:15
31    2015-07-22 08:40:35
74    2015-07-22 17:47:30
114   2015-07-22 18:40:26
138   2015-07-22 23:14:15
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-22 08:05:53 to 2015-07-22 08:26:15 because start = 0 and end = 10
Considering trip from 2015-07-22 08:26:15 to 2015-07-22 08:40:35 because start = 10 and end = 31
Considering trip from 2015-07-22 08:40:35 to 2015-07-22 17:47:30 because start = 31 and end = 74
Considering trip from 2015-07-22 17:47:30 to 2015-07-22 18:40:26 because start = 74 and end = 114
Considering trip from 2015-07-22 18:40:26 to 2015-07-22 23:14:15 because start = 114 and end = 138

In [19]:
tom_distance_filter_map_list_22 = get_map_list(lq.get_uuid_list()[2], "distance", get_dt(22), get_dt(23))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437552000000.0}}, {'data.mTime': {'$lt': 1437638400000.0}}], 'user_id': UUID('b0d937d0-70ef-305e-9563-440369012b39'), 'metadata.filter': 'distance'} 
0    2015-07-22 08:05:53
2    2015-07-22 08:26:15
14   2015-07-22 08:40:35
23   2015-07-22 08:51:06
29   2015-07-22 17:47:30
48   2015-07-22 18:40:26
58   2015-07-22 23:14:15
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-22 08:05:53 to 2015-07-22 08:26:15 because start = 0 and end = 2
Ignoring trip from 2015-07-22 08:05:53 to 2015-07-22 08:26:15 because start = 0 and end = 2
Considering trip from 2015-07-22 08:26:15 to 2015-07-22 08:40:35 because start = 2 and end = 14
Considering trip from 2015-07-22 08:40:35 to 2015-07-22 08:51:06 because start = 14 and end = 23
Considering trip from 2015-07-22 08:51:06 to 2015-07-22 17:47:30 because start = 23 and end = 29
Considering trip from 2015-07-22 17:47:30 to 2015-07-22 18:40:26 because start = 29 and end = 48
Considering trip from 2015-07-22 18:40:26 to 2015-07-22 23:14:15 because start = 48 and end = 58

In [22]:
tom_zippedMaps_22 = zip(tom_time_filter_map_list_22, tom_distance_filter_map_list_22)
ipy.inline_maps(tom_zippedMaps_22, len(tom_zippedMaps_22), 2)


Out[22]:

In [37]:
import numpy as np

In [38]:
tom_time_filter_df_22[tom_time_filter_df_22.mLatitude == 37.262226300000002][["mAccuracy", "mTime", "mElapsedRealtimeNanos"]]


Out[38]:
mAccuracy mTime mElapsedRealtimeNanos
34 978 1437612607683 798404153000000
36 978 1437612827651 798624121000000
39 978 1437612921570 798718041000000
44 978 1437613296848 799093319000000

In [88]:
tom_dist_filter_map_list_23 = get_map_list(lq.get_uuid_list()[2], "distance", get_dt(23), get_dt(24))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437638400000.0}}, {'data.mTime': {'$lt': 1437724800000.0}}], 'user_id': UUID('b0d937d0-70ef-305e-9563-440369012b39'), 'metadata.filter': 'distance'} 
0     2015-07-23 01:14:32
2     2015-07-23 08:09:59
4     2015-07-23 08:16:09
64    2015-07-23 09:19:23
66    2015-07-23 09:28:08
77    2015-07-23 09:45:57
80    2015-07-23 09:56:17
110   2015-07-23 14:36:50
127   2015-07-23 15:04:13
238   2015-07-23 16:55:58
241   2015-07-23 17:15:31
245   2015-07-23 19:51:32
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-23 01:14:32 to 2015-07-23 08:09:59 because start = 0 and end = 2
Ignoring trip from 2015-07-23 01:14:32 to 2015-07-23 08:09:59 because start = 0 and end = 2
Considering trip from 2015-07-23 08:09:59 to 2015-07-23 08:16:09 because start = 2 and end = 4
Ignoring trip from 2015-07-23 08:09:59 to 2015-07-23 08:16:09 because start = 2 and end = 4
Considering trip from 2015-07-23 08:16:09 to 2015-07-23 09:19:23 because start = 4 and end = 64
Considering trip from 2015-07-23 09:19:23 to 2015-07-23 09:28:08 because start = 64 and end = 66
Ignoring trip from 2015-07-23 09:19:23 to 2015-07-23 09:28:08 because start = 64 and end = 66
Considering trip from 2015-07-23 09:28:08 to 2015-07-23 09:45:57 because start = 66 and end = 77
Considering trip from 2015-07-23 09:45:57 to 2015-07-23 09:56:17 because start = 77 and end = 80
Ignoring trip from 2015-07-23 09:45:57 to 2015-07-23 09:56:17 because start = 77 and end = 80
Considering trip from 2015-07-23 09:56:17 to 2015-07-23 14:36:50 because start = 80 and end = 110
Considering trip from 2015-07-23 14:36:50 to 2015-07-23 15:04:13 because start = 110 and end = 127
Considering trip from 2015-07-23 15:04:13 to 2015-07-23 16:55:58 because start = 127 and end = 238
Considering trip from 2015-07-23 16:55:58 to 2015-07-23 17:15:31 because start = 238 and end = 241
Ignoring trip from 2015-07-23 16:55:58 to 2015-07-23 17:15:31 because start = 238 and end = 241
Considering trip from 2015-07-23 17:15:31 to 2015-07-23 19:51:32 because start = 241 and end = 245

In [89]:
my_time_filter_map_list_23 = get_map_list(lq.get_uuid_list()[0], "time", get_dt(23), get_dt(24))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437638400000.0}}, {'data.mTime': {'$lt': 1437724800000.0}}], 'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), 'metadata.filter': 'time'} 
0     2015-07-23 08:16:14
135   2015-07-23 09:51:10
217   2015-07-23 14:30:59
458   2015-07-23 16:46:47
459   2015-07-23 16:53:47
469   2015-07-23 19:40:05
479   2015-07-23 21:09:45
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-23 08:16:14 to 2015-07-23 09:51:10 because start = 0 and end = 135
Considering trip from 2015-07-23 09:51:10 to 2015-07-23 14:30:59 because start = 135 and end = 217
Considering trip from 2015-07-23 14:30:59 to 2015-07-23 16:46:47 because start = 217 and end = 458
Considering trip from 2015-07-23 16:46:47 to 2015-07-23 16:53:47 because start = 458 and end = 459
Ignoring trip from 2015-07-23 16:46:47 to 2015-07-23 16:53:47 because start = 458 and end = 459
Considering trip from 2015-07-23 16:53:47 to 2015-07-23 19:40:05 because start = 459 and end = 469
Considering trip from 2015-07-23 19:40:05 to 2015-07-23 21:09:45 because start = 469 and end = 479

In [90]:
tom_dist_filter_map_list_24 = get_map_list(lq.get_uuid_list()[2], "distance", get_dt(24), get_dt(25))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437724800000.0}}, {'data.mTime': {'$lt': 1437811200000.0}}], 'user_id': UUID('b0d937d0-70ef-305e-9563-440369012b39'), 'metadata.filter': 'distance'} 
0    2015-07-24 08:15:56
22   2015-07-24 14:08:08
52   2015-07-24 14:47:13
60   2015-07-24 15:04:56
61   2015-07-24 15:14:14
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-24 08:15:56 to 2015-07-24 14:08:08 because start = 0 and end = 22
Considering trip from 2015-07-24 14:08:08 to 2015-07-24 14:47:13 because start = 22 and end = 52
Considering trip from 2015-07-24 14:47:13 to 2015-07-24 15:04:56 because start = 52 and end = 60
Considering trip from 2015-07-24 15:04:56 to 2015-07-24 15:14:14 because start = 60 and end = 61
Ignoring trip from 2015-07-24 15:04:56 to 2015-07-24 15:14:14 because start = 60 and end = 61

In [91]:
tom_dist_filter_map_list_25 = get_map_list(lq.get_uuid_list()[2], "distance", get_dt(25), get_dt(26))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1437811200000.0}}, {'data.mTime': {'$lt': 1437897600000.0}}], 'user_id': UUID('b0d937d0-70ef-305e-9563-440369012b39'), 'metadata.filter': 'distance'} 
0    2015-07-25 10:13:31
5    2015-07-25 10:55:29
12   2015-07-25 15:25:13
20   2015-07-25 16:28:01
Name: formatted_time, dtype: datetime64[ns]
Considering trip from 2015-07-25 10:13:31 to 2015-07-25 10:55:29 because start = 0 and end = 5
Considering trip from 2015-07-25 10:55:29 to 2015-07-25 15:25:13 because start = 5 and end = 12
Considering trip from 2015-07-25 15:25:13 to 2015-07-25 16:28:01 because start = 12 and end = 20

In [92]:
mine_tom_map_list_23 = zip(tom_dist_filter_map_list_23, my_time_filter_map_list_23)
ipy.inline_maps(mine_tom_map_list_23, len(mine_tom_map_list_23), 2)


Out[92]:

In [30]:
ipy.inline_maps([[map] for map in my_time_filter_map_list_23], len(my_time_filter_map_list_23), 1)


Out[30]:

In [31]:
get_aug_dt = lambda date: pydt.datetime(2015,8,date,tzinfo=pytz.timezone("America/Los_Angeles"))

In [42]:
df = lq.get_plottable_df(lq.get_uuid_list()[0], "time", get_dt(29), get_dt(30))


final query = {'metadata.key': 'background/location', '$and': [{'data.mTime': {'$gt': 1438156800000.0}}, {'data.mTime': {'$lt': 1438243200000.0}}], 'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), 'metadata.filter': 'time'} 

In [43]:
df.shape


Out[43]:
(205, 28)