# HG changeset patch # User Teemu Piippo # Date 1524748343 -10800 # Node ID 53ee9e94567316f8da7b688b864193d93cf7855c # Parent 16a5c37e4e678cebd01aea6596a96d04bab16536 added ferry support diff -r 16a5c37e4e67 -r 53ee9e945673 buses.py --- a/buses.py Tue Apr 24 23:21:34 2018 +0300 +++ b/buses.py Thu Apr 26 16:12:23 2018 +0300 @@ -185,7 +185,7 @@ clusters_by_name = {} services_for_day = {} -def load_buses(gtfs_zip_path, regions): +def load_buses(gtfs_zip_path): global viimeinen_käyttöpäivä from zipfile import ZipFile with ZipFile(gtfs_zip_path) as gtfs_zip: @@ -196,6 +196,22 @@ routes[route.reference] = route routes_per_id[route.id] = route print('%d routes' % len(routes), file = stderr) + # Add services + import re + service_patterns = {} + if 'service-patterns' in profile: + for service_type, regexps in profile['service-patterns'].items(): + service_patterns[service_type] = {re.compile(regexp) for regexp in regexps.split('@')} + if 'services' in profile and profile['services'].get('default-service'): + print('Tagging services...', end = '') + for route in routes.values(): + for service_type, regexps in service_patterns.items(): + if any(regexp.match(route.reference) for regexp in regexps): + route.service = service_type + break + else: + route.service = profile['services']['default-service'] + print('') print('Loading trips... ', file = stderr, end = '', flush = True) shape_distances = {} try: @@ -231,8 +247,7 @@ hour, minute, second = map(int, teksti.split(':')) return timedelta(hours = hour, minutes = minute, seconds = second) - print('Ladataan päiväykset... ', file = stderr, flush = True) - + print('Loading dates... ', file = stderr, flush = True) viimeinen_käyttöpäivä = date.today() def date_range(start_date, end_date, *, include_end = False): @@ -504,13 +519,11 @@ trips_by_vehicle_info = {} for trip in all_trips.values(): trips_by_vehicle_info[(trip.block_id, trip.schedule[0].arrival_time)] = trip - if 'services' in profile and profile['services'].get('default-service'): - for route in routes.values(): - if not route.service: - route.service = profile['services']['default-service'] - for trip in route.trips: - for halt in trip.schedule: - halt.stop.services.add(route.service) + # Add services to all bus stops + for route in routes.values(): + for trip in route.trips: + for halt in trip.schedule: + halt.stop.services.add(route.service) if __name__ == '__main__': profile.read('profiles/föli.ini') diff -r 16a5c37e4e67 -r 53ee9e945673 service.py --- a/service.py Tue Apr 24 23:21:34 2018 +0300 +++ b/service.py Thu Apr 26 16:12:23 2018 +0300 @@ -214,6 +214,7 @@ cluster = bus_stop.cluster.url_name if len(bus_stop.cluster.stops) > 1 else None, tr = tr, typename = bus_stop.typename, + service = min(bus_stop.services), ) def week_schedule(bus_stop, **kwargs): @@ -608,6 +609,7 @@ stops_in_cluster = stops_in_cluster, amount_of_stops_in_cluster = len(stops_in_cluster), tr = tr, + service = min(set.union(*[bus_stop.services for bus_stop in cluster.stops])), ) def day_class(weekday): @@ -758,6 +760,7 @@ night = is_night_time(datetime.combine(today(), time()) + trip.schedule[-1].arrival_time), tr = tr, length = trip.length / 1000, + service = trip.route.service, ) @app.route('/route/') @@ -816,7 +819,7 @@ tr.load_regions(regions) import busroute busroute.regions = regions -buses.load_buses(args.gtfs_zip_path, regions = regions) +buses.load_buses(args.gtfs_zip_path) if __name__ == '__main__': app.run(debug = args.debug, port = args.port) diff -r 16a5c37e4e67 -r 53ee9e945673 static/ferry-terminal.png Binary file static/ferry-terminal.png has changed diff -r 16a5c37e4e67 -r 53ee9e945673 static/style.css --- a/static/style.css Tue Apr 24 23:21:34 2018 +0300 +++ b/static/style.css Thu Apr 26 16:12:23 2018 +0300 @@ -32,6 +32,16 @@ box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5); } +.aikataulu.service-ferry +{ + background: #0090fe; +} + +.aikataulu.service-ferry thead +{ + color: white; +} + .aikataulu tr:first-child th:first-child { border-top-left-radius: 30px; @@ -83,16 +93,18 @@ .aikataulu tr.yö td { - /* - background-color: #115; - color: #dde; - border-top: 1px solid #338; - */ background-color: #2f271a; color: #eae4db; border-top: 1px solid #4a3d28; } +.aikataulu.service-ferry tr.yö td +{ + background-color: #1a2a2f; + color: #dbe6ea; + border-top: 1px solid #28424a; +} + #pysäkki-info { text-align: center @@ -168,6 +180,11 @@ color: inherit; } +.service-ferry .imminent-leave +{ + color: #0b93c0; +} + @keyframes blinking { from, 24.9% @@ -232,12 +249,22 @@ box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.5); } +.service-ferry .actions a +{ + background: #00ade6; +} + .actions a:hover { background: #fff3b3; text-decoration: none; } +.service-ferry .actions a:hover +{ + background: #00c0fe; +} + .route-suffix { font-size: 75%; diff -r 16a5c37e4e67 -r 53ee9e945673 static/train-station.png Binary file static/train-station.png has changed diff -r 16a5c37e4e67 -r 53ee9e945673 static/tram-stop.png Binary file static/tram-stop.png has changed diff -r 16a5c37e4e67 -r 53ee9e945673 templates/cluster.html --- a/templates/cluster.html Tue Apr 24 23:21:34 2018 +0300 +++ b/templates/cluster.html Thu Apr 26 16:12:23 2018 +0300 @@ -40,7 +40,7 @@ --> - +
diff -r 16a5c37e4e67 -r 53ee9e945673 templates/stop.html --- a/templates/stop.html Tue Apr 24 23:21:34 2018 +0300 +++ b/templates/stop.html Thu Apr 26 16:12:23 2018 +0300 @@ -14,7 +14,7 @@ - +
diff -r 16a5c37e4e67 -r 53ee9e945673 templates/trip.html --- a/templates/trip.html Tue Apr 24 23:21:34 2018 +0300 +++ b/templates/trip.html Thu Apr 26 16:12:23 2018 +0300 @@ -56,7 +56,7 @@ {{route}} {{description}} - +
@@ -85,7 +89,7 @@ {% for halt in entry['stops'] %} - + {% endfor %}
@@ -64,7 +64,11 @@ {% if night %} 🌙  {% endif %} - 🚍 + {% if service == 'ferry' %} + ⛴ + {% else %} + 🚍 + {% endif %} {{route}} {{description}}
{{halt['time']}} {{halt['code']}} {{halt['code']}} {{halt['name']}}