Thu, 26 Apr 2018 16:12:23 +0300
added ferry support
buses.py | file | annotate | diff | comparison | revisions | |
service.py | file | annotate | diff | comparison | revisions | |
static/ferry-terminal.png | file | annotate | diff | comparison | revisions | |
static/style.css | file | annotate | diff | comparison | revisions | |
static/train-station.png | file | annotate | diff | comparison | revisions | |
static/tram-stop.png | file | annotate | diff | comparison | revisions | |
templates/cluster.html | file | annotate | diff | comparison | revisions | |
templates/stop.html | file | annotate | diff | comparison | revisions | |
templates/trip.html | file | annotate | diff | comparison | revisions |
--- 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')
--- 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/<name>') @@ -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)
--- 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%;
--- 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 @@ </ul> </div> --> - <table class='aikataulu' cellspacing="0"> + <table class='aikataulu service-{{service}}' cellspacing="0"> <thead> <tr> <th class='primary-heading' colspan='5'>
--- 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 @@ </style> </head> <body> - <table class='aikataulu' cellspacing="0"> + <table class='aikataulu service-{{service}}' cellspacing="0"> <thead> <tr> <th colspan='4' class='primary-heading'>
--- 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 @@ <title>{{route}} {{description}}</title> </head> <body> - <table class='aikataulu' cellspacing='0'> + <table class='aikataulu service-{{service}}' cellspacing='0'> <thead> <tr> <th class='primary-heading' colspan='3'> @@ -64,7 +64,11 @@ {% if night %} 🌙 {% endif %} - 🚍 + {% if service == 'ferry' %} + ⛴ + {% else %} + 🚍 + {% endif %} </span> <span>{{route}} {{description}}</span> </th> @@ -85,7 +89,7 @@ {% for halt in entry['stops'] %} <tr> <td>{{halt['time']}}</td> - <td><a href="../stop/{{halt['id']}}"><img src='../static/{{typename}}.png' height='24' /> {{halt['code']}}</a></td> + <td><a href="../stop/{{halt['id']}}"><img src="../static/{{halt['typename']}}.png" height='24' /> {{halt['code']}}</a></td> <td><a href="../stop/{{halt['id']}}">{{halt['name']}}</a></td> </tr> {% endfor %}