Skip to content

Commit

Permalink
Improve performance of enrollment trend line
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Dec 16, 2024
1 parent 1c2298c commit ee06ef2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]
Expand Down Expand Up @@ -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<DateTime>(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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateTime, EnrollmentReportLineChartGroupViewModel>;
byGameByDate: Map<string, Map<DateTime, EnrollmentReportLineChartGroupViewModel>>;
byDate: Map<DateTime, number>;
byGameByDate: Map<string, Map<DateTime, number>>;
gameNames: { [gameId: string]: string };
}

export interface EnrollmentReportLineChartGroupViewModel {
totalCount: number;
players: EnrollmentReportLineChartPlayer[];
}
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -50,24 +50,18 @@ export class EnrollmentReportService {
.get<EnrollmentReportLineChartResponse>(this.apiUrl.build("reports/enrollment/trend", trendParams))
.pipe(
map(results => {
const byDate = new Map<DateTime, EnrollmentReportLineChartGroupViewModel>();
const byGameByDate = new Map<string, Map<DateTime, EnrollmentReportLineChartGroupViewModel>>();
const byDate = new Map<DateTime, number>();
const byGameByDate = new Map<string, Map<DateTime, number>>();

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<DateTime, EnrollmentReportLineChartGroupViewModel>();
const gameDateGroups = new Map<DateTime, number>();

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);
Expand Down

0 comments on commit ee06ef2

Please sign in to comment.