Exemplo n.º 1
0
def get_constructor_standings():
    resp = {"team_standings": []}
    year = request.args.get('year')
    if year:
        try:
            year = int(year)
            _round = request.args.get('round')
            if _round:
                _round = int(_round)
                races = [get_race(year, _round)]
                res = get_constructor_standings_from_race(races[0].raceId)
            else:
                races = get_races_in_year(year)
                race_ids = [r.raceId for r in races]
                res = get_constructor_standings_from_races(race_ids=race_ids)

        except ValueError:
            return "Invalid route param, either supply a number or the string 'latest'", 400
    else:
        return "Must supply at least a year in query param to get standings", 400

    races.reverse()
    for race in races:
        tmp = {"race": race.to_json()}
        race_standings = list(filter(lambda x: x.raceId == race.raceId, res))
        if race_standings:
            tmp["standings"] = [s.to_json() for s in race_standings]
            resp["team_standings"].append(tmp)

    return resp
Exemplo n.º 2
0
def get_driver_standings():
    resp = {"driver_standings": []}
    year = request.args.get('year')
    if year:
        try:
            year = int(year)
            _round = request.args.get('round')
            if _round:
                _round = int(_round)
                races = [get_race(year, _round)]
                if races:
                    res = get_driver_standings_by_race(races[0].raceId)
                else:
                    return "Race not found", 404
            else:
                races = get_races_in_year(year)
                race_ids = [r.raceId for r in races]
                res = get_driver_standings_by_races(race_ids=race_ids)

        except ValueError:
            return "Invalid year/round", 400
    else:
        return "Must supply at least a year in query param to get standings", 400

    races.reverse()
    for race in races:
        tmp = {"race": race.to_json()}
        race_standings = list(filter(lambda x: x.raceId == race.raceId, res))
        tmp["standings"] = [s.to_json() for s in race_standings]
        resp["driver_standings"].append(tmp)

    return resp
Exemplo n.º 3
0
def get_result():
    resp = {"data": []}
    year = request.args.get('year')
    if year:
        try:
            year = int(year)
            race_number = request.args.get('round')
            if race_number:
                race_number = int(race_number)
                races = [get_race(year, race_number)]
                res = get_results_from_race(race_id=races[0].raceId)
            else:
                races = get_races_in_year(year)
                race_ids = [r.raceId for r in races]
                res = get_results_from_races(race_ids=race_ids)

        except ValueError:
            return "Invalid year/round, must be numbers", 400
    else:
        races = [get_last_race()]
        res = get_results_from_race(races[0].raceId)

    races.reverse()
    for race in races:
        tmp = {"race": race.to_json()}
        race_results = list(filter(lambda x: x.raceId == race.raceId, res))
        if race_results:
            tmp["results"] = [r.to_json() for r in race_results]
            resp["data"].append(tmp)
    return resp
Exemplo n.º 4
0
def get_qualifying():
    resp = {"data": []}
    year = request.args.get('year')
    if year:
        try:
            year = int(year)
            qualy_round = request.args.get('round')
            if qualy_round:
                qualy_round = int(qualy_round)
                races = [get_race(year=year, round=qualy_round)]
                res = get_qualifying_results(races[0].raceId)
            else:
                races = get_races_in_year(year)
                race_ids = [r.raceId for r in races]
                res = get_qualifying_results(race_ids)

        except ValueError:
            return "Invalid year/round, must be numbers", 400
    else:
        return "No year specified in query param", 400

    races.reverse()
    for race in races:
        tmp = {"race": race.to_json(), "results": []}
        quali_results = list(filter(lambda x: x.raceId == race.raceId, res))
        if quali_results:
            tmp["results"] = [qr.to_json() for qr in quali_results]
            resp["data"].append(tmp)

    return resp
Exemplo n.º 5
0
def get_races():
    year = request.args.get('year')
    season_round = request.args.get('round')
    data = {}
    try:
        if year:
            year = int(year)    
            if season_round:
                season_round = int(season_round)
                race = get_race(year, season_round)
                data["races"] = [race.to_json()]
            else:
                races = get_races_in_year(year)
                data["races"] = [r.to_json() for r in races]
        else:
            races = get_all_races()
            before = time.time()
            races.sort(key=lambda x: x.date)
            data["races"] = [r.to_json() for r in races]
        return data
    except ValueError as err:
        print(err)
        return "Invalid query parameter", 400