3
0
Fork 0

fix trayectos por paradero

master
Francisco Sandoval 2024-03-20 10:57:53 -03:00
parent 7273f21e5a
commit b8873ad140
1 changed files with 26 additions and 55 deletions

41
main.py
View File

@ -34,7 +34,6 @@ def main():
for key in data:
r.set(key, json.dumps(data[key]))
# print(json.dumps(data['route:549-1'], indent=4))
def download_file_proto():
@ -56,6 +55,9 @@ def read_file_proto_x_stop(content):
for entity in feed.entity:
if entity.HasField('trip_update'):
# agregar trayectos con paraderos
for update in entity.trip_update.stop_time_update:
trip_data = {
"id": str(entity.id),
"stop_id": None,
@ -76,24 +78,23 @@ def read_file_proto_x_stop(content):
"speed": entity.vehicle.position.speed
}
for update in entity.trip_update.stop_time_update:
trip_data["stop_id"] = update.stop_id
trip_data["stop_sequence"] = update.stop_sequence
trip_data["arrival_time"] = update.arrival.time
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 > '':
stop_id = update.stop_id
key = f'stop_id:{stop_id}'
if key in data_stop:
data_stop[key].append(trip_data)
else:
data_stop[key] = [ trip_data ]
else:
# agregar trayectos sin paradero
key = f'stop_id:none'
trip_data = {
@ -117,36 +118,6 @@ def read_file_proto_x_stop(content):
else:
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;