From ee06ef2fb7f248011af6222f8169c2172ec2143a Mon Sep 17 00:00:00 2001 From: Ben Stein Date: Mon, 16 Dec 2024 14:15:56 -0500 Subject: [PATCH] Improve performance of enrollment trend line --- .../enrollment-report-trend.component.ts | 7 +--- .../enrollment-report.models.ts | 37 ++++++++----------- .../enrollment-report.service.ts | 18 +++------ 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report-trend/enrollment-report-trend.component.ts b/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report-trend/enrollment-report-trend.component.ts index 495eba78..0c6edf03 100644 --- a/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report-trend/enrollment-report-trend.component.ts +++ b/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report-trend/enrollment-report-trend.component.ts @@ -45,7 +45,7 @@ export class EnrollmentReportTrendComponent { datasets: [ { label: "Enrolled players", - data: Array.from(viewModel.byDate.values()).map(g => g.totalCount), + data: Array.from(viewModel.byDate.values()), backgroundColor: 'green', }, ] @@ -84,10 +84,7 @@ export class EnrollmentReportTrendComponent { labels: Array.from(viewModel.byDate.keys()).map(k => k as any), datasets: Array.from(viewModel.byGameByDate.keys()).map(gameId => ({ label: viewModel.gameNames[gameId], - data: Array.from(viewModel.byGameByDate.get(gameId)!.keys()).map(date => { - const players = viewModel.byGameByDate.get(gameId)?.get(date); - return players?.totalCount || 0; - }) + data: Array.from(viewModel.byGameByDate.get(gameId)!.values()) })) }, options: { diff --git a/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report.models.ts b/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report.models.ts index 7601db7b..bc96d413 100644 --- a/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report.models.ts +++ b/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report.models.ts @@ -88,39 +88,34 @@ export interface EnrollmentReportStatSummary { } export interface EnrollmentReportLineChartResponse { - byDate: { [dateString: string]: EnrollmentReportLineChartPlayerGame[] } + byDate: { [dateString: string]: number } byGameByDate: { [gameId: string]: { - [dateString: string]: EnrollmentReportLineChartPlayerGame[]; + [dateString: string]: number; } } games: { [gameId: string]: string }; - players: { [playerId: string]: EnrollmentReportLineChartPlayer } + // players: { [playerId: string]: EnrollmentReportLineChartPlayer } periodType: string; periodStart: DateTime; periodEnd: DateTime; } -export interface EnrollmentReportLineChartPlayer { - id: string; - name: string; - game: SimpleEntity; - enrollDate: Date; -} +// export interface EnrollmentReportLineChartPlayer { +// id: string; +// name: string; +// game: SimpleEntity; +// enrollDate: Date; +// } -export interface EnrollmentReportLineChartPlayerGame { - id: string; - gameId: string; -} +// export interface EnrollmentReportLineChartPlayerGame { +// id: string; +// gameId: string; +// } -// these areclient side models that represents the data after it's been structured from the API +// these are client side models that represents the data after it's been structured from the API export interface EnrollmentReportLineChartViewModel { - byDate: Map; - byGameByDate: Map>; + byDate: Map; + byGameByDate: Map>; gameNames: { [gameId: string]: string }; } - -export interface EnrollmentReportLineChartGroupViewModel { - totalCount: number; - players: EnrollmentReportLineChartPlayer[]; -} diff --git a/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report.service.ts b/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report.service.ts index fe797f6a..c8c0acf0 100644 --- a/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report.service.ts +++ b/projects/gameboard-ui/src/app/reports/components/reports/enrollment-report/enrollment-report.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { EnrollmentReportByGameRecord, EnrollmentReportFlatParameters, EnrollmentReportLineChartViewModel, EnrollmentReportLineChartResponse, EnrollmentReportRecord, EnrollmentReportStatSummary, EnrollmentReportLineChartGroupViewModel } from './enrollment-report.models'; +import { EnrollmentReportByGameRecord, EnrollmentReportFlatParameters, EnrollmentReportLineChartViewModel, EnrollmentReportLineChartResponse, EnrollmentReportRecord, EnrollmentReportStatSummary } from './enrollment-report.models'; import { Observable, firstValueFrom, map, } from 'rxjs'; import { ReportResults } from '@/reports/reports-models'; import { ReportsService } from '@/reports/reports.service'; @@ -50,24 +50,18 @@ export class EnrollmentReportService { .get(this.apiUrl.build("reports/enrollment/trend", trendParams)) .pipe( map(results => { - const byDate = new Map(); - const byGameByDate = new Map>(); + const byDate = new Map(); + const byGameByDate = new Map>(); for (const group of Object.entries(results.byDate)) { - byDate.set(DateTime.fromISO(group[0]), { - totalCount: group[1].length, - players: group[1].map(playerGame => results.players[playerGame.id]) - }); + byDate.set(DateTime.fromISO(group[0]), group[1]); } for (const gameGroup of Object.entries(results.byGameByDate)) { - const gameDateGroups = new Map(); + const gameDateGroups = new Map(); for (const dateGroup of Object.entries(gameGroup[1])) { - gameDateGroups.set(DateTime.fromISO(dateGroup[0]), { - totalCount: dateGroup[1].length, - players: dateGroup[1].map(playerGame => results.players[playerGame.id]) - }); + gameDateGroups.set(DateTime.fromISO(dateGroup[0]), dateGroup[1]); } byGameByDate.set(gameGroup[0], gameDateGroups);