367 length += 1 |
367 length += 1 |
368 else: |
368 else: |
369 break |
369 break |
370 return length or len(route) |
370 return length or len(route) |
371 from math import inf |
371 from math import inf |
|
372 def route_limit(route): |
|
373 return (route in night_routes) and 20 else 6 |
372 def route_key(route): |
374 def route_key(route): |
373 from math import log |
375 from math import log |
374 return ( |
376 return ( |
375 route in night_routes, |
377 route in night_routes, |
376 counts_per_variant.get(route, 0) < 20, |
378 counts_per_variant.get(route, 0) < route_limit(route), |
377 route_len(route), |
379 route_len(route), |
378 str(route) |
380 str(route) |
379 ) |
381 ) |
380 def routes_key(routes): |
382 def routes_key(routes): |
381 return min(route_key(route) for route in routes) |
383 return min(route_key(route) for route in routes) |
382 result = [] |
384 result = [] |
383 rare_variants = {variant['name'] for variant in all_variants if variant['count'] < 20} |
385 rare_variants = {variant['name'] for variant in all_variants if variant['count'] < route_limit(route)} |
384 rare_variant_groups = set() |
386 rare_variant_groups = set() |
385 for regions, routes in sorted( |
387 for regions, routes in sorted( |
386 routes_per_destination.items(), |
388 routes_per_destination.items(), |
387 key = lambda pair: routes_key(pair[1]) |
389 key = lambda pair: routes_key(pair[1]) |
388 ): |
390 ): |