# HG changeset patch # User Teemu Piippo # Date 1544132360 -7200 # Node ID 4ac0f2e2ec4e637424400ef85213e51734d74a31 # Parent 091a48867bae1fec3e1c6fea2114a057ff4c1965 removed uuid mapping diff -r 091a48867bae -r 4ac0f2e2ec4e buses.py --- a/buses.py Thu Dec 06 20:47:19 2018 +0200 +++ b/buses.py Thu Dec 06 23:39:20 2018 +0200 @@ -5,7 +5,6 @@ from copy import copy from misc import * from geometry import * -import uuid def transform_trip_reference(reference): return reference @@ -153,11 +152,11 @@ return 'bus-stop' class BusHalt: - def __init__(self, arrival_time, departure_time, stop, trip, traveled_distance): + def __init__(self, arrival_time, departure_time, stop, trip, traveled_distance, visitnumber): self.arrival_time, self.departure_time, self.stop, self.trip = arrival_time, departure_time, \ stop, trip self.traveled_distance = traveled_distance - self.uuid = uuid.uuid4() + self.visitnumber = visitnumber @property def is_arrival(self): if profile['regions']['use-regions']: @@ -185,7 +184,7 @@ import datetime return datetime.datetime.combine(date, datetime.time()) + self.arrival_time def __repr__(self): - return 'BusHalt(%r, %r, %r, %r)' % (self.arrival_time, self.departure_time, self.stop, self.trip) + return 'BusHalt(%r, %r, %r, %r, %r, %r)' % (self.arrival_time, self.departure_time, self.stop, self.trip, self.traveled_distance, self.visitnumber) def sign(self, long = False): from busroute import reduce_schedule return reduce_schedule( @@ -193,6 +192,10 @@ trip_length = self.trip.length - self.traveled_distance, long = long, ) + @property + def primary_key(self): + arrival_time = self.trip.schedule[0].arrival_time; + return self.trip.block_id + '-' + str(int(arrival_time.seconds)) + '-' + str(self.visitnumber) class BusStopCluster: def __init__(self): @@ -502,7 +505,8 @@ departure_time = read_time(row['departure_time']) stop = bus_stops[row['stop_id']] traveled_distance = float(row.get('shape_dist_traveled', 1)) * float(profile['metrics']['shape-modifier']) - trip.schedule.append(BusHalt(arrival_time, departure_time, stop, trip, traveled_distance)) + visitnumber = len(trip.schedule) + 1 + trip.schedule.append(BusHalt(arrival_time, departure_time, stop, trip, traveled_distance, visitnumber)) stop.involved_trips.add(trip) progress += 1 if progress % 1000 == 0: @@ -552,10 +556,6 @@ last_leg_distance = trip.schedule[-1].traveled_distance - trip.schedule[-2].traveled_distance trip.schedule[-1].arrival_time = trip.schedule[-2].departure_time + timedelta(minutes = last_leg_distance / bus_speed_coefficient) - global trips_by_vehicle_info - trips_by_vehicle_info = {} - for trip in all_trips.values(): - trips_by_vehicle_info[(trip.block_id, trip.schedule[0].arrival_time)] = trip # Add services to all bus stops for route in routes.values(): for trip in route.trips: diff -r 091a48867bae -r 4ac0f2e2ec4e service.py --- a/service.py Thu Dec 06 20:47:19 2018 +0200 +++ b/service.py Thu Dec 06 23:39:20 2018 +0200 @@ -211,7 +211,7 @@ 'trip': schedule_entry['stop'].trip.name, 'night': is_night_time(schedule_entry['time']), 'imminent': imminent(schedule_entry), - 'id': str(schedule_entry['stop'].uuid), + 'id': str(schedule_entry['stop'].primary_key), 'gone': schedule_entry['gone'], }) return render_template( @@ -449,7 +449,6 @@ 'abbreviation': trip_abbreviation(trip), }) - def service_start_time(): from datetime import date, datetime, timedelta result = datetime.now().replace(hour = 0, minute = 0, second = 0, microsecond = 0) @@ -457,20 +456,6 @@ result -= timedelta(1) return result -@app.route('/find_halt///') -def find_halt(stop_reference, blockref, originalaimeddeparturetime): - from datetime import datetime - from flask import jsonify - info = (blockref, datetime.fromtimestamp(originalaimeddeparturetime) - service_start_time()) - trip = buses.trips_by_vehicle_info[info] - try: - return jsonify({ - 'id': [str(halt.uuid) for halt in buses.trips_by_vehicle_info[info].schedule if halt.stop.reference == stop_reference][0], - }) - except: - abort(404) - - def current_bus_day(): from datetime import date, datetime, timedelta day = date.today() diff -r 091a48867bae -r 4ac0f2e2ec4e templates/stop.html --- a/templates/stop.html Thu Dec 06 20:47:19 2018 +0200 +++ b/templates/stop.html Thu Dec 06 23:39:20 2018 +0200 @@ -36,7 +36,8 @@ }