Skip to content

Commit

Permalink
Enhance reports (#352)
Browse files Browse the repository at this point in the history
- Add first time participant count to vendor code report
- Add achievers to the participant count and minutes by program
  • Loading branch information
k7hpn committed Aug 14, 2018
1 parent 895f9b8 commit b7fdbcf
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
- Community experience attendance report
- Email address collection after program has ended
- Templates in the shared folder for front page and dashboard views
- First time participant count on vendor code report
- Achiever count to the participant count and minutes by program report

### Changed
- Mission Control events navbar icon is now a drop-down (#322)
Expand Down
5 changes: 5 additions & 0 deletions src/GRA.Data/Repository/VendorCodeRepository.cs
Expand Up @@ -93,6 +93,11 @@ public async Task<ICollection<VendorCode>> GetEarnedCodesAsync(ReportCriterion c
var validUsers = _context.Users.AsNoTracking()
.Where(_ => _.SiteId == criterion.SiteId);

if(criterion.IsFirstTimeParticipant == true)
{
validUsers = validUsers.Where(_ => _.IsFirstTime == true);
}

if (criterion.BranchId.HasValue)
{
validUsers = validUsers.Where(_ => _.BranchId == criterion.BranchId.Value);
Expand Down
2 changes: 2 additions & 0 deletions src/GRA.Domain.Model/ReportCriterion.cs
Expand Up @@ -23,5 +23,7 @@ public class ReportCriterion : Abstract.BaseDomainEntity
public string Name { get; set; }
public string BadgeRequiredList { get; set; }
public string ChallengeRequiredList { get; set; }

public bool IsFirstTimeParticipant { get; set; }
}
}
11 changes: 9 additions & 2 deletions src/GRA.Domain.Report/ParticipantsMinutesByProgramReport.cs
Expand Up @@ -13,7 +13,7 @@ namespace GRA.Domain.Report
{
[ReportInformation(16,
"Participant Count and Minutes By Program Report",
"Select a system, see participant count and minutes reported by program.",
"Select a system, see participant count, achievers, and minutes reported by program.",
"Program")]
public class ParticipantCountMinutesByProgram : BaseReport
{
Expand Down Expand Up @@ -73,6 +73,7 @@ public class ParticipantCountMinutesByProgram : BaseReport
"System Name",
"Program Name",
"Registered Users",
"Achievers"
};

var translations = new Dictionary<string, ICollection<int?>>();
Expand Down Expand Up @@ -115,6 +116,7 @@ public class ParticipantCountMinutesByProgram : BaseReport

// running totals
long totalRegistered = 0;
long totalAchievers = 0;

int totalItems = programDictionary.Count();

Expand All @@ -134,12 +136,16 @@ public class ParticipantCountMinutesByProgram : BaseReport

int users = await _userRepository.GetCountAsync(criterion);

int achievers = await _userRepository.GetAchieverCountAsync(criterion);

totalRegistered += users;
totalAchievers += achievers;

var row = new List<object>() {
system.Name,
programDictionary[programId],
users
users,
achievers
};

foreach (var translationName in translations.Keys)
Expand All @@ -166,6 +172,7 @@ public class ParticipantCountMinutesByProgram : BaseReport
"Total",
string.Empty,
totalRegistered,
totalAchievers
};

foreach (var total in translationTotals.Values)
Expand Down
73 changes: 58 additions & 15 deletions src/GRA.Domain.Report/VendorCodeReport.cs
Expand Up @@ -13,7 +13,7 @@ namespace GRA.Domain.Report
{
[ReportInformation(13,
"Vendor Code Report",
"Vendor prizes earned and ordered by partcipants filterable by system.",
"Select a system or for all see vendor prizes earned and ordered. Includes deleted participants!",
"Participants")]
public class VendorCodeReport : BaseReport
{
Expand Down Expand Up @@ -69,25 +69,43 @@ var criterion
AsOf = _serviceFacade.DateTimeProvider.Now
};
var reportData = new List<object[]>();

var askIfFirstTime
= await GetSiteSettingBoolAsync(criterion, SiteSettingKey.Users.AskIfFirstTime);
#endregion Reporting initialization

#region Collect data
UpdateProgress(progress, 1, "Starting report...", request.Name);

// header row
report.HeaderRow = new object[] {
var headerRow = new List<object>
{
"System Name",
"Branch Name",
"# Redeemed",
"# Ordered"
"Branch Name"
};

// first time?

if (askIfFirstTime)
{
headerRow.Add("First Time # Earned");
headerRow.Add("First Time # Ordered");
}

headerRow.Add("# Earned");
headerRow.Add("# Ordered");

report.HeaderRow = headerRow.ToArray();

int count = 0;

// running totals
int totalEarned = 0;
int totalOrdered = 0;

int totalFirstEarned = 0;
int totalFirstOrdered = 0;

var branches = criterion.SystemId != null
? await _branchRepository.GetBySystemAsync((int)criterion.SystemId)
: await _branchRepository.GetAllAsync((int)criterion.SiteId);
Expand All @@ -114,19 +132,37 @@ var criterion
criterion.SystemId = systemId;
criterion.BranchId = branch.Id;

var row = new List<object> {
branch.SystemName,
branch.Name,
};

if(askIfFirstTime)
{
criterion.IsFirstTimeParticipant = true;
var firstVendorCodes =
await _vendorCodeRepository.GetEarnedCodesAsync(criterion);
int firstEarnedCodes = firstVendorCodes.Count;
int firstUsedCodes = firstVendorCodes.Where(_ => _.IsUsed).Count();

criterion.IsFirstTimeParticipant = false;

row.Add(firstEarnedCodes);
row.Add(firstUsedCodes);

totalFirstEarned += firstEarnedCodes;
totalFirstOrdered += firstUsedCodes;
}

var vendorCodes = await _vendorCodeRepository.GetEarnedCodesAsync(criterion);
int earnedCodes = vendorCodes.Count;
int usedCodes = vendorCodes.Where(_ => _.IsUsed).Count();

totalEarned += earnedCodes;
totalOrdered += usedCodes;

var row = new List<object>() {
branch.SystemName,
branch.Name,
earnedCodes,
usedCodes
};
row.Add(earnedCodes);
row.Add(usedCodes);

reportData.Add(row.ToArray());

Expand All @@ -140,14 +176,21 @@ var criterion
report.Data = reportData.ToArray();

// total row
var footerRow = new List<object>()
var footerRow = new List<object>
{
"Total",
string.Empty,
totalEarned,
totalOrdered
string.Empty
};

if(askIfFirstTime)
{
footerRow.Add(totalFirstEarned);
footerRow.Add(totalFirstOrdered);
}

footerRow.Add(totalEarned);
footerRow.Add(totalOrdered);

report.FooterRow = footerRow.ToArray();

#endregion Collect data
Expand Down

0 comments on commit b7fdbcf

Please sign in to comment.