Example #1
0
def retrieveLapRunDataLapQuads(lapId: str) -> []:
    # config the request for API to get the run data
    limit, page = int(os.environ['runDataRetrieveLimit']), \
                  int(os.environ['runDataPaging'])

    payload = {'lapName': lapId, 'page': page, 'limit': limit}
    # call API to get runData
    runData: dict = ApiWrapper.get("/rundata/", params=payload).json()['data']

    if len(runData) == 0:
        raise RunDataException

    # some times the first rows is mistaken distance data
    # and need to remove them from the run data ro
    def removed_first_bad_distance_rows() -> int:
        glitches, total_rows, g = 0, len(runData), 0
        for row_id in range(total_rows - 1):
            # In this case, the row 'distance' value is bigger then the next row 'distance' value.
            if runData[row_id]['distance'] > runData[row_id + 1]['distance']:
                glitches += 1
            else:
                break
        return glitches

    # the number of glitches in thr beginning of the lap
    num_dist_glit: int = removed_first_bad_distance_rows()
    if num_dist_glit > 0:
        print(f"FOUND {num_dist_glit} BAD ROWS FOR LAP {lapId}"
              f"\nLAP FIRST ROWS DISTANCE IS BIGGER THEN THE NEXT ROWS")

    runData = runData[num_dist_glit:]  # remove the rows with the distance glitches in the
    # beginning

    # create array of RunDataRow bean object
    return [RunDataRow(**runData[i]) for i in range(len(runData))]