-
Notifications
You must be signed in to change notification settings - Fork 5
Home
store following data
- valid cells - set
- vehicle data (vehicle_id,regNum,type,color,make,photo_url,driver_id,driver name) - hash
- vehicle locations (by vehicle_id) - key (vehicle_id), unique (cell_id), timestamp,vehicle_id -sortedset
- vehicle locations (by cell_id)
- cells with vehicles
- busy vehicles
- trips
- passengers
-
when driver sign-in to GoSwift update the following:-
- vehicle location logs
- vehicle cell logs
- vehicle is assumed to be free? (this is default assumption, so do nothing)
-
when driver starts a trip, update the following:-
- vehicle location logs
- vehicle trip logs
- add vehicle to busy log
-
when driver ends a trip, update the following:-
- vehicle location logs
- vehicle trip logs
- remove vehicle from busy log
ZRANGE loc:222030303:04455 0 -1 ZRANGE loc:222030303:04455 0 -1 WITHSCORES ZRANGEBYSCORE loc:222030303:04455 1493586776 1493587553 ZREVRANGEBYSCORE loc:222030303:04455 1493586776 1493587553
HMSET vehicle_id:04455 cell:2203795020390208331 gps:2203795001640038161 timestmap: 1493376367 HMSET vehicle_id:04455 cell:2203795020390208331 gps:2203795001640038162 timestmap: 1493376368 HMSET vehicle_id:04455 cell:2203795020390208332 gps:2203795001640037155 timestmap: 1493376367
---List of vehicles inside cell and their latest gps location ------
ZADD location:: ts 2203795001640038161 ZADD location:: ts 2203795001640038162
ZADD location:: ts 2203795001640038163
ZADD cell:222030305 ts 04449 ZADD cell:222030305 ts 04446 ZADD loc:222030303 1493587553 04455
---- List of free vehicles -------------------
---SADD free_taxis:: ts 2203795001640038161 (remove this set, no need)
---- List of busy vehicles --------------------------
- SADD busy_taxis:<cell-222030303>:<vehicle-04455> ts 2203795001640038161
- SADD cell:2203795020390208331 04455
- SADD cell:2203795020390208331 2203795001640038161
------list of vehicle_ids within a cell------
- SADD cell:2203795001640038161 ts 04455
- SADD cell:2203795001640038162 ts 04455
- SADD cell:2203795001640038163 ts 04455
- SADD cell:2203795001640038164 ts 04455
SADD trip:vehicle_id:trip_id 1493376367 2203795001640038161 (trip:vehicle_id:trip_id-> timestamp, leaf_id)
HMSET trip:00233 vehicle:04455 gps:2203795001640038161 timestamp: 1493376367
SADD vehicle:04455 00233
------------------ trip 00233 in vehicle 04455--------------
- SADD trip:<id-00233>:<vehicle-04455> ts 2203795001640038161
- SADD trip:<id-00233>:<vehicle-04455> ts 2203795001640038162
- SADD trip:<id-00233>:<vehicle-04455> ts 2203795001640038163
- SADD trip:<id-00233>:<vehicle-04455> ts 2203795001640038164
- SADD trip:<id-00233>:<vehicle-04455> ts 2203795001640038168
Notes:-
-
no need to keep the free vehicles set, we assume that taxis are free unless their vehicle_id is in busy vehicles set
-
vehicles starts being free. when there is a trip request, we check if vehicle is not in the busy set. if so, we can dispatch it.
-
and then immediately add it to the busy set. when its trip completes we delete it from busy set.
-
whats the possibility of two vehicles having same quad_key? if this is high then we store location in hashmap instead of set (Set requires unique elements)
vehicle:04455 -> set [array][timestamp, quad_key] cell:222010203 -> hashmap (timestamp, quad_key,vehicle_id) trip:0002 -> timestamp,vehicle_id,quad_key trip:0003 -> vehicle_id, start_time, end_time
driver:0002 - > driver_id, driver_url,
vehicle:0001 (1 vehicle, 1 key) - Vehicle location logs
- zadd vehicle:001 1493758483 2203795001640038161
- zadd vehicle:001 1493758500 2203794989626726499
cell:002 (each vehicle, each cell) - Vehicle cell logs
- zadd cell:2203674533334876160 timestamp vehicle:001
- zadd cell:2203674533334876160 1493759113 vehicle:001
check how to check SINTER cell:002 vehicle:001
trip:002 (1 vehicle, 1 trip at a time) - Trip logs
- zadd start_trip:002 1493759113 vehicle:001
- zadd end_trip:002 1493759413 vehicle:001
sadd busy_taxi -> timestamp vehicle_id - Busy flag
/hash/trip:003 -> vehicle : 003 start_time: 1493759113 start_cellid: 2203795001640038161 end_time: -1 end_cellid:
/hash/trip:005 -> vehicle : 004 start_time: 1493759116 start_cellid: 2203795001640038161 end_time: -1 end_cellid:
/hash/trip:007 -> vehicle : 005 start_time: 1493759117 start_cellid: 2203795001640038161 end_time: -1 end_cellid:
/hash/multi-trip:005 -> [trip:002,trip:003,trip:004]; /hash/multi_trip:006 -> [1: trip-002, 2: trip-003, 3: trip-004] add set to associate vehicle with rider when the trip starts
trip:001 - > {trip_id, depart_gps, arrival_gps, start_time, end_time, request_time, no_of_riders }