Refactor bot startup process to auto-create configuration files, enhance update system, and add historical stats endpoints

- Updated README.md to reflect new bot setup and configuration process.
- Removed outdated installer README and integrated update logic directly into the bot.
- Implemented smart update for example configuration files, ensuring user files are not overwritten.
- Added FileBootstrap class to handle automatic creation of configuration files on first run.
- Enhanced BotController to manage stop requests and ensure graceful shutdown.
- Introduced new stats management features, including historical stats and activity breakdown endpoints.
- Updated API routes to include new statistics retrieval functionalities.
This commit is contained in:
2026-01-02 18:38:56 +01:00
parent 18d88a0071
commit e981a69095
10 changed files with 816 additions and 1408 deletions

View File

@@ -256,6 +256,68 @@ export class StatsManager {
console.error('[STATS] Failed to prune old stats:', error)
}
}
/**
* Get historical stats for charts (last N days)
*/
getHistoricalStats(days: number = 30): Record<string, number> {
const result: Record<string, number> = {}
const today = new Date()
for (let i = 0; i < days; i++) {
const date = new Date(today)
date.setDate(date.getDate() - i)
const dateStr = date.toISOString().slice(0, 10)
const stats = this.loadDailyStats(dateStr)
result[dateStr] = stats?.totalPoints || 0
}
return result
}
/**
* Get activity breakdown for last N days
*/
getActivityBreakdown(days: number = 7): Record<string, number> {
const breakdown: Record<string, number> = {
'Desktop Search': 0,
'Mobile Search': 0,
'Daily Set': 0,
'Quizzes': 0,
'Punch Cards': 0,
'Other': 0
}
const today = new Date()
for (let i = 0; i < days; i++) {
const date = new Date(today)
date.setDate(date.getDate() - i)
const dateStr = date.toISOString().slice(0, 10)
const accountStats = this.getAccountStatsForDate(dateStr)
for (const account of accountStats) {
if (!account.desktopSearches) account.desktopSearches = 0
if (!account.mobileSearches) account.mobileSearches = 0
if (!account.activitiesCompleted) account.activitiesCompleted = 0
breakdown['Desktop Search']! += account.desktopSearches
breakdown['Mobile Search']! += account.mobileSearches
breakdown['Daily Set']! += Math.min(1, account.activitiesCompleted)
breakdown['Other']! += Math.max(0, account.activitiesCompleted - 3)
}
}
return breakdown
}
/**
* Get global stats
*/
getGlobalStats(): GlobalStats {
return this.loadGlobalStats()
}
}
// Singleton instance