forked from TDTP/proto_backend
fix trayectos por paradero
parent
7273f21e5a
commit
b8873ad140
81
main.py
81
main.py
|
@ -34,7 +34,6 @@ def main():
|
||||||
for key in data:
|
for key in data:
|
||||||
r.set(key, json.dumps(data[key]))
|
r.set(key, json.dumps(data[key]))
|
||||||
|
|
||||||
# print(json.dumps(data['route:549-1'], indent=4))
|
|
||||||
|
|
||||||
|
|
||||||
def download_file_proto():
|
def download_file_proto():
|
||||||
|
@ -56,44 +55,46 @@ def read_file_proto_x_stop(content):
|
||||||
|
|
||||||
for entity in feed.entity:
|
for entity in feed.entity:
|
||||||
if entity.HasField('trip_update'):
|
if entity.HasField('trip_update'):
|
||||||
trip_data = {
|
# agregar trayectos con paraderos
|
||||||
"id": str(entity.id),
|
|
||||||
"stop_id": None,
|
|
||||||
"stop_sequence": None,
|
|
||||||
"trip_id": entity.trip_update.trip.trip_id,
|
|
||||||
"route_id": entity.trip_update.trip.route_id,
|
|
||||||
"direction_id": entity.trip_update.trip.direction_id,
|
|
||||||
"start_time": entity.trip_update.trip.start_time,
|
|
||||||
"start_date": entity.trip_update.trip.start_date,
|
|
||||||
"arrival_time": None,
|
|
||||||
"hora_llegada": None,
|
|
||||||
"schedule_relationship": entity.trip_update.trip.schedule_relationship,
|
|
||||||
"vehicle_license_plate": entity.trip_update.vehicle.license_plate,
|
|
||||||
"latitude": entity.vehicle.position.latitude,
|
|
||||||
"longitude": entity.vehicle.position.longitude,
|
|
||||||
"bearing": entity.vehicle.position.bearing,
|
|
||||||
"odometer": entity.vehicle.position.odometer,
|
|
||||||
"speed": entity.vehicle.position.speed
|
|
||||||
}
|
|
||||||
|
|
||||||
for update in entity.trip_update.stop_time_update:
|
for update in entity.trip_update.stop_time_update:
|
||||||
|
|
||||||
|
trip_data = {
|
||||||
|
"id": str(entity.id),
|
||||||
|
"stop_id": None,
|
||||||
|
"stop_sequence": None,
|
||||||
|
"trip_id": entity.trip_update.trip.trip_id,
|
||||||
|
"route_id": entity.trip_update.trip.route_id,
|
||||||
|
"direction_id": entity.trip_update.trip.direction_id,
|
||||||
|
"start_time": entity.trip_update.trip.start_time,
|
||||||
|
"start_date": entity.trip_update.trip.start_date,
|
||||||
|
"arrival_time": None,
|
||||||
|
"hora_llegada": None,
|
||||||
|
"schedule_relationship": entity.trip_update.trip.schedule_relationship,
|
||||||
|
"vehicle_license_plate": entity.trip_update.vehicle.license_plate,
|
||||||
|
"latitude": entity.vehicle.position.latitude,
|
||||||
|
"longitude": entity.vehicle.position.longitude,
|
||||||
|
"bearing": entity.vehicle.position.bearing,
|
||||||
|
"odometer": entity.vehicle.position.odometer,
|
||||||
|
"speed": entity.vehicle.position.speed
|
||||||
|
}
|
||||||
|
|
||||||
trip_data["stop_id"] = update.stop_id
|
trip_data["stop_id"] = update.stop_id
|
||||||
trip_data["stop_sequence"] = update.stop_sequence
|
trip_data["stop_sequence"] = update.stop_sequence
|
||||||
trip_data["arrival_time"] = update.arrival.time
|
trip_data["arrival_time"] = update.arrival.time
|
||||||
trip_data["hora_llegada"] = datetime.fromtimestamp(update.arrival.time).strftime('%H:%M:%S')
|
trip_data["hora_llegada"] = datetime.fromtimestamp(update.arrival.time).strftime('%H:%M:%S')
|
||||||
|
|
||||||
stop_id = '--'
|
stop_id = 'none'
|
||||||
if update.stop_id != None and update.stop_id > '':
|
if update.stop_id != None and update.stop_id > '':
|
||||||
stop_id = update.stop_id
|
stop_id = update.stop_id
|
||||||
|
|
||||||
key = f'stop_id:{stop_id}'
|
key = f'stop_id:{stop_id}'
|
||||||
|
|
||||||
if key in data_stop:
|
if key in data_stop:
|
||||||
data_stop[key].append(trip_data)
|
data_stop[key].append(trip_data)
|
||||||
else:
|
else:
|
||||||
data_stop[key] = [ trip_data ]
|
data_stop[key] = [ trip_data ]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
# agregar trayectos sin paradero
|
||||||
key = f'stop_id:none'
|
key = f'stop_id:none'
|
||||||
|
|
||||||
trip_data = {
|
trip_data = {
|
||||||
|
@ -117,36 +118,6 @@ def read_file_proto_x_stop(content):
|
||||||
else:
|
else:
|
||||||
data_stop[key] = [ trip_data ]
|
data_stop[key] = [ trip_data ]
|
||||||
|
|
||||||
# data_dict = trip_data.copy()
|
|
||||||
# data_dict["stop_sequence"] = update.stop_sequence
|
|
||||||
# data_dict["stop_id"] = update.stop_id
|
|
||||||
# data_dict["arrival_time"] = update.arrival.time
|
|
||||||
# data_dict["hora_llegada"] = datetime.fromtimestamp(update.arrival.time).strftime('%Y-%m-%d %H:%M:%S')
|
|
||||||
# data_list.append(data_dict)
|
|
||||||
|
|
||||||
# else:
|
|
||||||
# trip_data = {
|
|
||||||
# "id": str(entity.id),
|
|
||||||
# "trip_id": entity.vehicle.trip.trip_id,
|
|
||||||
# "route_id":entity.vehicle.trip.route_id,
|
|
||||||
# "direction_id": entity.vehicle.trip.direction_id,
|
|
||||||
# "start_time": entity.vehicle.trip.start_time,
|
|
||||||
# "start_date": entity.vehicle.trip.start_date,
|
|
||||||
# "schedule_relationship": entity.vehicle.trip.schedule_relationship,
|
|
||||||
# "vehicle_license_plate": entity.vehicle.vehicle.license_plate,
|
|
||||||
# "latitude": entity.vehicle.position.latitude,
|
|
||||||
# "longitude": entity.vehicle.position.longitude,
|
|
||||||
# "bearing": entity.vehicle.position.bearing,
|
|
||||||
# "odometer": entity.vehicle.position.odometer,
|
|
||||||
# "speed": entity.vehicle.position.speed
|
|
||||||
# }
|
|
||||||
# data_dict = trip_data.copy()
|
|
||||||
# data_dict["stop_sequence"] = ""
|
|
||||||
# data_dict["stop_id"] = ""
|
|
||||||
# data_dict["arrival_time"] = ""
|
|
||||||
# data_dict["hora_llegada"] = ""
|
|
||||||
# data_list.append(data_dict)
|
|
||||||
|
|
||||||
return data_stop;
|
return data_stop;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue