Beispiel #1
0
    def get_best_route(self, from_station, to_station, lines):
        route = Route()
        route.from_stop = from_station
        route.to_stop = to_station
        route.stops = 9999
        if len(lines) == 0:
            route.stops = 9999
            return route
        else:
            for each_line in lines:
                line = self.lines[each_line]
                start_index = 0
                stop_index = 0

                for i in range(0, len(line.stations)):
                    if line.stations[i] == from_station:
                        start_index = i
                    elif line.stations[i] == to_station:
                        stop_index = i

                stops = abs(start_index - stop_index)

                if stops < route.stops:
                    route.stops = stops
                    route.line_number = line.line_number

        return route