Thu, 06 Dec 2018 23:39:20 +0200
removed uuid mapping
buses.py | file | annotate | diff | comparison | revisions | |
service.py | file | annotate | diff | comparison | revisions | |
templates/stop.html | file | annotate | diff | comparison | revisions |
--- 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:
--- 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/<stop_reference>/<blockref>/<int:originalaimeddeparturetime>') -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()
--- 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 @@ } </style> <script> - var getJSON = function(url, callback) { + var getJSON = function(url, callback) + { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'json'; @@ -49,21 +50,8 @@ xhr.send(); }; - var getUuid = function(blockref, originaimeddeparturetime, data, callback) { - var xhr = new XMLHttpRequest(); - var url = "../find_halt/{{ref}}/" + blockref + "/" + originaimeddeparturetime.toString(); - xhr.open('GET', url, true); - xhr.responseType = 'json'; - xhr.onload = function() { - var status = xhr.status; - if (status === 200) { - callback(xhr.response['id'], data); - } - }; - xhr.send(); - }; - - function timeConverter(UNIX_timestamp){ + function timeConverter(UNIX_timestamp) + { var a = new Date(UNIX_timestamp * 1000); var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; var year = a.getFullYear(); @@ -76,18 +64,39 @@ return time; } - function updateTime(uuid, time) { - const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + function epoch() + { + var d = new Date(); + if (d.getHours() < 4) + d.setDate(d.getDate() - 1); + d.setHours(0); + d.setMinutes(0); + d.setSeconds(0); + return Math.floor(d.getTime() / 1000); + } + + function primarykey(data) + { + var key = data['blockref'] + '-'; + key += (data['originaimeddeparturetime'] - epoch()).toString() + '-'; + key += data['visitnumber']; + return key; + } + + function updateTime(key, time) + { const d = new Date(); const now = (d.getTime() + d.getTimezoneOffset()) / 1000; - row = document.getElementById(uuid); - timeCell = document.getElementById(uuid + '-time'); - t0 = parseInt(document.getElementById(uuid + '-stamp').innerHTML); - if (Math.abs(time - t0) > 90) { + row = document.getElementById(key); + timeCell = document.getElementById(key + '-time'); + t0 = parseInt(document.getElementById(key + '-stamp').innerHTML); + if (Math.abs(time - t0) > 90) + { oldTime = timeConverter(t0); newTime = timeConverter(time); timeCell.innerHTML = '<s style="color:gray">' + oldTime + '</s> ⟶ <b>' + newTime + '</b>'; } + if (time + 15 > now) row.classList.remove('gone'); else @@ -153,9 +162,8 @@ var blockref = data['result'][i]['blockref']; var originaimeddeparturetime = data['result'][i]['originaimeddeparturetime']; var expecteddeparturetime = data['result'][i]['expecteddeparturetime']; - getUuid(blockref, originaimeddeparturetime, expecteddeparturetime, function(id, expecteddeparturetime) { - updateTime(id, expecteddeparturetime); - }); + var key = primarykey(data['result'][i]); + updateTime(key, expecteddeparturetime); } }); </script>