private void MatchesDataGrid_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Tab) { if (ViewModel.EventVM.Event == null) { return; } DataGridCellInfo cell = MatchesDataGrid.SelectedCells.LastOrDefault(); if (cell.Column.DisplayIndex == MatchesDataGrid.Columns.Count - 1 && MatchesDataGrid.Items.IndexOf(cell.Item) == MatchesDataGrid.Items.Count - 1) { e.Handled = true; Match m = new Match(); ViewModel.EventVM.Event.Matches.Add(m); ViewModel.RefreshDatagrid(); //MatchesDataGrid.SelectedItem = m; MatchesDataGrid.SelectedIndex = ViewModel.EventVM.Event.Matches.Count - 1; MatchesDataGrid.UpdateLayout(); } } }
public void SetMatchContext(Match match) { if (match != null) { ViewModel.RatedTeam = match.GetTeamByInclusiveIndex(TeamIndex); } ViewModel.IndicatedMatch = match; }
public RecordLite(Team team, Match match) { Team = team; TeamID = team != null ? team.Number : -1; Match = match; MatchID = match != null ? match.Number : -1; if (match != null) { Color = match.GetTeamColor(team); Position = match.GetTeamPosition(team); Ratings = new RatingSet(); } }
public void LoadEvent(string filepath) { if (!File.Exists(filepath)) { return; } FrcEvent temp = ScoutingJson.ParseFrcEvent(filepath); if (temp != null) { Event = temp; AppSettings.EventFile = filepath; if (Teams != null) { Event.PostJsonLoading(Teams); } SelectedMatch = Event.Matches.FirstOrDefault(); } UpdateTextBoxInfo(); }
private void UpdateMatchPostgame(Match match, MatchAnalysis analysis) { if (match == null || analysis == null) { MatchDefenseRedTxt.Text = "NULL"; MatchDefenseBlueTxt.Text = "NULL"; MatchGoalCountRedTxt.Text = "NULL"; MatchGoalCountBlueTxt.Text = "NULL"; return; } if (analysis.Pregame) { MatchDefenseRedTxt.Text = "PREGAME"; MatchDefenseBlueTxt.Text = "PREGAME"; MatchGoalCountRedTxt.Text = "PREGAME"; MatchGoalCountBlueTxt.Text = "PREGAME"; return; } MatchDefenseRedTxt.Text = analysis.RedDefenseMean.Value.ToString(); MatchDefenseBlueTxt.Text = analysis.BlueDefenseMean.Value.ToString(); MatchGoalCountRedTxt.Text = analysis.RedGoalCount.Value.ToString(); MatchGoalCountBlueTxt.Text = analysis.BlueGoalCount.Value.ToString(); }
private void UpdateMatchPregame(Match match, MatchAnalysis analysis) { if (match == null || analysis == null) { MatchWinrateRedTxt.Text = "NULL"; MatchWinrateBlueTxt.Text = "NULL"; MatchExpectedWinnerTxt.Text = "NULL"; MatchExpectedWinnerTxt.Foreground = new SolidColorBrush(TITLE_GRAY); MatchAdvantageTxt.Text = "NULL"; MatchExpectedFinalScoreRedTxt.Text = "NULL"; MatchExpectedFinalScoreBlueTxt.Text = "NULL"; MatchProfileTxt.Text = "NULL"; return; } MatchWinrateRedTxt.Text = analysis.RedWinRateMean.ToStringPct(); MatchWinrateBlueTxt.Text = analysis.BlueWinRateMean.ToStringPct(); MatchExpectedWinnerTxt.Text = analysis.ExpectedWinner.ToString(); MatchExpectedWinnerTxt.Foreground = new SolidColorBrush( analysis.ExpectedWinner == AllianceColor.Red ? LIGHT_RED : LIGHT_BLUE); MatchAdvantageTxt.Text = analysis.Advantage.ToString(); MatchExpectedFinalScoreRedTxt.Text = analysis.RedExpectedFinalScore.ToString(); MatchExpectedFinalScoreBlueTxt.Text = analysis.BlueExpectedFinalScore.ToString(); MatchProfileTxt.Text = analysis.GameProfileValue.ToString(); }
private void UpdateMatchSummary(Match match) { if (match == null) { MatchNumberTxt.Text = "Match NULL"; MatchRedTeamsTxt.Text = "####-####-####"; MatchBlueTeamsTxt.Text = "####-####-####"; MatchFinalScoreRedTxt.Text = "NULL"; MatchFinalScoreBlueTxt.Text = "NULL"; MatchFinalScoreLabelTxt.Visibility = System.Windows.Visibility.Collapsed; MatchFinalScoreRedTxt.Visibility = System.Windows.Visibility.Collapsed; MatchFinalScoreToTxt.Visibility = System.Windows.Visibility.Collapsed; MatchGoalCountBlueTxt.Visibility = System.Windows.Visibility.Collapsed; return; } MatchNumberTxt.Text = "Match " + match.Number.ToString(); MatchRedTeamsTxt.Text = match.RedAlliance.ToString(); MatchBlueTeamsTxt.Text = match.BlueAlliance.ToString(); if (match.Pregame) { MatchFinalScoreRedTxt.Text = "???"; MatchFinalScoreBlueTxt.Text = "???"; MatchFinalScoreLabelTxt.Visibility = System.Windows.Visibility.Collapsed; MatchFinalScoreRedTxt.Visibility = System.Windows.Visibility.Collapsed; MatchFinalScoreToTxt.Visibility = System.Windows.Visibility.Collapsed; MatchFinalScoreBlueTxt.Visibility = System.Windows.Visibility.Collapsed; } else { MatchFinalScoreRedTxt.Text = match.RedFinalScore.ToString(); MatchFinalScoreBlueTxt.Text = match.BlueFinalScore.ToString(); MatchFinalScoreLabelTxt.Visibility = System.Windows.Visibility.Visible; MatchFinalScoreRedTxt.Visibility = System.Windows.Visibility.Visible; MatchFinalScoreToTxt.Visibility = System.Windows.Visibility.Visible; MatchFinalScoreBlueTxt.Visibility = System.Windows.Visibility.Visible; } }
public MatchAnalysis LoadMatch(Match match) { return LoadMatch(match.Number); }
/// <summary> /// Gets the color for which the points from the goal went to. /// </summary> /// <param name="match">Match to extract data from</param> /// <returns>Color for whom the goal's points went to</returns> public AllianceColor GetScoringAlliance(Match match) { if (Global || ScoringAlliance == null) { return AllianceColor.Indeterminate; } return ScoringAlliance.Value; }
public static List<TeamDataContext> CreateDataList(Match m) { List<TeamDataContext> res = new List<TeamDataContext>(); res.Add(new TeamDataContext(m.BlueAlliance.A, AllianceColor.Blue)); res.Add(new TeamDataContext(m.BlueAlliance.B, AllianceColor.Blue)); res.Add(new TeamDataContext(m.BlueAlliance.C, AllianceColor.Blue)); res.Add(new TeamDataContext(m.RedAlliance.A, AllianceColor.Red)); res.Add(new TeamDataContext(m.RedAlliance.B, AllianceColor.Red)); res.Add(new TeamDataContext(m.RedAlliance.C, AllianceColor.Red)); return res; }
/// <summary> /// Instantiates a match analysis object with pregame analysis done. /// </summary> /// <param name="frc">Host event</param> /// <param name="m">Corresponding match</param> /// <param name="analyses">List of team analyses</param> public MatchAnalysis(FrcEvent frc, Match m, List<TeamAnalysis> analyses) { Event = frc; Match = m; TeamAnalyses = analyses; Pregame = m.Pregame; CalculatePregame(); }
public void UpdateRatingViewsMatch(Match m) { BlueAView.SetMatchContext(m); BlueBView.SetMatchContext(m); BlueCView.SetMatchContext(m); RedAView.SetMatchContext(m); RedBView.SetMatchContext(m); RedCView.SetMatchContext(m); }
public void UpdateIndicators(Match match) { if (match == null) { RedA.SetNumber(-1); RedB.SetNumber(-1); RedC.SetNumber(-1); BlueA.SetNumber(-1); BlueB.SetNumber(-1); BlueC.SetNumber(-1); return; } RedA.SetNumber(match.RedAlliance.TeamA_ID); RedB.SetNumber(match.RedAlliance.TeamB_ID); RedC.SetNumber(match.RedAlliance.TeamC_ID); BlueA.SetNumber(match.BlueAlliance.TeamA_ID); BlueB.SetNumber(match.BlueAlliance.TeamB_ID); BlueC.SetNumber(match.BlueAlliance.TeamC_ID); }
/// <summary> /// Forms a match from recorded data /// </summary> /// <param name="frc">Event to load additional data from</param> /// <param name="redData">Group of recordings from red's data</param> /// <param name="blueData">Group of recordings from blue's data</param> /// <returns></returns> public static Match FormMatch(FrcEvent frc, AllianceGroup<RecordedMatch> redData, AllianceGroup<RecordedMatch> blueData) { // Team data count (reliability) int redTeamsCount = redData.Count((rec) => rec != null); int blueTeamsCount = blueData.Count((rec) => rec != null); if (redTeamsCount + blueTeamsCount < 3 || redTeamsCount == 0 || blueTeamsCount == 0) // not enough data { return null; // Give up } Alliance red = new Alliance(redData.A.TrackedTeam, redData.B.TrackedTeam, redData.C.TrackedTeam); Alliance blue = new Alliance(blueData.A.TrackedTeam, blueData.B.TrackedTeam, blueData.C.TrackedTeam); List<RecordedMatch> allData = new List<RecordedMatch>(); foreach (RecordedMatch rec in redData) { allData.Add(rec); } foreach (RecordedMatch rec in blueData) { allData.Add(rec); } // MATCH ID (quadruple lambda!) int matchID = allData.ConvertAll<int>((rec) => rec.MatchNumber).Mode((modes) => { try { return modes.First((n) => { return !(frc.Matches.Exists((m) => m.Number == n && !m.Pregame)); }); } catch (InvalidOperationException) { Util.DebugLog(LogLevel.Warning, "SYNC", "Completed match with this ID is already present in event"); return modes.First(); } }); Match result = new Match(matchID, blue, red); result.Pregame = false; // This section is because Unprocessed and Landfill Litter type goals are shared, but // come more than one per match. double dRedLfLitter = redData.ToList().ConvertAll<int>((rec) => rec.ScoredGoals.Count( (g) => g.Type == GoalType.LandfillLitter)).Mean(); int nRedLfLitter = (int)dRedLfLitter; double dRedUnpLitter = redData.ToList().ConvertAll<int>((rec) => rec.ScoredGoals.Count( (g) => g.Type == GoalType.UnprocessedLitter)).Mean(); int nRedUnpLitter = (int)dRedUnpLitter; double dBlueLfLitter = blueData.ToList().ConvertAll<int>((rec) => rec.ScoredGoals.Count( (g) => g.Type == GoalType.UnprocessedLitter)).Mean(); int nBlueLfLitter = (int)dBlueLfLitter; double dBlueUnpLitter = blueData.ToList().ConvertAll<int>((rec) => rec.ScoredGoals.Count( (g) => g.Type == GoalType.UnprocessedLitter)).Mean(); int nBlueUnpLitter = (int)dBlueUnpLitter; // GOALS LIST List<Goal> goals = new List<Goal>(); goals.Sort((g1, g2) => g1.TimeScoredInt - g2.TimeScoredInt); foreach (RecordedMatch rec in allData) { foreach (Goal addedGoal in rec.ScoredGoals) { #region add by goal type switch (addedGoal.Type) { #region RobotSet case GoalType.RobotSet: bool alreadyHasRobotSet = goals.Exists((g) => { return g.Type == GoalType.RobotSet && g.ScoringAlliance == addedGoal.ScoringAlliance; }); if (!alreadyHasRobotSet) { goals.Add(addedGoal); } break; #endregion #region YellowToteSet case GoalType.YellowToteSet: bool alreadyHasYTS = goals.Exists((g) => { return g.Type == GoalType.YellowToteSet && g.ScoringAlliance == addedGoal.ScoringAlliance; }); if (!alreadyHasYTS) { goals.Add(addedGoal); } break; #endregion #region ContainerSet case GoalType.ContainerSet: bool alreadyHasContainerSet = goals.Exists((g) => { return g.Type == GoalType.ContainerSet && g.ScoringAlliance == addedGoal.ScoringAlliance; }); if (!alreadyHasContainerSet) { goals.Add(addedGoal); } break; #endregion #region Coopertition case GoalType.Coopertition: bool alreadyHasCoopertition = goals.Exists((g) => { return g.Type == GoalType.Coopertition; }); if (!alreadyHasCoopertition) { goals.Add(addedGoal); } break; #endregion case GoalType.GrayTote: goals.Add(addedGoal); break; case GoalType.ContainerTeleop: goals.Add(addedGoal); break; case GoalType.RecycledLitter: goals.Add(addedGoal); break; default: break; } #endregion } } for (int i = 0; i < nRedLfLitter; i++) { goals.Add(Goal.MakeLandfillLitter(AllianceColor.Red)); } for (int i = 0; i < nRedUnpLitter; i++) { goals.Add(Goal.MakeUnprocessedLitter(AllianceColor.Red)); } for (int i = 0; i < nBlueLfLitter; i++) { goals.Add(Goal.MakeLandfillLitter(AllianceColor.Blue)); } for (int i = 0; i < nBlueUnpLitter; i++) { goals.Add(Goal.MakeUnprocessedLitter(AllianceColor.Blue)); } result.Goals = goals; // PENALTIES List<Penalty> penalties = new List<Penalty>(); foreach (RecordedMatch rec in allData) { foreach (Penalty pen in rec.AlliancePenalties) { bool nearbyPenalty = penalties.Exists((p) => { return Math.Abs(p.TimeOfPenaltyInt - pen.TimeOfPenaltyInt) < PENALTY_THRESHOLD; }); if (!nearbyPenalty) { penalties.Add(pen); } } } result.Penalties = penalties; List<Goal> redGoals = result.RedGoals; int redGoalScore = redGoals.Aggregate(0, (total, g) => total + g.PointValue()); redGoalScore = result.RedPenalties.Aggregate(redGoalScore, (total, p) => total + p.ScoreChange()); List<Goal> blueGoals = result.BlueGoals; int blueGoalScore = blueGoals.Aggregate(0, (total, g) => total + g.PointValue()); blueGoalScore = result.BluePenalties.Aggregate(blueGoalScore, (total, p) => total + p.ScoreChange()); // WINNER List<AllianceColor> winnerRecords = allData.ConvertAll<AllianceColor>((rec) => rec.Winner); AllianceColor winner = winnerRecords.Mode((modes) => redGoalScore > blueGoalScore ? AllianceColor.Red : AllianceColor.Blue); // Incredibly unlikely result.Winner = winner; // WORKING result.RedWorking = new AllianceGroup<bool>(); result.RedWorking.A = redData.A != null ? redData.A.Working : true; result.RedWorking.B = redData.B != null ? redData.B.Working : true; result.RedWorking.C = redData.C != null ? redData.C.Working : true; result.BlueWorking = new AllianceGroup<bool>(); result.BlueWorking.A = blueData.A != null ? blueData.A.Working : true; result.BlueWorking.B = blueData.B != null ? blueData.B.Working : true; result.BlueWorking.C = blueData.C != null ? blueData.C.Working : true; // DEFENSE result.RedDefense = new AllianceGroup<int>(); result.RedDefense.A = redData.A != null ? redData.A.Defense : 5; result.RedDefense.B = redData.B != null ? redData.B.Defense : 5; result.RedDefense.C = redData.C != null ? redData.C.Defense : 5; result.BlueDefense = new AllianceGroup<int>(); result.BlueDefense.A = blueData.A != null ? blueData.A.Defense : 5; result.BlueDefense.B = blueData.B != null ? blueData.B.Defense : 5; result.BlueDefense.C = blueData.C != null ? blueData.C.Defense : 5; // DISCREPANCY POINTS int finalScoreRed = (int)redData.ToList().ConvertAll<int>((rec) => rec.AllianceFinalScore).Mean(); int finalScoreBlue = (int)blueData.ToList().ConvertAll<int>((rec) => rec.AllianceFinalScore).Mean(); // round down result.RedFinalScore = finalScoreRed; result.BlueFinalScore = finalScoreBlue; int dpRed = finalScoreRed - redGoalScore; int dpBlue = finalScoreBlue - blueGoalScore; result.RedDiscrepancyPoints = dpRed; result.BlueDiscrepancyPoints = dpBlue; return result; }
public MatchModel(Match arg_match) { match = arg_match; if (ViewModel.EventVM.Event == null) { return; } if (!ViewModel.EventVM.Event.Matches.Exists((m) => m.Number == match.Number)) { ViewModel.EventVM.Event.Matches.Add(match); } }