Skip to content

Commit

Permalink
Fix ranks and average performance (#22)
Browse files Browse the repository at this point in the history
* Fix Ranks (no longer 1-index based, apparently) and therefore Average Performance.
  • Loading branch information
eduherminio authored Apr 16, 2021
1 parent b38935c commit 159cb26
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;osx-x64</RuntimeIdentifiers>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
<Version>0.2.2</Version>
<Version>0.3.0</Version>
<Authors>Eduardo Cáceres</Authors>
<Description>
Multiplatform desktop app that allows you to aggregate the results of multiple Lichess tournaments
Expand Down
10 changes: 3 additions & 7 deletions LichessTournamentAggregator.Test/AggregatedResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void Ranks()
new TournamentResult()
{
Username = Username,
Rank = 0
},
new TournamentResult()
{
Expand All @@ -234,7 +235,7 @@ public void Ranks()

foreach (var rank in aggregatedResult.Ranks)
{
Assert.Single(results, (result) => result.Username == aggregatedResult.Username && result.Rank == rank);
Assert.Single(results, (result) => result.Username == aggregatedResult.Username && result.Rank + 1 == rank);
}
}

Expand All @@ -243,11 +244,6 @@ public void AveragePerformance()
{
ICollection<TournamentResult> results = new[]
{
new TournamentResult()
{
Username = Username,
Rank = 0
},
new TournamentResult()
{
Username = Username,
Expand Down Expand Up @@ -277,7 +273,7 @@ public void AveragePerformance()
AggregatedResult aggregatedResult = new AggregatedResult(results.GroupBy(r => r.Username).Single(g => g.Key == Username));

Assert.Equal(
(double)results.Where(r => r.Username == Username).Sum(r => r.Performance) / results.Count(r => r.Username == Username && r.Rank != 0),
(double)results.Where(r => r.Username == Username).Sum(r => r.Performance) / results.Count(r => r.Username == Username),
aggregatedResult.AveragePerformance);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Title>LichessTournamentAggregator</Title>
<PackageId>LichessTournamentAggregator</PackageId>
<Version>0.3.2</Version>
<Version>0.4.0</Version>
<PackageTags>Chess, Lichess, Tournament, Aggregator</PackageTags>
<Tags>$(PackageTags)</Tags>
<Authors>Eduardo Cáceres</Authors>
Expand Down
4 changes: 2 additions & 2 deletions LichessTournamentAggregator/Model/AggregatedResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public AggregatedResult(IGrouping<string, TournamentResult> results)
Username = results.First().Username;
Title = results.First().Title;
MaxRating = results.Max(p => p.Rating);
Ranks = results.Select(p => p.Rank);
Ranks = results.Select(p => p.Rank + 1);
Scores = results.Select(p => CalculatePoints(p.Score));
TieBreaks = results.Select(p => p.TieBreak);
TotalScores = Scores.Sum();
TotalTieBreaks = TieBreaks.Sum();
AveragePerformance = (double)results.Select(p => p.Performance).Sum() / results.Count(p => p.Rank != 0);
AveragePerformance = (double)results.Select(p => p.Performance).Sum() / results.Count();
}

/// <summary>
Expand Down

0 comments on commit 159cb26

Please sign in to comment.