示例#1
0
def text_for_local_comparison(triplette, position, team_or_driver):
    text = ''
    if triplette[0] == None:
        text += "they both have an equal number of "
        if position == 1:
            text += "wins"
        else:
            text += integer_to_ordinal(position) + " positions"
        text += " (" + str(triplette[1]) + "), "
    else:
        if position == 1:
            if team_or_driver == 'driver':
                text += "he has more "
            else:
                text += "the team has more "
            text += "wins"
        else:
            if team_or_driver == 'driver':
                text += "but " + driver_mapping[triplette[0]] + " has more "
            else:
                text += "but " + constuctor_mapping[
                    triplette[0]] + " has more "
            text += integer_to_ordinal(position) + " positions"
        text += " (" + str(triplette[1]) + " compared to " + str(
            triplette[2]) + ")."
    return text
示例#2
0
def specific_position_text(name,
                           position,
                           gp_names,
                           year_text,
                           is_quali=False):
    race_info = " in " + gp_names + year_text
    if isinstance(position, int):
        if is_quali:
            text = name + " finished " + \
                integer_to_ordinal(position) + " in the qualifying" + race_info
        else:
            text = name + " finished " + \
                integer_to_ordinal(position) + " in the race" + race_info
    else:
        text = name + " retired in the race" + race_info
    return text
示例#3
0
def text_for_retirement_reason(returned_reasons, \
                    gp_names, driver, constructor, year):
    if len(returned_reasons) > 0:
        year_text = text_for_year(year)

        text = []
        if returned_reasons[0] == 'no_retirement':
            if (driver != None or constructor != None):
                if driver != None:
                    text.append(driver_mapping[driver] + " did not " +\
                                "retire in " + gp_names + year_text)
                else:
                    text.append("No " + constuctor_mapping[constructor] +\
                                " retired in " + gp_names + year_text)
        else:
            if (driver != None or constructor != None):
                if driver != None:
                    text.append(driver_mapping[driver] + " retired due to " + \
                                    finishing_statuses[returned_reasons[0]] + " in " + gp_names + year_text)
                else:
                    if len(returned_reasons) > 1:
                        for car_no in range(len(returned_reasons)):
                            text.append("The " + integer_to_ordinal(car_no+1) + \
                                    " " + constuctor_mapping[constructor] + " retired due to " + \
                                    finishing_statuses[returned_reasons[car_no]] + ".")

                    else:
                        text.append("A " + constuctor_mapping[constructor] +\
                                    " retired due to " + finishing_statuses[returned_reasons[0]] +\
                                    " in " + gp_names + year_text)
    return text
示例#4
0
def text_for_aggregate_stats(gp_name, circuit_name, locality, country, \
                    year, top_bottom, numeric, ordinal, driver, \
                    constructor, team_or_driver, podium, metric_value):

    print(top_bottom, numeric, ordinal, podium)

    if year == None:
        year_text = ''
    else:
        year_text = text_for_year(year)

    #Get top N drivers
    if (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1
    elif podium != None:
        top_bottom = 'top'
        numeric = 3

    text = ""
    if driver != None and constructor != None:
        text += driver_mapping[driver] + ", driving for " + \
                constuctor_mapping[constructor] + ","
    elif driver != None and constructor == None:
        text += driver_mapping[driver]
    elif driver == None and constructor != None:
        text += constuctor_mapping[constructor]

    #Get specific number
    if isinstance(ordinal, int):
        text += " has finished " + integer_to_ordinal(ordinal)

    #Get top N drivers-teams
    elif (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1

        if numeric == 1:
            text += " has won"
        else:
            text += " has finished in the top " + str(numeric) + " positions"

    #Get bottom N drivers-teams
    elif top_bottom == 'bottom':
        if numeric == None:
            numeric = 1
        if numeric == 1:
            text += " has finished last"
        else:
            text += " has finished in the last " + str(numeric) + " positions"

    time_or_times = ' time' if metric_value == 1 else ' times'
    text += " " + str(metric_value) + time_or_times + " "

    text += text_for_circuits(gp_name, circuit_name, locality, country)

    text += year_text

    return text
示例#5
0
def text_for_most_championship_stats(team_or_driver, ordinal, \
                        numeric, top_bottom, driver, constructor, \
                        metric_value):
    #TODO: Make proper text if None
    if metric_value[0][0] == None:
        text = "This combination has no championships!"
        return text

    #Get top N drivers
    if (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1

    if team_or_driver == None:
        team_or_driver = 'driver'

    is_or_are = 'is' if len(metric_value) == 1 else 'are'
    has_or_have = 'has' if len(metric_value) == 1 else 'have'
    singular = True if len(metric_value) == 1 else False

    text = ''
    text += connect_teams_or_drivers(metric_value, team_or_driver) + " " + \
            is_or_are + " the " + team_or_driver_text(team_or_driver, singular)

    #Get specific number
    if isinstance(ordinal, int):
        text += " with the most " + integer_to_ordinal(
            ordinal) + " positions in the championship"

    #Get top N drivers-teams
    elif (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1

        if numeric == 1:
            text += " with the most championships"
        else:
            text += " that " + has_or_have + " finished in the top " + \
                    str(numeric) + " positions " +\
                    "of the championship the most times"

    if constructor != None:
        text += " with a " + constuctor_mapping[constructor]
    if driver != None:
        text += " with " + driver_mapping[driver] + " as a driver"

    #Add text for times
    time_or_times = ' time' if metric_value[0][1] == 1 else ' times'
    text += " (" + str(int(metric_value[0][1])) + time_or_times + ")."

    return text
示例#6
0
def text_for_championship_stats(top_bottom, numeric, ordinal, driver, \
                    constructor, metric_value, years):

    #Get top N drivers
    if (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1

    text = ""
    if driver != None and constructor != None:
        text += driver_mapping[driver] + ", driving for " + \
                constuctor_mapping[constructor] + ","
    elif driver != None and constructor == None:
        text += driver_mapping[driver]
    elif driver == None and constructor != None:
        text += constuctor_mapping[constructor]

    #Get specific number
    if isinstance(ordinal, int):
        text += " has finished " + integer_to_ordinal(
            ordinal) + " in the championship"

    #Get top N drivers-teams
    elif (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1

        if numeric == 1:
            text += " has won the championship"
        else:
            text += " has finished in the top " + str(
                numeric) + " positions of the championship"

    time_or_times = ' time' if metric_value == 1 else ' times'
    text += " " + str(metric_value) + time_or_times + "."

    #Add text for years
    if len(years) > 0:
        years_text = "This happened in " + text_for_many_items(years) + "."
    else:
        years_text = ''

    return [text, years_text]
示例#7
0
def text_for_standings(returned_list, returned_positions, top_bottom, numeric, \
                    ordinal, driver, constructor, team_or_driver, year, returned_points):

    #TODO: add player points
    year_text = text_for_year(year)

    if returned_positions == [] and returned_points == []:
        text = returned_list[0] + " did not take part in that championship."

    elif (driver != None or constructor != None):
        for i, pos in enumerate(returned_positions):
            try:
                returned_positions[i] = int(returned_positions[i])
            except Exception:
                pass

        text = returned_list[0] + " " + is_or_was(year) + " " +\
                    integer_to_ordinal(returned_positions[0]) +\
                    " in the " + team_or_driver_text(team_or_driver, singular=True) +\
                    "'s championship"
        if year == 'current':
            text += " this year."
        else:
            text += " in " + str(year) + "."

    #Get specific number
    elif isinstance(ordinal, int):
        text = "The " + integer_to_ordinal(ordinal) + " " + team_or_driver_text(team_or_driver, singular=True) + \
                year_text + " " + is_or_was(year, singular=True) + " " + \
                text_for_many_items(returned_list) + "."

    #Get top N drivers-teams
    elif (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1

        if numeric == 1:
            if year == 'current':
                text = returned_list[0] + " won the " + team_or_driver_text(team_or_driver, singular=True) +\
                        "'s championship last year."
            else:
                text = returned_list[0] + " won the " + team_or_driver_text(team_or_driver, singular=True) +\
                        "'s championship in " + str(year) + "."
        else:
            text = "The first " + str(numeric) + " " + team_or_driver_text(team_or_driver, singular=False) + \
                    " in the championship " + year_text + " " +\
                    is_or_was(year, singular=False) + " " + \
                    text_for_many_items(returned_list) + "."

    #Get bottom N drivers-teams
    elif top_bottom == 'bottom':  #and isinstance(numeric, int)
        #This is for the question "which is the last team in the standings?"
        if numeric == None:
            numeric = 1
        if numeric == 1:
            if year == 'current':
                text = "The last " + team_or_driver_text(team_or_driver, singular=True) +\
                        "in championship last year was " + returned_list[0] + "."
            else:
                text = "The last " + team_or_driver_text(team_or_driver, singular=True) +\
                        "in " + str(year) + " championship was " + returned_list[0] + "."
        else:
            text = "The last " + str(numeric) + " " + team_or_driver_text(team_or_driver, singular=False) + \
                    " in the championship " + year_text + " " +\
                    is_or_was(year, singular=False) +\
                    " " + text_for_many_items(returned_list) + "."

    else:
        if year == 'current':
            text = "Here are the current standings:\n" + \
                '\n'.join(returned_list)
        else:
            text = "Here are the standings for " + str(year) + ":\n" + \
                '\n'.join(returned_list)

    return text
示例#8
0
def text_for_most_aggregate_quali_stats(gp_name, circuit_name, locality, country, year, \
                        team_or_driver, ordinal, pole, \
                        numeric, top_bottom, driver, \
                        constructor, metric_value):

    #TODO: Make proper text if None
    if metric_value[0][0] == None:
        text = "This combination has no pole positions!"
        return text

    if year == None:
        year_text = ''
    else:
        year_text = text_for_year(year)

    #Get top N drivers
    if (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1
    elif pole != None:
        top_bottom = 'top'
        numeric = 1

    if team_or_driver == None:
        team_or_driver = 'driver'

    is_or_are = 'is' if len(metric_value) == 1 else 'are'
    has_or_have = 'has' if len(metric_value) == 1 else 'have'
    singular = True if len(metric_value) == 1 else False

    text = ''
    text += connect_teams_or_drivers(metric_value, team_or_driver) + " " + \
            is_or_are + " the " + team_or_driver_text(team_or_driver, singular)

    #Get specific number
    if isinstance(ordinal, int):
        text += " with the most " + integer_to_ordinal(
            ordinal) + " positions in qualifying"

    #Get top N drivers-teams
    elif (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1

        if numeric == 1:
            text += " with the most pole positions"
        else:
            text += " that " + has_or_have + " qualified in the top " + \
                    str(numeric) + " positions " + "the most times"

    if constructor != None:
        text += " with a " + constuctor_mapping[constructor]
    if driver != None:
        text += " with " + driver_mapping[driver] + " as a driver"

    #Add text for circuits
    lst = [gp_name, circuit_name, locality, country]
    print(lst)
    lst = [i.title() for i in lst if i != None]
    if len(lst) == 1:
        text += " in " + lst[0]
    elif len(lst) > 1:
        text += " in " + " in ".join(lst)

    text += year_text + " (" + str(int(metric_value[0][1])) + ")."

    return text
示例#9
0
def text_for_aggregate_quali_stats(gp_name, circuit_name, locality, country, \
                    year, top_bottom, numeric, ordinal, driver, \
                    constructor, team_or_driver, pole, metric_value):

    if year == None:
        year_text = ''
    else:
        year_text = text_for_year(year)

    #Get top N drivers
    if (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1
    elif pole != None:
        top_bottom = 'top'
        numeric = 1

    text = ""
    if driver != None and constructor != None:
        text += driver_mapping[driver] + ", driving for " + \
                constuctor_mapping[constructor] + ","
    elif driver != None and constructor == None:
        text += driver_mapping[driver]
    elif driver == None and constructor != None:
        text += constuctor_mapping[constructor]

    #Get specific number
    if isinstance(ordinal, int):
        text += " has qualified " + integer_to_ordinal(ordinal)

    #Get top N drivers-teams
    elif (top_bottom == 'top' or ordinal == 1):
        if numeric == None:
            numeric = 1

        if numeric == 1:
            text += " has taken the pole position"
        else:
            text += " has qualified in the top " + str(numeric) + " positions"

    #Get bottom N drivers-teams
    elif top_bottom == 'bottom':
        if numeric == None:
            numeric = 1
        if numeric == 1:
            text += " has qualified last"
        else:
            text += " has qualified in the last " + str(numeric) + " positions"

    time_or_times = ' time' if metric_value == 1 else ' times'
    text += " " + str(metric_value) + time_or_times

    #Add text for circuits
    lst = [gp_name, circuit_name, locality, country]
    print(lst)
    lst = [i for i in lst if i != None]
    if len(lst) == 1:
        text += " in " + lst[0]
    elif len(lst) > 1:
        text += " in " + " in ".join(lst)

    text += year_text

    return text
示例#10
0
def text_for_quali_time(returned_constructors, returned_drivers, returned_times, gp_names, \
        top_bottom, numeric, ordinal, driver, constructor, team_or_driver, \
        year='current', returned_quali_phases=None):
    if len(returned_constructors) > 0:

        year_text = text_for_year(year)

        if (driver != None or constructor != None):
            #TODO: Add reason for retirement
            if driver != None:
                if returned_times[0] == None or returned_times[0] == 'None':
                    text = [returned_drivers[0] + " did not record a qualifying time in " + \
                            returned_quali_phases + " in " + gp_names + year_text + "."]
                else:
                    text = [returned_drivers[0] + "'s qualifying time in " + \
                            returned_quali_phases + " in " + gp_names + year_text +\
                            " was " + returned_times[0] + "."]
            elif (team_or_driver == 'team' or constructor != None):
                text = []
                for car_no in range(len(returned_constructors)):
                    if returned_times[car_no] == None or returned_times[
                            car_no] == 'None':
                        text.append("The " + integer_to_ordinal(car_no+1) + \
                            " " + returned_constructors[car_no] + " (" + returned_drivers[car_no] + \
                            ") did not record a qualifying time in " + \
                            returned_quali_phases + " in " + gp_names + year_text + ".")
                    else:
                        text.append("The " + integer_to_ordinal(car_no+1) + \
                            " " + returned_constructors[car_no] + "'s (" + returned_drivers[car_no] + \
                            ") qualifying time in " + \
                            returned_quali_phases + " in " + gp_names + year_text +\
                            "was " + returned_times[car_no] + ".")

        #Get specific number
        elif isinstance(ordinal, int):  #and top_bottom==None
            if ordinal == 1:
                text = ["The fastest qualifying time in " + returned_quali_phases + \
                        " in " + gp_names + year_text + \
                        "was " + returned_times[0] + ".", "It was made by " + returned_drivers[0] +\
                        " (" + returned_constructors[0] + ")."]
            else:
                text = ["The " + integer_to_ordinal(ordinal) + " fastest qualifying time in " + \
                        returned_quali_phases + " in " + gp_names + year_text + \
                        "was " + returned_times[0] + ".", "It was made by " + returned_drivers[0] +\
                        " (" + returned_constructors[0] + ")."]

        #Get top N drivers-teams
        elif (top_bottom == 'top' or ordinal == 1):
            if numeric == None:
                numeric = 1

            if numeric == 1:
                text = ["The fastest qualifying time in " + returned_quali_phases + \
                        " in " + gp_names + year_text + \
                        "was " + returned_times[0] + ".", "It was made by " + returned_drivers[0] +\
                        " (" + returned_constructors[0] + ")."]
            else:
                quali_times = text_for_quali_times(returned_constructors,
                                                   returned_drivers,
                                                   returned_times)
                text = ["Below are the top " + str(numeric) + " qualifying times " +\
                        "for " + returned_quali_phases + " in " + gp_names + year_text + "."]
                text = text + quali_times

        #Get bottom N drivers-teams
        elif top_bottom == 'bottom':  #and isinstance(numeric, int)
            #This is for the question "which is the last team in the standings?"
            if numeric == None:
                numeric = 1

            if numeric == 1:
                text = ["The slowest qualifying time in " + returned_quali_phases + \
                        " in " + gp_names + year_text + \
                        "was " + returned_times[0] + ".", "It was made by " + returned_drivers[0] +\
                        " (" + returned_constructors[0] + ")."]
            else:
                quali_times = text_for_quali_times(returned_constructors,
                                                   returned_drivers,
                                                   returned_times)
                text = ["Below are the bottom " + str(numeric) + " qualifying times " +\
                        "for " + returned_quali_phases + " in " + gp_names + year_text + "."]
                text = text + quali_times

        else:
            quali_times = text_for_quali_times(returned_constructors,
                                               returned_drivers,
                                               returned_times)
            text = ["Below are the top 5 qualifying times " +\
                    "for " + returned_quali_phases + " in " + gp_names + year_text + "."]
            text = text + quali_times

    return text
示例#11
0
def text_for_race_result(returned_list, returned_positions, gp_names, \
        top_bottom, numeric, ordinal, driver, constructor, team_or_driver, \
        is_quali=False, year='current'):
    if len(returned_list) > 0 and len(returned_positions) > 0:
        #Get specific driver-team
        #if top_bottom==None and numeric==None and ordinal==None and (driver!=None or constructor!=None):

        year_text = text_for_year(year)

        if (driver != None or constructor != None):
            #TODO: Add reason for retirement
            for i, pos in enumerate(returned_positions):
                try:
                    returned_positions[i] = int(returned_positions[i])
                except Exception:
                    pass

            if (team_or_driver == 'team' or constructor != None):
                text = "The first " + specific_position_text(returned_list[0], returned_positions[0], gp_names, year_text, is_quali) + \
                        " and the second " + specific_position_text(returned_list[1], returned_positions[1], gp_names, year_text, is_quali) + "."
            else:
                text = specific_position_text(returned_list[0],
                                              returned_positions[0], gp_names,
                                              year_text, is_quali) + "."

        #Get specific number
        elif isinstance(ordinal, int):  #and top_bottom==None
            text = "The " + integer_to_ordinal(ordinal) + " " + team_or_driver_text(team_or_driver, singular=True) + \
                    " in " + gp_names + year_text + " was " + text_for_many_items(returned_list) + "."

        #Get top N drivers-teams
        elif (top_bottom == 'top' or ordinal == 1):
            if numeric == None:
                numeric = 1

            if numeric == 1:
                if is_quali == True:
                    text = "The pole sitter in " + gp_names + year_text + \
                            " was " + text_for_many_items(returned_list) + "."
                else:
                    text = "The winner in " + gp_names + year_text + \
                            " was " + text_for_many_items(returned_list) + "."
            else:
                text = "The first " + str(numeric) + " " + team_or_driver_text(team_or_driver, singular=False) + \
                        " in " + gp_names + year_text + " were " + text_for_many_items(returned_list) + "."

        #Get bottom N drivers-teams
        elif top_bottom == 'bottom':  #and isinstance(numeric, int)
            #This is for the question "which is the last team in the standings?"
            if numeric == None:
                numeric = 1
            if numeric == 1:
                text = "The last " + team_or_driver_text(team_or_driver, singular=True) \
                        + " in " + gp_names + year_text + " was " + \
                        text_for_many_items(returned_list) + "."
            else:
                text = "The last " + str(numeric) + " " + \
                        team_or_driver_text(team_or_driver, singular=False) + \
                        " in " + gp_names + year_text + " were " + \
                        text_for_many_items(returned_list) + "."

        else:
            if is_quali:
                text = ["Here is the final classification for the qualifying session in " + \
                        gp_names + year_text + ":"]
            else:
                text = ["Here is the final classification for the race in " + \
                        gp_names + year_text + ":"]

            #If the driver retired, show it in text
            for driver, pos in zip(returned_list, returned_positions):
                try:
                    pos = int(pos)
                except Exception:
                    pass
                if isinstance(pos, str) or isinstance(pos, unicode):
                    this_text = driver + " (" + pos + ")"
                else:
                    this_text = driver
                text.append(this_text)

    else:
        year_text = text_for_year(year)

        if (driver != None or constructor != None):
            if (team_or_driver == 'team' or constructor != None):
                text = "The first " + specific_position_text_not_raced(returned_list[0], gp_names, year_text, is_quali) + \
                        " and the second " + specific_position_text_not_raced(returned_list[1], gp_names, year_text, is_quali) + "."
            else:
                text = specific_position_text_not_raced(
                    returned_list[0], gp_names, year_text, is_quali) + "."

    if isinstance(text, str) or isinstance(text, unicode):
        text = [text]

    return text