Ejemplo n.º 1
0
def get_circuit_name(cid, include_flag=True):
    """
    Gets the stylized version of the given circuit's name
    :param cid: Circuit ID
    :param include_flag: Whether to include the nationality flag in the constructor's name
    :return: String
    """
    global circuits
    if circuits is None:
        circuits = load_circuits()
    circuit = circuits.loc[cid]
    name = circuit["name"]
    if include_flag:
        nat = circuit["country"].lower()
        if nat in NATIONALITY_TO_FLAG.index:
            flag_t = NATIONALITY_TO_FLAG.loc[nat, "flag"]
            name = flag.flagize(f":{flag_t}: " + name)
        else:
            logging.warning(f"Unknown nationality {nat}, circuit ID: {cid}")
    return name
Ejemplo n.º 2
0
def get_race_name(rid,
                  include_flag=True,
                  include_country=True,
                  line_br=None,
                  use_shortened=False,
                  include_year=False):
    """
    Gets the stylized version of the given race's name
    :param rid: Race ID
    :param include_flag: Whether to include the nationality flag in the constructor's name
    :param include_country: Whether to use the full race name or just the country name
    :param line_br: Character to use for line break, or None if not desired
    :param use_shortened: Use shortened version of GP name
    :param include_year: Whether to include the year in the name, only works if `use_shortened` and `line_br` are both
    False
    :return: String
    """
    global circuits, races
    if circuits is None:
        circuits = load_circuits()
    if races is None:
        races = load_races()
    race = races.loc[rid]
    circuit = circuits.loc[race["circuitId"]]
    name = circuit["country"] if include_country else race["name"]
    if use_shortened:
        name = name[:3].upper()
    if include_flag:
        nat = circuit["country"].lower()
        if nat in NATIONALITY_TO_FLAG.index:
            flag_t = NATIONALITY_TO_FLAG.loc[nat, "flag"]
            if line_br:
                name = flag.flagize(f"{name} {line_br} :{flag_t}:")
            else:
                name = flag.flagize(f":{flag_t}: " + name)
        else:
            logging.warning(f"Unknown nationality {nat}, race ID: {rid}")
    if include_year:
        name = str(race["year"]) + " " + name
    return name
Ejemplo n.º 3
0
import logging
from bokeh.layouts import column
from bokeh.models import Div
from data_loading.data_loader import load_races, load_results, load_driver_standings, load_fastest_lap_data, \
    load_lap_times, load_circuits
from mode import circuitdriver, driverconstructor
from utils import get_circuit_name, get_driver_name, get_constructor_name, plot_image_url, generate_spacer_item, \
    generate_plot_list_selector, generate_div_item, PlotItem, COMMON_PLOT_DESCRIPTIONS

races = load_races()
results = load_results()
driver_standings = load_driver_standings()
fastest_lap_data = load_fastest_lap_data()
lap_times = load_lap_times()
circuits = load_circuits()


def get_layout(circuit_id=-1, driver_id=-1, constructor_id=-1, download_image=True, **kwargs):
    circuit_rids = races[races["circuitId"] == circuit_id].index.values
    driver_results = results[results["driverId"] == driver_id]
    cdc_results = driver_results[(driver_results["raceId"].isin(circuit_rids)) &
                                 (driver_results["constructorId"] == constructor_id)]

    logging.info(f"Generating layout for mode CIRCUITDRIVERCONSTRUCTOR in circuitdriverconstructor, "
                 f"circuit_id={circuit_id}, driver_id={driver_id}, constructor_id={constructor_id}")

    # Detect invalid combos
    if cdc_results.shape[0] == 0:
        return generate_error_layout(circuit_id, driver_id, constructor_id)

    cdc_rids = cdc_results["raceId"]