diff -r 209f5930d038 -r 16a5c37e4e67 service.py --- a/service.py Fri Apr 20 13:50:02 2018 +0300 +++ b/service.py Tue Apr 24 23:21:34 2018 +0300 @@ -268,9 +268,11 @@ adjusted_time = time - timedelta(hours = 4, minutes = 30) return adjusted_time.weekday() in [4, 5] and is_night_time(time) -encircled = '\u24b6\u24b7\u24b8\u24b9\u24ba\u24bb\u24bc\u24bd\u24be\u24bf' \ - '\u24c0\u24c1\u24c2\u24c3\u24c4\u24c5\u24c6\u24c7\u24c8\u24c9\u24ca\u24cb' \ - '\u24cc\u24cd\u24ce\u24cf' +#encircled = '\u24b6\u24b7\u24b8\u24b9\u24ba\u24bb\u24bc\u24bd\u24be\u24bf' \ +# '\u24c0\u24c1\u24c2\u24c3\u24c4\u24c5\u24c6\u24c7\u24c8\u24c9\u24ca\u24cb' \ +# '\u24cc\u24cd\u24ce\u24cf' +#encircled = '⒜⒝⒞⒟⒠⒡⒢⒣⒤⒥⒦⒧⒨⒩⒪⒫⒬⒭⒮⒯⒰⒱⒲⒳⒴⒵' +encircled = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ' def encircle(char): from string import ascii_uppercase @@ -295,9 +297,11 @@ from collections import defaultdict, Counter from busroute import simplify_name destinations_per_route = defaultdict(Counter) + counts_per_variant = {} def route_key(route_ref): + from math import log try: - return parse_route_ref(route_ref) + return () + parse_route_ref(route_ref) except ValueError: return () def filter_names(names): @@ -340,12 +344,14 @@ 'destination': filter_names(destination), 'count': count }) + counts_per_variant[route_name] = count all_variants.sort(key = lambda k: k['count']) route_variant_count = len(all_variants) # Only consider variants so that they cover at least 99% of bus leaves coverage = 0 - while all_variants: #coverage / num_leaves < 0.99: - variant = all_variants.pop() + #while coverage / num_leaves < 0.99: + # variant = all_variants.pop() + for variant in all_variants: routes_per_destination[variant['destination']].add(variant['name']) coverage += variant['count'] for key in routes_per_destination: @@ -360,22 +366,29 @@ return length or len(route) from math import inf def route_key(route): + from math import log return ( route in night_routes, + counts_per_variant.get(route, 0) < 20, route_len(route), str(route) ) def routes_key(routes): return min(route_key(route) for route in routes) result = [] + rare_variants = {variant['name'] for variant in all_variants if variant['count'] < 20} + rare_variant_groups = set() for regions, routes in sorted( routes_per_destination.items(), key = lambda pair: routes_key(pair[1]) ): + routes_tuple = tuple(condense_route_list(sorted(routes, key = route_key))) result.append(( - list(condense_route_list(sorted(routes, key = route_key))), + routes_tuple, ' - '.join(tr(region, 'region_short_name') for region in regions) )) + if all(variant in rare_variants for variant in routes): + rare_variant_groups.add(routes_tuple) return { 'night-routes': night_routes, 'all-night-routes': lambda entry, description: all(route in description['night-routes'] for route in entry[0]), @@ -383,6 +396,8 @@ 'description': result, 'wtf': destinations_per_route, 'variant-map': {k:variant_names[v] for k, v in trip_mapping.items()}, + 'rare-variants': rare_variants, + 'rare-variant-groups': rare_variant_groups, } @app.route('/stop_description/')