public override CompetitorRanks GenerateResult(int tournamentRunSequence, MatchStrategies.MatchStrategy matchStrategy, List<Competitor> competitors) { CompetitorPoints randomPoints = new CompetitorPoints(); foreach (Competitor competitor in competitors) { randomPoints.Add(competitor, _randomPointsGenerator.Next(1, 1000)); } return randomPoints.GetCompetitorRanks(); }
public void GetCompetitorRanksTest() { var points = new CompetitorPoints(); double pointValue = 1.0; var competitors = Helpers.CompetitorListHelper.GetStandardCompetitors(8); foreach (var competitor in competitors) { points.Add(competitor, pointValue++); } var ranks = points.GetCompetitorRanks(); Assert.AreEqual(1, ranks[competitors[7]]); Assert.AreEqual(2, ranks[competitors[6]]); Assert.AreEqual(competitors.Count, ranks[competitors[0]]); }
protected static CompetitorPoints AccumulateMatchPoints(List<Match> matches) { CompetitorPoints competitorPoints = new CompetitorPoints(); foreach (Match match in matches) { if (!competitorPoints.ContainsKey(match.Winner)) competitorPoints.Add(match.Winner, 0); if (!competitorPoints.ContainsKey(match.Loser)) competitorPoints.Add(match.Loser, 0); competitorPoints[match.Winner]++; } return competitorPoints; }
/// <summary> /// Runs through all tournament rounds and accumulates the point totals to the competitors. /// </summary> /// <param name="tournamentRounds"></param> /// <remarks> /// This may not be appropriate for all cases, since multiple rounds might not carry over points from previous rounds, or /// rank may not be assigned purely on weight of total scores. /// </remarks> protected static CompetitorPoints AccumulatePointsFromTournamentRounds(List<TournamentRound> tournamentRounds) { CompetitorPoints competitorPoints = new CompetitorPoints(); foreach (TournamentRound tournamentRound in tournamentRounds) { foreach (Match match in tournamentRound.Matches) { if (!competitorPoints.ContainsKey(match.Winner)) competitorPoints.Add(match.Winner, 0); if (!competitorPoints.ContainsKey(match.Loser)) competitorPoints.Add(match.Loser, 0); competitorPoints[match.Winner]++; } } return competitorPoints; }
protected static new CompetitorPoints AccumulateMatchPoints(List<Match> matches) { List<Competitor> competitors = matches .Select(x => x.Winner) .Union(matches.Select(x => x.Loser)) .Distinct() .ToList<Competitor>(); CompetitorPoints competitorPoints = new CompetitorPoints(); foreach (Competitor competitor in competitors) { competitorPoints.Add(competitor, 0.0); } for (int i = 0; i < competitors.Count - 1; i++) { for (int j = i + 1; j < competitors.Count; j++) { Competitor competitorA = competitors[i]; Competitor competitorB = competitors[j]; List<Match> aWins = matches .Where(x => (x.Winner == competitorA && x.Loser == competitorB)) .ToList<Match>(); List<Match> bWins = matches .Where(x => (x.Winner == competitorB && x.Loser == competitorA)) .ToList<Match>(); if (aWins.Count > 0 || bWins.Count > 0) { competitorPoints[competitorA] += Convert.ToDouble(aWins.Count) / (Convert.ToDouble(aWins.Count) + Convert.ToDouble(bWins.Count)); competitorPoints[competitorB] += Convert.ToDouble(bWins.Count) / (Convert.ToDouble(aWins.Count) + Convert.ToDouble(bWins.Count)); } } } return competitorPoints; }
/// <summary> /// Computes the mean absolute difference between the expected and the observed tournament result. /// </summary> /// <param name="competitors"></param> /// <returns></returns> public double GetTournamentMAD(List<Competitor> competitors) { CompetitorPoints theoreticalRatings = new CompetitorPoints(); foreach (Competitor competitor in competitors) { theoreticalRatings.Add(competitor, competitor.TheoreticalRating); } CompetitorRanks theoreticalRanks = theoreticalRatings.GetCompetitorRanks(); // TODO: convert to using the StatisticsHelper or Iridium double[] competitorDiffs = theoreticalRanks .Select(x => Math.Abs((double)x.Value - (double)x.Key.TournamentRanks[RunSequence.Value])) .ToArray<double>(); return new Helpers.StatisticsHelper(competitorDiffs).Mean; }