diff -r 302f840d6a65 -r 9139a94e540c busroute.py --- a/busroute.py Mon Mar 12 18:10:58 2018 +0200 +++ b/busroute.py Thu Mar 29 23:55:36 2018 +0300 @@ -7,16 +7,18 @@ region_info.read('regions.ini') def simplify_name(name): - name = profile['replacements'].get(name, name) - return name + return profile['replacements'].get(name, name) -def reduce_schedule(route, trip_length, whole = False, long = False): +def greatly_simplify_name(name): + return profile['more replacements'].get(name, simplify_name(name)) + +def reduce_schedule(route, trip_length, whole = False, format = 'medium'): priorities = profile['priorities'] length = ((trip_length / 600) * 3 + len(route) * 2) / 5 + have_already = set() + i = 0 if not route: return '' - have_already = set() - i = 0 while i < len(route): if route[i] in profile['replacements']: route[i] = profile['replacements'][route[i]] @@ -32,6 +34,8 @@ factor = 1 / max(f(i + 1) for i in range(len(route))) while float(priorities.get(route[-1], 0)) < 0: del route[-1] + if not route: + return '' destination = route[-1] for i, stop in enumerate(route): # muunna indeksi siten että myöhemmät alueet korostuvat @@ -50,27 +54,35 @@ for i, stop in enumerate(route) \ if reitti_arvot[stop] >= 1 ], key = lambda stop: -stop[1]) - if long: + if format == 'long': weights = weights[:4] + elif format == 'short': + weights = weights[:2] + # repeat for the second sign value + try: + if weights[1][0] != destination and weights[1][1] < (500 / length ** 1.15): + del weights[1] + except IndexError: + pass else: # enintään neljä tulee kylttiin weights = weights[:3] - # jos kolmas kylttiarvo ei ole tarpeeksi merkittävä suhteessa reitin pituuteen niin otetaan se pois + # if the third sign value is not significant enough, drop it try: if weights[2][0] != destination and weights[2][1] < (725 / length ** 0.8): del weights[2] except IndexError: pass + # repeat for the second sign value try: if weights[1][0] != destination and weights[1][1] < (500 / length ** 1.15): del weights[1] except IndexError: pass - # lajitellaan painoarvot uudestaan reittijärjestykseen jotta sign tulee oikeinpäin + # reorder to get the sign the right way around weights = sorted(weights, key = lambda weight_data: weight_data[2]) - # muodostetaan sign.. + # form the sign.. sign = [paino[0] for paino in weights] - to_place = sign[-1] old_sign = sign.copy() sign = [] for place in old_sign: