Exemple #1
0
def tft_helper(
    comma_separated_roster: Type.string,
    comma_separated_exclude: Type.string,
    level: Type.int,
):
    r, cache_hit = cache_frame(inspect.currentframe())
    if r is not None:
        return r, cache_hit

    champs, synergies = parse_yaml()
    roster = {
        k: champs[k]
        for k in comma_separated_roster.split(",") if len(k) > 0
    }
    unused = {
        name: info
        for name, info in champs.items() if name not in roster.keys()
        and name not in comma_separated_exclude.split("/")
    }
    combos = combinations(list(unused.keys()), level - len(roster.keys()))

    top_score = 0
    top_roster = None
    top_synergies = None
    for combo in combos:
        new_roster = roster.copy()
        for champ in combo:
            new_roster.update({champ: champs[champ]})
        strengths = get_synergies(new_roster, synergies)
        if score_synergies(strengths) > top_score:
            top_score = score_synergies(strengths)
            top_roster = new_roster
            top_synergies = strengths

    return {"synergies": top_synergies, "roster": top_roster}
Exemple #2
0
def most_awards_per_state(award_id: Type.int, num_per_state: Type.int):
    # https://github.com/the-blue-alliance/the-blue-alliance/blob/master/consts/award_type.py#L6
    r, cache_hit = cache_frame(inspect.currentframe())
    if r is not None:
        return r, cache_hit

    events = [call(tba.events, year=y) for y in range(1992, 2019)]
    events = helpers.flatten_lists(events)
    events = helpers.filter_official_events(events)
    events = list(filter(lambda e: e["country"] in ["USA", "Canada"], events))
    key_to_state = {e["key"]: e["state_prov"] for e in events}
    event_awards = batch_call(events, tba.event_awards, lambda e: [],
                              lambda e: {"event": e["key"]})
    win_counts = defaultdict(lambda: defaultdict(lambda: 0))
    for awards_list in event_awards:
        for award in awards_list:
            if award["award_type"] == award_id:
                for recipient in award["recipient_list"]:
                    win_counts[key_to_state[award["event_key"]]][
                        recipient["team_key"]] += 1

    top5_per_state = {}
    for state, leaderboard in win_counts.items():
        leaderboard = sorted(leaderboard.items(), key=lambda t: -t[1])
        top5_per_state[state] = leaderboard[:num_per_state]

    return top5_per_state
Exemple #3
0
def score_event(event_key: Type.string):
    r, cache_hit = cache_frame(inspect.currentframe())
    if r is not None:
        return r, cache_hit

    data = []
    for team in tba.event_teams(event=event_key):
        ret = score_team_event(team_number=team["team_number"], event_key=event_key, refresh=True, wk=10)
        if type(ret) is tuple:
            ret, _ = ret

        data.append(
            [
                team["team_number"],
                ret["alliance"],
                ret["award"],
                ret["elim"],
                ret["qual"],
                ret["total"],
            ]
        )

    data.sort(key=lambda r: -r[-1])
    data = [["Team", "Alliance", "Award", "Elim", "Qual", "Total"]] + data
    return data
Exemple #4
0
def worlds_foldy_sheet(region: Type.string):
    r, cache_hit = cache_frame(inspect.currentframe())
    if r is not None:
        return r, cache_hit

    perms = None
    if region.upper() == "LCK":
        perms = generate_lck_perms()
    if region.upper() == "LCS":
        perms = generate_lcs_perms()
    if region.upper() == "LEC":
        perms = generate_lec_perms()
    if region.upper() == "LPL":
        perms = generate_lpl_perms()
    if region.upper() == "LMS":
        perms = generate_lms_perms()

    return perms_to_foldy(region, perms)
Exemple #5
0
def team_info(team_number: Type.int):
    r, cache_hit = cache_frame(inspect.currentframe())
    if r is not None:
        return r, cache_hit

    return call(tba.team, team=team_number)
Exemple #6
0
def add(a: Type.int, b: Type.int):
    r, cache_hit = cache_frame(inspect.currentframe())
    if r is not None:
        return r, cache_hit

    return a + b
Exemple #7
0
def head_to_head(team_1: Type.int, team_2: Type.int):
    r, cache_hit = cache_frame(inspect.currentframe())
    if r is not None:
        return r, cache_hit

    origin_key = f"frc{max(team_1, team_2)}"
    target_key = f"frc{min(team_1, team_2)}"

    rookie_year = call(tba.team, team=origin_key)["rookie_year"]

    won_together = 0
    lost_together = 0
    tied_together = 0

    won_against = 0
    lost_against = 0
    tied_against = 0

    for year in range(rookie_year, 2019):
        matches = call(tba.team_matches, team=origin_key, year=year, simple=True)
        for match in matches:
            event = call(tba.event, event=match["event_key"])
            if event["event_type_string"] == "Offseason":
                continue
            blue = match["alliances"]["blue"]["team_keys"]
            red = match["alliances"]["red"]["team_keys"]

            if match["event_key"][:4] == "2015":
                if (
                    match["alliances"]["blue"]["score"]
                    > match["alliances"]["red"]["score"]
                ):
                    winner = "blue"
                elif (
                    match["alliances"]["blue"]["score"]
                    < match["alliances"]["red"]["score"]
                ):
                    winner = "red"
                else:
                    winner = ""
            else:
                winner = match["winning_alliance"]

            if origin_key in blue:
                if target_key in blue:
                    if winner == "blue":
                        won_together += 1
                    elif winner == "red":
                        lost_together += 1
                    else:
                        tied_together += 1
                elif target_key in red:
                    if winner == "blue":
                        won_against += 1
                    elif winner == "red":
                        lost_against += 1
                    else:
                        tied_against += 1
            else:
                if target_key in blue:
                    if winner == "blue":
                        lost_against += 1
                    elif winner == "red":
                        won_against += 1
                    else:
                        tied_against += 1
                elif target_key in red:
                    if winner == "blue":
                        lost_together += 1
                    elif winner == "red":
                        won_together += 1
                    else:
                        tied_together += 1

    together_pct = round(
        won_together * 100 / max(won_together + tied_together + lost_together, 1), 1
    )
    against_pct = round(
        won_against * 100 / max(won_against + tied_against + lost_against, 1), 1
    )
    s = (
        f"{origin_key} with {target_key} is "
        f"{won_together}-{lost_together}-{tied_together} ({together_pct}%)"
    )
    s += (
        "<br>" + f"{origin_key} against {target_key} is "
        f"{won_against}-{lost_against}-{tied_against} ({against_pct}%)"
    )
    return s
Exemple #8
0
def score_slff(team_number: Type.int, event_key: Type.string):
    r, cache_hit = cache_frame(inspect.currentframe())
    if r is not None:
        return r, cache_hit

    return score_team_event(team_number, event_key, refresh=True, wk=10)