Exemplo n.º 1
0
    def update(self, auto=False, data=None):
        """
        Updates data.
        """

        if data is None or type(data) != dict:
            d = get_data_from_json(vcub_url)
        else:
            d = data
        # the original format is awfull, so I change it a little
        if type(d) == dict:
            self.data = {}
            d = d["lists"]
            for i in d:
                e = {
                    "name": i["name"],
                    "online": i["connexionState"] == "CONNECTEE",
                    "plus": i["typeVlsPlus"] == "VLS_PLUS",
                    "empty": int(i["nbPlaceAvailable"]),
                    "bikes": int(i["nbBikeAvailable"]),
                    "ebikes": int(i["nbElectricBikeAvailable"]),
                    "location": (float(i["latitude"]), float(i["longitude"])),
                }
                self.data[int(i["id"])] = e
            self.last_update = time()
Exemplo n.º 2
0
def get_stop_areas_by_name(keyword):
    data = get_data_from_json(STOP_URL % quote(keyword))
    stopAreas = []
    for s in data:
        if s["type"] == "stop_area":
            stopAreas.append(StopArea(s["id"], s["name"], s["city"]))
    return stopAreas
Exemplo n.º 3
0
def file_function():
    '''
    Request arguments must include user_name field.
    e.g. {base_url}/files?user_name=r_fisher
  '''
    user_name = request.args.get("user_name", None)
    if user_name:
        user_files = utils.get_data_from_json(APP_ROOT, user_name, 'files')
        return utils.send_json(user_files or {})
    return utils.send_json({"error": "user not specified"}), 400
Exemplo n.º 4
0
def get_ssh_password():
    '''
    Request arguments must include user_name field.
    e.g. {base_url}/password?user_name=r_fisher
  '''
    user_name = request.args.get("user_name", None)
    if not user_name or user_name not in USERS:
        user_name = "no_user"
    user_password = utils.get_data_from_json(APP_ROOT, user_name, 'password')
    return user_password or ""
Exemplo n.º 5
0
def get_commands():
    '''
    Request arguments must include the type of commands.
    e.g. {base_url}/commands?type=logged_in
  '''
    command_type = request.args.get("type", None)
    if not command_type:
        command_type = "logged_out"

    user_commands = utils.get_data_from_json(APP_ROOT, 'commands',
                                             command_type)
    return utils.send_json(user_commands or {})
Exemplo n.º 6
0
 def get_photo_details(self, photo):
     photo_path = self.path + photo
     try:
         latitude, longitude, compas = get_gps_lat_long_compass(photo_path)
     except Exception:
         try:
             tags = exifread.process_file(open(photo_path, 'rb'))
             latitude, longitude = get_exif_location(tags)
             compas = -1
             if latitude is None and longitude is None:
                 latitude, longitude, compas = get_data_from_json(self.path, photo_path)
         except Exception:
             return None
     return latitude, longitude, compas
Exemplo n.º 7
0
    def update(self, auto=False):
        """
        Update data.
        """

        data = get_data_from_json(SCHEDULE_URL % (self.number, self.line))
        if "destinations" in data:
            data = data["destinations"]
        else:
            print("No data for stop %d" % self.number)
            return
        self.last_update = time()
        if type(data) == dict:
            self.data = []
            # let's simplify the data
            for i in data:
                for j in data[i]:
                    location = None
                    try:
                        location = (
                            float(j["vehicle_lattitude"]),
                            float(j["vehicle_longitude"]),
                        )
                    except TypeError:
                        pass
                    vehicle = Vehicle(
                        j["vehicle_id"],
                        j["destination_name"],
                        j["realtime"] == "1",
                        location,
                        hms2seconds(j["waittime"]),
                        j["waittime_text"],
                        int(self.last_update + hms2seconds(j["waittime"])),
                    )
                    self.data.append(vehicle)
            self.data = sorted(self.data,
                               key=lambda vehicle: vehicle.getArrival())
        else:
            self.last_update = 0
Exemplo n.º 8
0
def get_stop_by_id(id):
    data = get_data_from_json(INFO_URL % quote(id))
    stop = Stop(
        data["id"],
        data["name"],
        float(data["latitude"]),
        float(data["longitude"]),
        data["city"],
    )
    stopPoints = []
    for i in data["stopPoints"]:
        stopPoint = StopPoint(i["name"])
        routes = []
        stopPoint.setId(int(search("[0-9]+$", i["id"]).group()))
        for j in i["routes"]:
            route = Route(j["name"], j["line"]["name"])
            add = False
            if route.getLineName() in LINE_TRANSLATE:
                line_id = LINE_TRANSLATE[route.getLineName()]
                add = True
            else:
                try:
                    line_id = search("[0-9]+$", route.getLineName()).group()
                except AttributeError:
                    continue
                line_id = "%02d" % int(line_id)
                for i in LINE_TYPES:
                    if route.getLineName()[0:len(i)] == i:
                        add = True
                        break
            if add:
                route.setId(line_id)
                routes.append(route)
                stopPoint.setRoutes(routes)
        if stopPoint.getRoutes() != []:
            stopPoints.append(stopPoint)
            stop.setStopPoints(stopPoints)
    return stop
Exemplo n.º 9
0
COMPETITIONS = ["line-entry", "line"]
ARENA_IDS = { "line-entry": ["A", "B"], "line": ["C", "D"] }

# dates need to be in "YYYY-MM-DD" format and times in "HH.mm" format
COMPETITION_START_TIME_FIRST_DAY = "11.30"
MINIMUM_BREAK_LENGTH_PER_ARENA_IN_MINUTES = 20 # needed for possible delays + new referees can familiarize themselves with arena
MINIMUM_BREAK_LENGTH_FOR_REFEREES_IN_MINUTES = 50
COMPETITION_END_TIME_SECOND_DAY = "13.10"
FIRST_DAY = "2022-04-01"
SECOND_DAY = "2022-04-02"
TIMEZONE = "+02"
SLOT_LENGTH_IN_MINUTES = 10

time_format_string = "%Y-%m-%dT%H:%M:%S" + TIMEZONE

teams = get_data_from_json("teams.json")
teams_per_competition = { "line-entry": [], "line": [] }
for team in teams:
    teams_per_competition[team["competition"]].append(team)

schedule = []
MAX_NUMBER_OF_SLOTS = int(max(len(teams_per_competition["line-entry"]), len(teams_per_competition["line"])) / 2 + 0.5)

# day 1
MIN_NUMBER_OF_SLOTS = int(min(len(teams_per_competition["line-entry"]), len(teams_per_competition["line"])) / 2 + 0.5)
empty_slots_in_shorter_competition_block_used_for_break = int((MAX_NUMBER_OF_SLOTS - MIN_NUMBER_OF_SLOTS) / 2 + 0.5)
effective_break_length_for_referees_when_using_min_break_length_on_longer_competition_block = empty_slots_in_shorter_competition_block_used_for_break * SLOT_LENGTH_IN_MINUTES + MINIMUM_BREAK_LENGTH_PER_ARENA_IN_MINUTES
break_length_on_longer_competition_block = MINIMUM_BREAK_LENGTH_PER_ARENA_IN_MINUTES + max(0, MINIMUM_BREAK_LENGTH_FOR_REFEREES_IN_MINUTES - effective_break_length_for_referees_when_using_min_break_length_on_longer_competition_block)
number_of_slots_for_break_on_longer_competition_block = break_length_on_longer_competition_block // SLOT_LENGTH_IN_MINUTES + (1 if break_length_on_longer_competition_block % SLOT_LENGTH_IN_MINUTES else 0)
start_time = datetime.datetime(*[int(x) for x in (FIRST_DAY.split("-") + COMPETITION_START_TIME_FIRST_DAY.split("."))])
for competition in COMPETITIONS: