# HG changeset patch # User Teemu Piippo # Date 1536863550 -10800 # Node ID b736478416d44f088ce8b1e8205ea9f30fdd8948 # Parent b8467d51f1b835c6f44df4072f8bc06f5e906dfa added map to trip view diff -r b8467d51f1b8 -r b736478416d4 buses.py --- a/buses.py Wed Sep 12 08:27:27 2018 +0300 +++ b/buses.py Thu Sep 13 21:32:30 2018 +0300 @@ -10,11 +10,12 @@ return reference class BusTrip: - def __init__(self, reference, route, service, length, block_id): + def __init__(self, reference, route, service, length, block_id, shape): self.reference, self.route, self.service, self.block_id = reference, route, service, block_id self.length = length self.schedule = [] self.name = transform_trip_reference(reference) + self.shape = str(shape) def __repr__(self): return 'all_trips[%r]' % self.name def contains_stop(self, stop): @@ -219,6 +220,8 @@ result += stop.schedule(max_amount = max_amount) result.sort(key = lambda schedule_entry: schedule_entry['time']) return result[:max_amount] + def __lt__(self, other): + return (self.name and other.name) and (self.name < other.name) or (id(self) < id(other)) class CustomBusStopCluster(BusStopCluster): def __init__(self, *, name, stops): @@ -232,6 +235,7 @@ from urllib.request import quote return 'custom?stops=' + ';'.join(stop.code for stop in self.stops) + '&name=' + quote(self.name) +from collections import defaultdict routes = {} routes_per_id = {} all_trips = {} @@ -241,6 +245,7 @@ viimeinen_käyttöpäivä = None clusters_by_name = {} services_for_day = {} +shapes = defaultdict(list) def load_buses(gtfs_zip_path): global viimeinen_käyttöpäivä @@ -274,6 +279,7 @@ try: with gtfs_zip.open('shapes.txt') as file: for row in read_csv(map(bytes.decode, file)): + list.append(shapes[row['shape_id']], (row['shape_pt_lat'], row['shape_pt_lon'])) shape_distances[row['shape_id']] = max(shape_distances.get(row['shape_id'], 0), float(row['shape_dist_traveled'])) except KeyError: pass @@ -289,6 +295,7 @@ service = services[row['service_id']], length = shape_distances.get(row.get('shape_id'), 1) * float(profile['metrics']['shape-modifier']), block_id = row.get('block_id') or row['service_id'], + shape = row.get('shape_id') ) route.trips.add(trip) if trip.name in all_trips: diff -r b8467d51f1b8 -r b736478416d4 service.py --- a/service.py Wed Sep 12 08:27:27 2018 +0300 +++ b/service.py Thu Sep 13 21:32:30 2018 +0300 @@ -790,8 +790,8 @@ @app.route('/trip/') def trip(trip_reference): from flask import request - from buses import all_trips - from busroute import simplify_name + from buses import all_trips, shapes + from busroute import simplify_name,greatly_simplify_name try: trip = all_trips[trip_reference] except KeyError: @@ -824,8 +824,12 @@ 'time': formatted_time, 'id': halt.stop.reference, 'code': halt.stop.code, + 'ref': halt.stop.code or halt.stop.reference, 'name': tr(halt.stop.name, 'bus-stops'), 'typename': halt.stop.typename, + 'arrival_time': time_representation(datetime.combine(today(), time()) + halt.arrival_time), + 'departure_time': time_representation(datetime.combine(today(), time()) + halt.departure_time), + 'location': str(halt.stop.location), }) sign = trip.concise_schedule() try: @@ -836,11 +840,20 @@ schedule = schedule, trip_reference = trip_reference, route = trip.route.reference, - description = ' - '.join(tr(place, 'region_name') for place in sign), + #description = ' - '.join(tr(place, 'region_name') for place in sign), + description = greatly_simplify_name(sign[-1]), night = is_night_time(datetime.combine(today(), time()) + trip.schedule[-1].arrival_time), tr = tr, length = trip.length / 1000, service = trip.route.service, + shape = ','.join(str.format('[{}, {}]', point[0], point[1]) for point in shapes[trip.shape]), + stops = list( + dict( + ref = halt.stop.reference, + name = halt.stop.name, + position = str.format('[{}]', str(halt.stop.location)), + ) for halt in trip.schedule + ), ) @app.route('/route/') diff -r b8467d51f1b8 -r b736478416d4 templates/custom_cluster.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/custom_cluster.html Thu Sep 13 21:32:30 2018 +0300 @@ -0,0 +1,1 @@ +make ur damn cluster here diff -r b8467d51f1b8 -r b736478416d4 templates/trip.html --- a/templates/trip.html Wed Sep 12 08:27:27 2018 +0300 +++ b/templates/trip.html Thu Sep 13 21:32:30 2018 +0300 @@ -3,7 +3,18 @@ - + + +