Esempio n. 1
0
def _complete_matches_teams(r):
    # Keep track of match numbers for fast lookup of if a match has already been added
    mtrack = {}

    event_teams = cache_or_get_json("teams" + r.key, bluealliance_download_file, "/event/" + r.key + "/teams")

    for t_small in event_teams:
        t = get_team(t_small["team_number"], t_small["nickname"])
        t.regionals.append(r.key)
        t.location = t_small["location"]
        t_large = cache_or_get_json(
            "team" + str(t.number) + "_" + str(r.year),
            bluealliance_download_file,
            "/team/frc" + str(t.number) + "/" + str(r.year),
        )
        event = next(ev for ev in t_large["events"] if ev["key"] == r.key)
        eliminated_in = "Quals"
        curr_index = 0
        MAPPINGS = {"qm": "Quals", "qf": "Quarters", "sf": "Semis", "f": "Finals"}
        ORDER = ["qm", "qf", "sf", "f"]

        for m in event["matches"]:
            ind = ORDER.index(m["comp_level"])
            if ind > curr_index:
                curr_index = ind
                eliminated_in = MAPPINGS[m["comp_level"]]

            mtrack_id = str(m["match_number"]) + m["comp_level"]
            if mtrack_id not in mtrack:
                # Create a match object from the match model.
                m_obj = Match(
                    m["match_number"],
                    [get_team(int(t.replace("frc", "")), None) for t in m["alliances"]["red"]["teams"]],
                    [get_team(int(t.replace("frc", "")), None) for t in m["alliances"]["blue"]["teams"]],
                    int(m["alliances"]["red"]["score"]),
                    int(m["alliances"]["blue"]["score"]),
                )
                t.matches.append(m_obj)
                mtrack[mtrack_id] = len(r.matches)
                r.matches.append(m_obj)
            else:
                t.matches.append(r.matches[mtrack[mtrack_id]])

        t.eliminated[r.key] = eliminated_in

        # Locate any awards for this team...
        t.awards[r.key] = []
        for award in event["awards"]:
            for recipient in award["recipient_list"]:
                if recipient["team_number"] == t.number:
                    if recipient["awardee"]:
                        t.awards[r.key].append(award["name"] + " (to " + recipient["awardee"] + ")")
                        if "winner" in award["name"].lower():
                            t.elimiated = "Win"
                    else:
                        t.awards[r.key].append(award["name"])

        r.teams.append(t)
Esempio n. 2
0
def _minimal_complete_teams(r):
    r.teams = [
        get_team(t_raw["team_number"], t_raw["nickname"])
        for t_raw in cache_or_get_json("teams" + r.key, bluealliance_download_file, "/event/" + r.key + "/teams")
    ]
Esempio n. 3
0
def usfirst_scrape_matches(reg_id):
    return [Match(int(id), time, [get_team(int(red1)), get_team(int(red2)), get_team(int(red3))],
                  [get_team(int(blue1)), get_team(int(blue2)), get_team(int(blue3))])
            for time, id, red1, red2, red3, blue1, blue2, blue3 in cache_or_get_json('matches' + reg_id, usfirst_scrape_matches_impl, reg_id)]