def calcPoints(team, event): draftPoints = 0 rankPoints = 0 elimPoints = 0 eM = gen.readEventCsv( event, 'matches', names=['key', 'r1', 'r2', 'r3', 'b1', 'b2', 'b3', 'rScore', 'bScore']) teamMatches = eM[(eM.r1 == team) | (eM.r2 == team) | (eM.r3 == team) | (eM.b1 == team) | (eM.b2 == team) | (eM.b3 == team)] rK = gen.readEventCsv(event, 'rankings') tmpRk = rK[rK.Team == team] if len(tmpRk) > 0: teamRank = rK[rK.Team == team]['Rank'].iloc[0] teamCount = len(rK) alpha = 1.07 rankPoints = math.ceil( abs( erfinv((teamCount - 2 * teamRank + 2) / (alpha * teamCount)) * 10 / erfinv(1 / alpha) + 12)) aL = gen.readEventCsv(event, 'alliances', names=['captain', 'firstPick', 'secondPick']) aLL = aL[(aL.captain == team) | (aL.firstPick == team) | (aL.secondPick == team)] if len(aLL) > 0: alliance = {'pick': 9, 'number': 9} alliance['number'] = aLL.index.values[0] if aLL['captain'].values[0] == team: alliance['pick'] = 0 elif aLL['firstPick'].values[0] == team: alliance['pick'] = 1 elif aLL['secondPick'].values[0] == team: alliance['pick'] = 2 if alliance['pick'] < 2: draftPoints = 17 - alliance['number'] elif alliance['pick'] == 2: draftPoints = alliance['number'] #Find points for playing in elims for idx, match in teamMatches.iterrows(): if match['key'].split('_')[1][:2] != 'qm': onRed = (match['r1'] == team) or (match['r2'] == team) or (match['r3'] == team) onBlue = not onRed redWins = match['rScore'] > match['bScore'] blueWins = match['bScore'] > match['rScore'] if (onRed and redWins) or (onBlue and blueWins): elimPoints += 5 return draftPoints + rankPoints + elimPoints
def getPlayPoints(team, event): draftPoints = 0 rankPoints = 0 elimPoints = 0 teamRank = 0 teamMatches = gen.teamEventMatches(team, event) tmpRk = [] try: rK = gen.readEventCsv(event, 'rankings') if str(rK['Team'][0]).isnumeric(): rK['Team'] = 'frc' + rK['Team'].astype(str) tmpRk = rK[rK.Team == team] if len(tmpRk) > 0: teamRank = rK[rK.Team == team]['Rank'].iloc[0] teamCount = len(rK) alpha = 1.07 rankPoints = math.ceil( abs( erfinv((teamCount - 2 * teamRank + 2) / (alpha * teamCount)) * 10 / erfinv(1 / alpha) + 12)) names = ['captain', 'firstPick', 'secondPick'] aL = gen.readEventCsv(event, 'alliances', names) aLL = aL[(aL.captain == team) | (aL.firstPick == team) | (aL.secondPick == team)] if len(aLL) > 0: alliance = {'pick': 9, 'number': 9} alliance['number'] = aLL.index.values[0] if aLL['captain'].values[0] == team: alliance['pick'] = 0 elif aLL['firstPick'].values[0] == team: alliance['pick'] = 1 elif aLL['secondPick'].values[0] == team: alliance['pick'] = 2 if alliance['pick'] < 2: draftPoints = 17 - int(alliance['number']) elif alliance['pick'] == 2: draftPoints = int(alliance['number']) if teamMatches is not None: for idx, match in teamMatches.iterrows(): if match['key'].split('_')[1][:2] != 'qm': if gen.matchResult(team, match, False) == 'WIN': elimPoints += 5 except: pass return [draftPoints, rankPoints, elimPoints, teamRank]
def getPerformanceData(team, year): team = gen.teamString(team) oprs = [] wins = 0 losses = 0 ties = 0 try: matches = gen.readTeamCsv(team, 'matches', year) if len(matches) > 0: for idx, match in matches.iterrows(): result = gen.matchResult(team, match) wins += 'WIN' == result losses += 'LOSS' == result ties += 'TIE' == result except: print("Could not retrieve matches for", team) try: events = gen.readTeamCsv(team, 'events', year) if len(events) > 0: for idx, e in events.iterrows(): try: eOprs = gen.readEventCsv(e['Event'], 'opr') teamOPR = eOprs[eOprs.Team == team]['OPR'].values[0] oprs.append(teamOPR) except Exception as e: print(e) except: print("Could not retrieve events for", team) if len(oprs) is 0: maxOPR = 0 avgOPR = 0 else: maxOPR = max(oprs) avgOPR = stat.mean(oprs) played = wins + losses + ties winPercent = 0 if played > 0: winPercent = wins / played teamKey = gen.teamNumber(team) return { 'Team': teamKey, 'Max OPR': maxOPR, 'Avg OPR': avgOPR, 'Wins': wins, 'Losses': losses, 'Ties': ties, 'Win %': winPercent }
def teamListHelper(event): teams = gen.readEventCsv(event, 'teams') if teams is None: matches = tba.event_matches(event) for match in matches: for team in match['alliances']['red']['team_keys']: if team not in teams: teams.append(team) for team in match['alliances']['blue']['team_keys']: if team not in teams: teams.append(team) return teams
def getTeamEventPoints(team, event, useTba=False, eventSize=None): awardPoints = 0 playPoints = 0 team = gen.teamString(team) if useTba == True: eventInfo = tba.event(event) isChamps = eventInfo['event_type'] in range(3, 5) else: eventInfo = gen.readEventCsv(event, 'info') isChamps = eventInfo['Type'][0] in range(3, 5) eventType = 'CMP' if isChamps else 'REG' if eventInfo is not None: playPoints = getPlayPoints(team, event, eventType, useTba, False, eventSize) awardPoints = getAwardPoints(team, event, eventType, useTba) return [playPoints, awardPoints]
def calcEventMCA(team, event): eventMCA = 0 teamAwards = gen.readTeamCsv('frc' + str(team), 'awards', int(event[:4])) #Don't bother doing calc if the team didn't win awards that year #This check is duplicated in calcYearMCA, but included here as well in case #function is run independently. if teamAwards is not None: eventFilter = teamAwards['Event'] == event currentAwards = teamAwards[eventFilter] #If the team didn't win any awards at this event don't calc. if not currentAwards.empty: eventValuation = len(gen.readEventCsv(event, 'teams')) / baseTeamCount for idx, award in currentAwards.iterrows(): if award['Type'] in awardValues: #For CA Finalist or Honorable Mention treat it as 100 team event if award['Type'] == awardTypes.CHAIRMANS_FINALIST or award[ 'Type'] == awardTypes.CHAIRMANS_HONORABLE_MENTION: eventValuation = 2 eventMCA += eventValuation * awardValues[award['Type']] return eventMCA
currentTeams = tba.district_teams(str(currentYear) + district, False, True) teamData = [] for team in currentTeams: events = gen.readTeamCsv(team, 'events', currentYear - 1) tm = tba.team(team) maxOPR = 0 totalOPR = 0 avgOPR = 0 eventAdjust = 0 if events is not None: seasonEvents = events[events.Type < 4]['Event'] for event in seasonEvents: eventData = gen.readEventCsv(event, 'opr') teamRow = eventData[eventData['Team'] == team] if teamRow.empty: eventAdjust += 1 newOPR = 0 else: newOPR = teamRow['OPR'].values[0] totalOPR += newOPR if maxOPR < newOPR: maxOPR = newOPR if len(events) != 0: avgOPR = totalOPR / (len(events) - eventAdjust)
def getPlayPoints(team, event, eventType, useTba=False, breakDown=False, eventSize=None): draftPoints = 0 rankPoints = 0 elimPoints = 0 if useTba == True: try: teamMatches = tba.team_matches(team, event, None, True) teamStats = tba.team_status(team, event) alliance = teamStats['alliance'] if alliance is not None: if alliance['pick'] < 2: draftPoints = 17 - alliance['number'] elif alliance['pick'] == 2: draftPoints = alliance['number'] if eventSize is not None: teamCount = eventSize else: teamCount = teamStats['qual']['num_teams'] teamRank = teamStats['qual']['ranking']['rank'] alpha = 1.07 rankPoints = math.ceil( abs( erfinv((teamCount - 2 * teamRank + 2) / (alpha * teamCount)) * 10 / erfinv(1 / alpha) + 12)) for match in teamMatches: if match['comp_level'] != "qm": if gen.matchResult(team, match, useTba) == 'WIN': elimPoints += 5 except: pass else: teamMatches = gen.teamEventMatches(team, event) tmpRk = [] try: rK = gen.readEventCsv(event, 'rankings') tmpRk = rK[rK.Team == team] except: pass if len(tmpRk) > 0: teamRank = rK[rK.Team == team]['Rank'].iloc[0] teamCount = len(rK) alpha = 1.07 rankPoints = math.ceil( abs( erfinv((teamCount - 2 * teamRank + 2) / (alpha * teamCount)) * 10 / erfinv(1 / alpha) + 12)) names = ['captain', 'firstPick', 'secondPick'] if eventType == 'CMP': names = ['captain', 'firstPick', 'secondPick', 'thirdPick'] aL = gen.readEventCsv(event, 'alliances', names) if aL is not None: aLL = aL[(aL.captain == team) | (aL.firstPick == team) | (aL.secondPick == team)] if len(aLL) > 0: alliance = {'pick': 9, 'number': 9} alliance['number'] = aLL.index.values[0] if aLL['captain'].values[0] == team: alliance['pick'] = 0 elif aLL['firstPick'].values[0] == team: alliance['pick'] = 1 elif aLL['secondPick'].values[0] == team: alliance['pick'] = 2 if alliance['pick'] < 2: draftPoints = 17 - int(alliance['number']) elif alliance['pick'] == 2: draftPoints = int(alliance['number']) #Find points for playing in elims if teamMatches is not None: for idx, match in teamMatches.iterrows(): if match['key'].split('_')[1][:2] != 'qm': result = gen.matchResult(team, match, useTba) if result == 'WIN': elimPoints += 5 res = draftPoints + rankPoints + elimPoints if breakDown: res = [draftPoints, rankPoints, elimPoints] return res
rookies = [] for team in currTeams: prevYears = slff.getTeamYears(team, rookieYear - 1) if len(prevYears) == 0: print(team) #Event data (ranks, opr) events = gen.readTeamCsv(team, 'events', currentYear) ranks = [] oprs = [] avgOpr = 0 avgRank = 99 if events is not None: for event in events['Event']: rank = gen.readEventCsv(event, 'rankings') opr = gen.readEventCsv(event, 'opr') if opr is not None: oprs.append(opr[opr.Team == team]['OPR'].values[0]) else: print("Couldn't get OPR data for", event) if rank is not None: if len(rank.columns) > 2: rank = rank[['Rank', 'Team']] if str(rank['Team'][0])[:3] != 'frc': rank['Team'] = 'frc' + rank['Team'].astype(str) rnk = rank[rank.Team == team]['Rank'] if len(rnk) > 0: ranks.append(rnk.values[0]) if len(oprs) > 0:
def teamAtEvent(team, event): ROBOT_AWARDS = [16, 17, 20, 21, 29, 71] OTHER_AWARDS = [5, 11, 13, 14, 18, 22, 27, 30] NO_POINTS = [1, 2] CA = 0 EI = 9 WF = 3 DEANS = 4 RAS = 10 RI = 15 CAF = 69 WILDCARD = 68 awardData = { 'REG': { CA: 25, EI: 15, RAS: 5, RI: 5, WF: 5, DEANS: 5, WILDCARD: 0, 'ROBOT': 10, 'OTHER': 5, 'NONE': 0 }, 'CMP': { CA: 110, EI: 60, RAS: 35, RI: 20, WF: 30, DEANS: 15, CAF: 90, 'ROBOT': 30, 'OTHER': 10, 'NONE': 0 } } awardPoints = 0 playPoints = 0 #Fetch event info, do this first since we only want to really process official events. eventInfo = gen.readEventCsv(event, 'info') if eventInfo is not None: isOfficial = eventInfo['Type'][0] in range(0, 7) isChamps = eventInfo['Type'][0] in range(3, 5) eventType = 'CMP' if isChamps else 'REG' if isOfficial: playPoints = calcPoints(team, event) tya = gen.readTeamCsv(team, 'awards', event[:4]) if tya is not None: teamEventAwards = tya[tya.Event == event] for idx, row in teamEventAwards.iterrows(): awardType = row['Type'] if awardType in ROBOT_AWARDS: awardType = 'ROBOT' if awardType in OTHER_AWARDS: awardType = 'OTHER' if awardType in NO_POINTS: awardType = 'NONE' awardPoints += awardData[eventType][awardType] return [playPoints, awardPoints]