Ejemplo n.º 1
0
def load_bus_schedule_json(path_bus_schedule_json):
    with open(path_bus_schedule_json, "r") as f:
        bus_schedules_json = json.load(f)["busSchedules"]
    bus_schedules = {}
    for target_bus_schedules in bus_schedules_json:
        schedule_branches = []
        for schedule_branch in target_bus_schedules["scheduleBranches"]:
            common_schedules = []
            for common in schedule_branch["common"]:
                common_schedules = Schedule.get_merged_schedules(common_schedules, [Schedule.new_schedule(
                    Target.new_targets(common["targets"]) if "targets" in common else None,
                    common["event"], None, None,
                    Route.decode_route_code(common["routeCode"])
                )])

            main_schedules = []
            for main in schedule_branch["main"]:
                main_schedules = Schedule.get_merged_schedules(
                    main_schedules, [Schedule.new_schedule(
                        Target.new_targets(main["targets"]) if "targets" in main else None,
                        main["event"], None, None,
                        Route.decode_route_code(main["routeCode"])
                    )]
                )
            sub_schedules = []
            for sub in schedule_branch["sub"]:
                sub_schedules = Schedule.get_merged_schedules(
                    sub_schedules, [Schedule.new_schedule(
                        Target.new_targets(sub["targets"]) if "targets" in sub else None,
                        sub["event"], None, None,
                        Route.decode_route_code(sub["routeCode"])
                    )]
                )
            schedule_branches.append(
                ScheduleBranch.new_schedule_branch(common_schedules, main_schedules, sub_schedules))
        bus_schedules[target_bus_schedules["ID"]] = schedule_branches
    return bus_schedules
Ejemplo n.º 2
0
    def get_distance_from_stopline(self, monitored_route):
        monitored_arrow_codes = monitored_route.arrow_codes
        distance_from_stopline = SIM_CAR.FLOAT_MAX

        self.traffic_signals_lock.acquire()
        traffic_signals = deepcopy(self.traffic_signals)
        self.traffic_signals_lock.release()

        not_green_traffic_signal_route_codes = list(
            map(
                lambda x: x.route_code,
                filter(
                    lambda x: x.state in
                    [TRAFFIC_SIGNAL.STATE.YELLOW, TRAFFIC_SIGNAL.STATE.RED],
                    traffic_signals.values())))

        new_monitored_route = None
        for i, monitored_arrow_code in enumerate(monitored_arrow_codes):
            for not_green_traffic_signal_route_code in not_green_traffic_signal_route_codes:
                if monitored_arrow_code in not_green_traffic_signal_route_code:
                    not_green_traffic_signal_route = Route.decode_route_code(
                        not_green_traffic_signal_route_code)
                    if monitored_arrow_code == not_green_traffic_signal_route.arrow_codes[
                            0]:
                        waypoint_ids = self.arrow.get_waypoint_ids(
                            monitored_arrow_code)
                        if self.status.location.waypoint_id not in waypoint_ids or \
                                waypoint_ids.index(self.status.location.waypoint_id) <= waypoint_ids.index(
                                    not_green_traffic_signal_route.start_waypoint_id):
                            new_monitored_route = Route.new_route(
                                monitored_route.start_waypoint_id,
                                not_green_traffic_signal_route.
                                start_waypoint_id,
                                monitored_arrow_codes[:i + 1])
                            break
            if new_monitored_route is not None:
                break

        if new_monitored_route is not None:
            distance_from_stopline = self.route.get_route_length(
                new_monitored_route)

        if distance_from_stopline < SIM_CAR.FLOAT_MAX:
            logger.info(
                "distance_from_stopline {}[m]".format(distance_from_stopline))
        return distance_from_stopline
Ejemplo n.º 3
0
        "8957",
        "8958",
        "8959",
        "8960",
        "8961",
        "8962",
        "8963",
        "8964",
        "8965",
        "8966",
        "8967",
        "8968",
    ]

    if args.route_code is not None:
        arg_route = Route.decode_route_code(args.route_code)
        start_waypoint_id = arg_route.start_waypoint_id
        arrow_codes = arg_route.arrow_codes
        goal_waypoint_id = arg_route.goal_waypoint_id
        start_arrow_code = arrow_codes[0]
        goal_arrow_code = arrow_codes[-1]
    else:
        start_waypoint_id = args.start_waypoint_id
        if start_waypoint_id is None:
            start_waypoint_id = random.choice(stop_waypoint_ids)
        start_arrow_code = arrow.get_arrow_codes_from_waypoint_id(
            start_waypoint_id)[0]
    current_time = time()

    sim_car = SimCar(_id=args.id if args.id is not None else str(uuid()),
                     name=args.name,