Skip to content

Commit

Permalink
Initial draft of enrollment report by game tab.
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Nov 28, 2023
1 parent 707bdde commit 6b5dce4
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<ng-container *ngIf="results; else loading">
<div *ngIf="results && results.records.length; else noRecords" class="results">
<table class="report-table table-hover gameboard-report">
<col>
<colgroup span="3"></colgroup>

<thead class="thead-light">
<tr class="headers super-headers-row">
<th scope="col" class="group-header game-column">Game</th>
<th scope="col" colSpan="3" class="group-header">Enrollment</th>
</tr>
</thead>

<tbody>
<tr class="headers headers-row">
<td>Game</td>
<td>Total Players</td>
<td>Total Sponsors</td>
<td>Top Sponsor</td>
</tr>

<tr class="data-row" *ngFor="let record of results.records">
<td>
<app-challenge-or-game-field [game]="record.game"></app-challenge-or-game-field>
</td>

<!--ENROLLMENT-->
<td class="report-field numerical">
{{record.playerCount}}
</td>
<td class="report-field numerical">
<p>{{record.sponsors.length}}</p>
</td>
<td class="report-field numerical">
<app-parameter-change-link *ngIf="record.topSponsor"
[config]="{ parameterChange: { sponsors: record.topSponsor.id} }">
<app-player-avatar-legacy class="d-block mr-2"
[avatarUri]="record.topSponsor.logoFileName | relativeImage"
[tooltip]="record.topSponsor.name" size="small"></app-player-avatar-legacy>
</app-parameter-change-link>
<small class="subtle-info">{{record.topSponsorPlayerCount}} {{ "player" |
pluralizer:record.topSponsorPlayerCount
}}</small>
</td>
</tr>
</tbody>
</table>
</div>
</ng-container>

<ng-template #loading>
<div class="page-height d-flex flex-column align-items-center justify-content-center">
<app-spinner>Loading the report...</app-spinner>
</div>
</ng-template>

<ng-template #noRecords>
<app-no-report-records></app-no-report-records>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.game-column {
width: 35%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { EnrollmentReportByGameRecord, EnrollmentReportFlatParameters } from '@/reports/components/reports/enrollment-report/enrollment-report.models';
import { ReportResults } from '@/reports/reports-models';
import { EnrollmentReportService } from '../../enrollment-report.service';
import { firstValueFrom } from 'rxjs';
import { PagingArgs } from '@/api/models';
import { RouterService } from '@/services/router.service';

@Component({
selector: 'app-enrollment-report-by-game',
templateUrl: './enrollment-report-by-game.component.html',
styleUrls: ['./enrollment-report-by-game.component.scss']
})
export class EnrollmentReportByGameComponent implements OnChanges {
@Input() parameters!: EnrollmentReportFlatParameters | null;

protected results: ReportResults<EnrollmentReportByGameRecord> | null = null;

constructor(
private enrollmentReportService: EnrollmentReportService,
private routerService: RouterService) { }

async ngOnChanges(changes: SimpleChanges): Promise<void> {
await this.loadData(this.parameters);
}

private async loadData(parameters: EnrollmentReportFlatParameters | null) {
this.results = await firstValueFrom(this.enrollmentReportService.getByGameData(this.parameters));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
<app-line-chart id="enrollmentTrend" [config]="ctx.chartConfig"></app-line-chart>
</div>
</tab>

<tab heading="By Game" id="tab-by-game">
<div class="by-game-container mt-4">
<app-enrollment-report-by-game [parameters]="selectedParameters"></app-enrollment-report-by-game>
</div>
</tab>
</tabset>
</ng-container>
</div>
Expand Down Expand Up @@ -158,7 +164,3 @@
<ng-template #multiSelectGame let-context>
<span class="game-name">{{ context.name }}</span>
</ng-template>

<ng-template #multiSelectSponsor let-context>
<span class="sponsor-name">{{ context.name }}</span>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ReportResultsWithOverallStats, ReportSponsor, ReportViewUpdate } from '
import { EnrollmentReportService } from '@/reports/components/reports/enrollment-report/enrollment-report.service';
import { Observable, firstValueFrom, of } from 'rxjs';
import { SimpleEntity } from '@/api/models';
import { ChallengeResult } from '@/api/board-models';
import { ModalConfirmService } from '@/services/modal-confirm.service';
import { MarkdownHelpersService } from '@/services/markdown-helpers.service';
import { LineChartConfig } from '@/core/components/line-chart/line-chart.component';
Expand Down Expand Up @@ -38,6 +37,7 @@ export class EnrollmentReportComponent extends ReportComponentBase<EnrollmentRep

protected results?: ReportResultsWithOverallStats<EnrollmentReportStatSummary, EnrollmentReportRecord>;
protected leadingSponsorStat?: ReportSummaryStat;
protected selectedParameters: EnrollmentReportFlatParameters | null = null;
protected stats: ReportSummaryStat[] = [];

// parameter query models
Expand Down Expand Up @@ -93,6 +93,7 @@ export class EnrollmentReportComponent extends ReportComponentBase<EnrollmentRep
}

this.isLoading = true;
this.selectedParameters = parameters;
this.results = await firstValueFrom(this.reportService.getReportData(parameters));
const lineChartResults = await this.reportService.getTrendData(parameters);

Expand All @@ -103,6 +104,7 @@ export class EnrollmentReportComponent extends ReportComponentBase<EnrollmentRep
additionalInfo: `(${this.results.overallStats.sponsorWithMostPlayers.distinctPlayerCount} players)`
} :
undefined;

this.stats = [
{ label: "Game", value: this.results.overallStats.distinctGameCount },
{ label: "Player", value: this.results.overallStats.distinctPlayerCount },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export interface EnrollmentReportRecord {
score?: number;
}

export interface EnrollmentReportByGameRecord {
game: ReportGame;
playerCount: number;
sponsors: ReportSponsor[];
topSponsor: ReportSponsor;
topSponsorPlayerCount: number;
}

export interface EnrollmentReportStatSummary {
distinctGameCount: number;
distinctPlayerCount: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { EnrollmentReportFlatParameters, EnrollmentReportLineChartGroup, EnrollmentReportParameters, EnrollmentReportRecord, EnrollmentReportStatSummary } from './enrollment-report.models';
import { Observable, firstValueFrom, map, tap } from 'rxjs';
import { ReportResults, ReportResultsWithOverallStats } from '../../../reports-models';
import { ReportsService } from '../../../reports.service';
import { EnrollmentReportByGameRecord, EnrollmentReportFlatParameters, EnrollmentReportLineChartGroup, EnrollmentReportRecord, EnrollmentReportStatSummary } from './enrollment-report.models';
import { Observable, firstValueFrom, map, } from 'rxjs';
import { ReportResults, ReportResultsWithOverallStats } from '@/reports/reports-models';
import { ReportsService } from '@/reports/reports.service';
import { HttpClient } from '@angular/common/http';
import { ApiUrlService } from '@/services/api-url.service';
import { DateTime } from 'luxon';
Expand All @@ -14,6 +14,12 @@ export class EnrollmentReportService {
private http: HttpClient,
private reportsService: ReportsService) { }

getByGameData(parameters: EnrollmentReportFlatParameters | null): Observable<ReportResults<EnrollmentReportByGameRecord>> {
parameters = parameters || {};
const pagedParameters = this.reportsService.applyDefaultPaging(parameters);
return this.http.get<ReportResults<EnrollmentReportByGameRecord>>(this.apiUrl.build("reports/enrollment/by-game", pagedParameters));
}

getReportData(parameters: EnrollmentReportFlatParameters): Observable<ReportResultsWithOverallStats<EnrollmentReportStatSummary, EnrollmentReportRecord>> {
const pagedParameters = this.reportsService.applyDefaultPaging(parameters);
return this.http.get<ReportResultsWithOverallStats<EnrollmentReportStatSummary, EnrollmentReportRecord>>(this.apiUrl.build("reports/enrollment", pagedParameters));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<table class="report-table table-hover gameboard-report">
<col span="2">
<colgroup span="6"></colgroup>
<!-- <colgroup span="3"></colgroup> -->

<thead class="thead-light">
<tr class="headers super-headers-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ReportResultsWithOverallStats } from '@/reports/reports-models';
import { ModalConfirmService } from '@/services/modal-confirm.service';
import { RouterService } from '@/services/router.service';
import { PagingArgs } from '@/api/models';
import { LogService } from '@/services/log.service';
import { PlayerChallengeAttempts, PlayerChallengeAttemptsModalComponent } from '@/reports/components/player-challenge-attempts-modal/player-challenge-attempts-modal.component';

@Component({
Expand All @@ -22,7 +21,6 @@ export class PracticeModeReportByUserComponent implements OnChanges {


constructor(
private log: LogService,
private modalService: ModalConfirmService,
private reportService: PracticeModeReportService,
private routerService: RouterService) {
Expand Down
2 changes: 2 additions & 0 deletions projects/gameboard-ui/src/app/reports/reports.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ArrayFieldToClassPipe } from './pipes/array-field-to-class.pipe';
import { ArrayToCountPipe } from './pipes/array-to-count.pipe';
import { CountToTooltipClassPipe } from './pipes/count-to-tooltip-class.pipe';
import { PlayerChallengeAttemptsModalComponent } from './components/player-challenge-attempts-modal/player-challenge-attempts-modal.component';
import { EnrollmentReportByGameComponent } from './components/reports/enrollment-report/enrollment-report-by-game/enrollment-report-by-game/enrollment-report-by-game.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -68,6 +69,7 @@ import { PlayerChallengeAttemptsModalComponent } from './components/player-chall
ReportStatSummaryComponent,
PlayerChallengeAttemptsModalComponent,
ParameterSponsorComponent,
EnrollmentReportByGameComponent,
],
imports: [
CommonModule,
Expand Down

0 comments on commit 6b5dce4

Please sign in to comment.