def get_ILS(event, quals, teams, team_stats, team_matches): min_ils = -1 / 3 out = {} for team in teams: out[team] = np.zeros(shape=(len(quals) + 1, 2)) out[team][0] = [ team_stats[team]["ils_1_start"], team_stats[team]["ils_2_start"], ] for i, m in enumerate(quals): red, blue = m["red"], m["blue"] adjust_red_1 = (m["red_rp_1"] - logistic(sum([out[r][i][0] for r in red]))) / 10 adjust_red_2 = (m["red_rp_2"] - logistic(sum([out[r][i][1] for r in red]))) / 10 adjust_blue_1 = ( m["blue_rp_1"] - logistic(sum([out[b][i][0] for b in blue])) ) / 10 adjust_blue_2 = ( m["blue_rp_2"] - logistic(sum([out[b][i][1] for b in blue])) ) / 10 for t in teams: out[t][i + 1] = out[t][i] if t in red: out[t][i + 1][0] = max(min_ils, out[t][i][0] + adjust_red_1) out[t][i + 1][1] = max(min_ils, out[t][i][1] + adjust_red_2) elif t in blue: out[t][i + 1][0] = max(min_ils, out[t][i][0] + adjust_blue_1) out[t][i + 1][1] = max(min_ils, out[t][i][1] + adjust_blue_2) return out
def get_ILS(event, quals): min_ils = -1 / 3 teams, out = [], {} for team_event in event.team_events: teams.append(team_event.team_id) out[teams[-1]] = np.zeros(shape=(len(quals) + 1, 2)) curr = [team_event.ils_1_start, team_event.ils_2_start] out[teams[-1]][0] = np.array(curr) for i, m in enumerate(quals): red, blue = m.getTeams() adjust_red_1 = (m.red_rp_1 - logistic(sum([out[r][i][0] for r in red]))) / 10 adjust_red_2 = (m.red_rp_2 - logistic(sum([out[r][i][1] for r in red]))) / 10 adjust_blue_1 = (m.blue_rp_1 - logistic(sum([out[b][i][0] for b in blue]))) / 10 adjust_blue_2 = (m.blue_rp_2 - logistic(sum([out[b][i][1] for b in blue]))) / 10 for t in teams: out[t][i + 1] = out[t][i] if t in red: out[t][i + 1][0] = max(min_ils, out[t][i][0] + adjust_red_1) out[t][i + 1][1] = max(min_ils, out[t][i][1] + adjust_red_2) elif t in blue: out[t][i + 1][0] = max(min_ils, out[t][i][0] + adjust_blue_1) out[t][i + 1][1] = max(min_ils, out[t][i][1] + adjust_blue_2) return out
def rp_prob(teams): return logistic(sum(teams))
def process_event(event, quals, playoffs, year, sd_score, team_ils_1, team_ils_2): oprs, ils = opr_model.opr_v2(event, quals, playoffs) opr_acc, opr_mse, mix_acc, mix_mse, count = 0, 0, 0, 0, 0 rp1_acc, rp1_mse, rp2_acc, rp2_mse, count_rp = 0, 0, 0, 0, 0 for i, m in enumerate(sorted(quals) + sorted(playoffs)): red, blue = m.getRed(), m.getBlue() red_oprs, blue_oprs = [], [] ind = -1 if m.playoff == 1 else i for r in red: if r in oprs and len(oprs[r]) > 0 and ind <= len(oprs[r]): red_oprs.append(clean(oprs[r][ind][0])) for b in blue: if b in oprs and len(oprs[b]) > 0 and ind <= len(oprs[b]): blue_oprs.append(clean(oprs[b][ind][0])) win_probs = {"red": 1, "blue": 0, "draw": 0.5} red_sum, blue_sum = sum(red_oprs), sum(blue_oprs) m.red_opr_sum, m.blue_opr_sum = red_sum, blue_sum m.opr_winner = "red" if red_sum > blue_sum else "blue" m.opr_win_prob = opr_model.win_prob(red_sum, blue_sum, year, sd_score) opr_mse += (win_probs[m.winner] - m.opr_win_prob)**2 if m.opr_winner == m.winner: opr_acc += 1 m.mix_win_prob = 0.5 * (m.elo_win_prob + m.opr_win_prob) m.mix_winner = "red" if m.mix_win_prob > 0.5 else "blue" mix_mse += (win_probs[m.winner] - m.mix_win_prob)**2 if m.winner == m.mix_winner: mix_acc += 1 count += 1 """ILS STATS""" if year >= 2016 and m.playoff == 0: # only predict on quals as elims don't have Ranking Points m.red_ils_1_sum = red_ils_1_sum = sum( [clean(ils[r][ind][0]) for r in red]) m.red_ils_2_sum = red_ils_2_sum = sum( [clean(ils[r][ind][1]) for r in red]) m.blue_ils_1_sum = blue_ils_1_sum = sum( [clean(ils[b][ind][0]) for b in blue]) m.blue_ils_2_sum = blue_ils_2_sum = sum( [clean(ils[b][ind][1]) for b in blue]) m.red_rp_1_prob = red_rp_1_prob = logistic(red_ils_1_sum) m.red_rp_2_prob = red_rp_2_prob = logistic(red_ils_2_sum) m.blue_rp_1_prob = blue_rp_1_prob = logistic(blue_ils_1_sum) m.blue_rp_2_prob = blue_rp_2_prob = logistic(blue_ils_2_sum) red_rp_1, red_rp_2 = m.red_rp_1, m.red_rp_2 blue_rp_1, blue_rp_2 = m.blue_rp_1, m.blue_rp_2 if int(red_rp_1_prob + 0.5) == red_rp_1: rp1_acc += 1 if int(red_rp_2_prob + 0.5) == red_rp_2: rp2_acc += 1 if int(blue_rp_1_prob + 0.5) == blue_rp_1: rp1_acc += 1 if int(blue_rp_2_prob + 0.5) == blue_rp_2: rp2_acc += 1 rp1_mse += (red_rp_1_prob - red_rp_1)**2 rp2_mse += (red_rp_2_prob - red_rp_2)**2 rp1_mse += (blue_rp_1_prob - blue_rp_1)**2 rp2_mse += (blue_rp_2_prob - blue_rp_2)**2 count_rp += 2 opr_stats = [opr_acc, opr_mse, mix_acc, mix_mse, count] rp_stats = [rp1_acc, rp1_mse, rp2_acc, rp2_mse, count_rp] event.opr_acc = round(opr_acc / count, 4) event.opr_mse = round(opr_mse / count, 4) event.mix_acc = round(mix_acc / count, 4) event.mix_mse = round(mix_mse / count, 4) if count_rp > 0: event.rp1_acc = round(rp1_acc / count_rp, 4) event.rp1_mse = round(rp1_mse / count_rp, 4) event.rp2_acc = round(rp2_acc / count_rp, 4) event.rp2_mse = round(rp2_mse / count_rp, 4) stats = opr_stats + rp_stats return oprs, ils, team_ils_1, team_ils_2, stats