public static void ProcessMatchInformations(IList <MatchInformation> matchInformations) { RawMatchData.AddRange(matchInformations); foreach (var matchInfo in matchInformations) { var fighter1 = GetOrCreateFighter(matchInfo.Fighter1); var fighter2 = GetOrCreateFighter(matchInfo.Fighter2); if (fighter1 == null || fighter2 == null) { continue; } // Win / loss by points? var resultByPoints = matchInfo.Method.ToLower().Contains("pts") || matchInfo.Method.ToLower().Contains("points"); MatchResult result; switch (matchInfo.Result) { case ("W"): result = resultByPoints ? MatchResult.WinByPoints : MatchResult.WinBySubmission; break; case ("L"): result = resultByPoints ? MatchResult.LossByPoints : MatchResult.LossBySubmission; break; case ("D"): result = MatchResult.Draw; break; default: throw new ArgumentException("Result could not be analyzed!"); } int year; if (!Int32.TryParse(matchInfo.Year, out year)) { year = 0; } var match = new MatchWithoutId() { Fighter1 = fighter1, Fighter2 = fighter2, Result = result, Year = year }; Matches.Add(match); } }
/// <summary> /// Calculates the points won or lost by the fighters in the match. /// The result has to be added to the elo rating of fighter 1, and subtracted from the elo rating of fighter 2. /// </summary> private static double CalculateEloPoints(MatchWithoutId match) { // The expected result of the match. Between 0 (loss by submission) and 1 (win by submission). var expectedResult = 1 / (1 + Math.Pow(10, (double)(match.Fighter2.EloRating - match.Fighter1.EloRating) / Constants.EloDifference)); // The actual result of the match. double actualResult; switch (match.Result) { case (MatchResult.WinBySubmission): actualResult = 1.0; break; case (MatchResult.WinByPoints): actualResult = Constants.WinByPointsFactor; break; case (MatchResult.Draw): actualResult = 0.5; break; case (MatchResult.LossByPoints): actualResult = 1 - Constants.WinByPointsFactor; break; case (MatchResult.LossBySubmission): actualResult = 0; break; default: throw new ArgumentException("Invalid match result detected!"); } // The points won or lost by the fighters. var eloDifference = Constants.EloFactor * (actualResult - expectedResult); return(eloDifference); }
private void dataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { var fighter = dataGrid.SelectedItem as Fighter; var matchesOfSelectedFighter1 = matches .Where(m => m.Fighter1 == fighter) .Select(m => new { Opponent = m.Fighter2, Rating = (int)m.Fighter2.EloRating, Result = m.Result, Year = m.Year }); var matchesOfSelectedFighter2 = matches .Where(m => m.Fighter2 == fighter) .Select(m => new { Opponent = m.Fighter1, Rating = (int)m.Fighter1.EloRating, Result = MatchWithoutId.InvertMatchResult(m.Result), Year = m.Year }); dataGrid1.ItemsSource = matchesOfSelectedFighter1.Concat(matchesOfSelectedFighter2).ToList(); }