Skip to content

Commit

Permalink
Add unstarted teams/no launched challenge teams to enrollment report …
Browse files Browse the repository at this point in the history
…summary
  • Loading branch information
sei-bstein committed Oct 14, 2024
1 parent a616f81 commit f386200
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public sealed class EnrollmentReportStatSummary
public required int DistinctSponsorCount { get; set; }
public required EnrollmentReportStatSummarySponsorPlayerCount SponsorWithMostPlayers { get; set; }
public required int DistinctTeamCount { get; set; }
public required double TeamsWithNoSessionCount { get; set; }
public required double TeamsWithNoStartedChallengeCount { get; set; }
}

public sealed class EnrollmentReportStatSummarySponsorPlayerCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,21 @@ public async Task<IOrderedEnumerable<EnrollmentReportRecord>> GetRawResults(Enro

public async Task<EnrollmentReportStatSummary> GetSummaryStats(EnrollmentReportParameters parameters, CancellationToken cancellationToken)
{
var query = GetBaseQuery(parameters);
var query = GetBaseQuery(parameters)
.Select(p => new
{
Player = p,
ChallengesStarted = p.Challenges.Where(c => c.StartTime != DateTimeOffset.MinValue).Count()
});

var rawResults = await query.ToArrayAsync(cancellationToken);

var usersBySponsor = rawResults
.Where(p => p.Sponsor is not null)
.Where(p => p.Player.Sponsor is not null)
.Select(p => new
{
p.SponsorId,
p.UserId
p.Player.SponsorId,
p.Player.UserId
})
.DistinctBy(sponsorUser => new { sponsorUser.SponsorId, sponsorUser.UserId })
.GroupBy(r => r.SponsorId)
Expand All @@ -202,10 +208,10 @@ public async Task<EnrollmentReportStatSummary> GetSummaryStats(EnrollmentReportP
// resolve the sponsor with the most unique users
// (it'll be the first one if there are any, because they're ordered by player
// count above)
EnrollmentReportStatSummarySponsorPlayerCount sponsorWithMostPlayers = null;
if (usersBySponsor.Any())
var sponsorWithMostPlayers = default(EnrollmentReportStatSummarySponsorPlayerCount);
if (usersBySponsor.Count != 0)
{
var allSponsors = rawResults.Select(p => p.Sponsor).DistinctBy(s => s.Id);
var allSponsors = rawResults.Select(p => p.Player.Sponsor).DistinctBy(s => s.Id);
var sponsor = allSponsors.FirstOrDefault(s => s.Id == usersBySponsor.First().Key);

if (sponsor is not null)
Expand All @@ -225,11 +231,13 @@ public async Task<EnrollmentReportStatSummary> GetSummaryStats(EnrollmentReportP

return new EnrollmentReportStatSummary
{
DistinctGameCount = rawResults.Select(r => r.GameId).Distinct().Count(),
DistinctPlayerCount = rawResults.Select(r => r.UserId).Distinct().Count(),
DistinctSponsorCount = rawResults.Select(r => r.SponsorId).Distinct().Count(),
DistinctTeamCount = rawResults.Select(r => r.TeamId).Distinct().Count(),
SponsorWithMostPlayers = sponsorWithMostPlayers
DistinctGameCount = rawResults.Select(r => r.Player.GameId).Distinct().Count(),
DistinctPlayerCount = rawResults.Select(r => r.Player.UserId).Distinct().Count(),
DistinctSponsorCount = rawResults.Select(r => r.Player.SponsorId).Distinct().Count(),
DistinctTeamCount = rawResults.Select(r => r.Player.TeamId).Distinct().Count(),
SponsorWithMostPlayers = sponsorWithMostPlayers,
TeamsWithNoSessionCount = rawResults.Where(r => r.Player.SessionBegin.IsEmpty()).Select(r => r.Player.TeamId).Distinct().Count(),
TeamsWithNoStartedChallengeCount = rawResults.Where(r => r.ChallengesStarted == 0).Select(r => r.Player.TeamId).Distinct().Count()
};
}

Expand Down

0 comments on commit f386200

Please sign in to comment.