# HG changeset patch # User Teemu Piippo # Date 1525170060 -10800 # Node ID e27c18f080d1d230e68b19486188baba387970e4 # Parent 53ee9e94567316f8da7b688b864193d93cf7855c added an interesting trip portal diff -r 53ee9e945673 -r e27c18f080d1 buses.py --- a/buses.py Thu Apr 26 16:12:23 2018 +0300 +++ b/buses.py Tue May 01 13:21:00 2018 +0300 @@ -165,6 +165,12 @@ return self.cachedIsArrival else: return self == self.trip.schedule[-1] + def departure_datetime(self, date): + import datetime + return datetime.datetime.combine(date, datetime.time()) + self.departure_time + def arrival_datetime(self, date): + 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) def sign(self, long = False): diff -r 53ee9e945673 -r e27c18f080d1 busroute.py --- a/busroute.py Thu Apr 26 16:12:23 2018 +0300 +++ b/busroute.py Tue May 01 13:21:00 2018 +0300 @@ -9,9 +9,11 @@ else: return 0 -def simplify_name(region_name): +def simplify_name(region_name, replace = False): region = regions.get(region_name) if region: + if replace and 'replacement' in region and region['replacement'] != region_name: + return simplify_name(region['replacement']) return region.get('short_name', region_name) else: return region_name diff -r 53ee9e945673 -r e27c18f080d1 profiles/föli.ini --- a/profiles/föli.ini Thu Apr 26 16:12:23 2018 +0300 +++ b/profiles/föli.ini Tue May 01 13:21:00 2018 +0300 @@ -13,3 +13,7 @@ [service-patterns] ferry = 180 + +[date-exceptions] +1.5. = sunday +30.4. = weekday diff -r 53ee9e945673 -r e27c18f080d1 service.py --- a/service.py Thu Apr 26 16:12:23 2018 +0300 +++ b/service.py Tue May 01 13:21:00 2018 +0300 @@ -157,7 +157,7 @@ except KeyError: return place -def trip_abbreviation(trip): +def trip_description(trip): entries = [trip.from_place] old_places = None starting_halt = None @@ -177,7 +177,10 @@ old_places = places if trip.to_place not in entries: entries += [trip.to_place] - return trip.route.reference + ':' + '-'.join(map(place_abbreviation, entries)) + return entries + +def trip_abbreviation(trip): + return trip.route.reference + ':' + '-'.join(map(place_abbreviation, trip_description(trip))) def split_route_ref(route_ref): try: @@ -782,6 +785,45 @@ schedule = schedule, ) +@app.route('/interesting') +def interesting(): + from buses import all_trips, services_for_day + from busroute import simplify_name + from collections import Counter, defaultdict + from datetime import datetime + trip_counts = Counter() + interesting_trips = defaultdict(list) + for trip_reference, trip in all_trips.items(): + if len(trip.service.dates) <= 3: + for date in trip.service.dates: + moment = trip.schedule[0].departure_datetime(date) + if moment > datetime.now(): + interesting_trips[date].append((trip, moment)) + for date in interesting_trips: + interesting_trips[date].sort(key = lambda tuple: tuple[1]) + interesting_trips = [(date, interesting_trips[date]) for date in sorted(interesting_trips.keys())] + data = [ + { + 'date': date, + 'leaves': [{ + 'route': trip.route.reference, + 'departure': moment, + 'trip': trip.reference, + 'stop': trip.schedule[0].stop, + 'description': ' - '.join( + simplify_name(place, replace = True) + for place in trip_description(trip) + ), + } for trip, moment in leaves] + } + for date, leaves in interesting_trips + ] + return render_template( + 'interesting.html', + data = data, + tr = tr, + ) + @app.route('/') def index(): return redirect('stop_cluster/kauppatori') diff -r 53ee9e945673 -r e27c18f080d1 tr/en.ini --- a/tr/en.ini Thu Apr 26 16:12:23 2018 +0300 +++ b/tr/en.ini Tue May 01 13:21:00 2018 +0300 @@ -11,4 +11,7 @@ route = Route bus-stop = Stop destination = Destination +interesting = Interesting trips +start-bus-stop = Stop +trip-description = Path diff -r 53ee9e945673 -r e27c18f080d1 tr/fi.ini --- a/tr/fi.ini Thu Apr 26 16:12:23 2018 +0300 +++ b/tr/fi.ini Tue May 01 13:21:00 2018 +0300 @@ -2,7 +2,10 @@ time = Aika route = Linja bus-stop = Pysäkki +start-bus-stop = Lähtöpysäkki destination = Määränpää +interesting = Erikoiset lähdöt +trip-description = Reitti [misc-text] right-now = nyt diff -r 53ee9e945673 -r e27c18f080d1 tr/sv.ini --- a/tr/sv.ini Thu Apr 26 16:12:23 2018 +0300 +++ b/tr/sv.ini Tue May 01 13:21:00 2018 +0300 @@ -3,6 +3,9 @@ route = Linje bus-stop = Hållplats destination = Destination +interesting = Intressanta resor +start-bus-stop = Hållplats +trip-description = Rutt [misc-text] right-now = nu