26 lines
987 B
TypeScript
26 lines
987 B
TypeScript
|
|
import { Injectable } from '@nestjs/common';
|
||
|
|
import { LearningActivityRepository } from './learning-activity.repository';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class LearningActivityService {
|
||
|
|
constructor(private readonly repository: LearningActivityRepository) {}
|
||
|
|
|
||
|
|
async getHeatmap(): Promise<Record<string, number>> {
|
||
|
|
const activities = await this.repository.findAll();
|
||
|
|
const heatmap: Record<string, number> = {};
|
||
|
|
for (const a of activities) {
|
||
|
|
heatmap[a.date] = a.minutes;
|
||
|
|
}
|
||
|
|
return heatmap;
|
||
|
|
}
|
||
|
|
|
||
|
|
async getSummary() {
|
||
|
|
const activities = await this.repository.findAll();
|
||
|
|
const totalMinutes = activities.reduce((s, a) => s + a.minutes, 0);
|
||
|
|
const totalCards = activities.reduce((s, a) => s + a.cardsReviewed, 0);
|
||
|
|
const activeDays = activities.filter((a) => a.minutes > 0).length;
|
||
|
|
const dailyAverage = activeDays > 0 ? Math.round(totalMinutes / activeDays) : 0;
|
||
|
|
return { totalMinutes, totalCardsReviewed: totalCards, activeDays, dailyAverage };
|
||
|
|
}
|
||
|
|
}
|