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): |
372 def route_limit(route): |
373 return (route in night_routes) and 20 or 6 |
373 return (route in night_routes) and 6 or 20 |
374 def route_key(route): |
374 def route_key(route): |
375 from math import log |
375 from math import log |
376 return ( |
376 return ( |
377 route in night_routes, |
377 route in night_routes, |
378 counts_per_variant.get(route, 0) < route_limit(route), |
378 counts_per_variant.get(route, 0) < route_limit(route), |
380 str(route) |
380 str(route) |
381 ) |
381 ) |
382 def routes_key(routes): |
382 def routes_key(routes): |
383 return min(route_key(route) for route in routes) |
383 return min(route_key(route) for route in routes) |
384 result = [] |
384 result = [] |
385 rare_variants = {variant['name'] for variant in all_variants if variant['count'] < route_limit(route)} |
385 rare_variants = {variant['name'] for variant in all_variants if variant['count'] < route_limit(variant['name'])} |
386 rare_variant_groups = set() |
386 rare_variant_groups = set() |
387 for regions, routes in sorted( |
387 for regions, routes in sorted( |
388 routes_per_destination.items(), |
388 routes_per_destination.items(), |
389 key = lambda pair: routes_key(pair[1]) |
389 key = lambda pair: routes_key(pair[1]) |
390 ): |
390 ): |