Untitled
unknown
plain_text
a year ago
3.0 kB
8
Indexable
import fs from 'fs/promises';
import path from 'path';
export interface StatsData {
totalItemsSorted: number;
itemsPerWasteType: Record<string, number>;
sortingTimestamps: Array<{ timestamp: string; wasteType: string }>;
bins: Array<{ id: number; type: string; fillLevel: number; emptyings: number }>;
modelUsage: { api: number; local: number };
dailyUsage: Array<{ date: string; count: number }>;
weeklyUsage: Array<{ week: string; count: number }>;
monthlyUsage: Array<{ month: string; count: number }>;
timeBetweenSorts: { average: number; min: number; max: number };
timeOfDayPatterns: Array<{ hour: number; count: number }>;
streaks: { daily: number; weekly: number; monthly: number };
binMetrics: {
timeTo90PercentFull: { average: number; min: number; max: number };
fillRate: { average: number; min: number; max: number };
fillLevelBalance: number;
};
classificationResponseTimes: { average: number; min: number; max: number };
}
export async function getStatsData(): Promise<StatsData> {
try {
const filePath = path.join(process.cwd(), 'data', 'stats.json');
const fileContents = await fs.readFile(filePath, 'utf8');
return JSON.parse(fileContents);
} catch (error) {
console.error('Error reading stats file:', error);
// Return mock data as fallback
return {
totalItemsSorted: 10000,
itemsPerWasteType: {
plastic: 3000,
paper: 2500,
glass: 1500,
metal: 1000,
organic: 2000
},
sortingTimestamps: [
{timestamp: "2023-06-01T08:30:00Z", wasteType: "plastic"},
{timestamp: "2023-06-01T09:15:00Z", wasteType: "paper"},
],
bins: [
{id: 1, type: "plastic", fillLevel: 75, emptyings: 5},
{id: 2, type: "paper", fillLevel: 60, emptyings: 4},
],
modelUsage: {
api: 8000,
local: 2000
},
dailyUsage: [
{date: "2023-06-01", count: 350},
{date: "2023-06-02", count: 375},
],
weeklyUsage: [
{week: "2023-W22", count: 2450},
{week: "2023-W23", count: 2600},
],
monthlyUsage: [
{month: "2023-05", count: 9800},
{month: "2023-06", count: 10200},
],
timeBetweenSorts: {
average: 300,
min: 60,
max: 1800
},
timeOfDayPatterns: [
{hour: 0, count: 50},
{hour: 1, count: 30},
],
streaks: {
daily: 15,
weekly: 4,
monthly: 2
},
binMetrics: {
timeTo90PercentFull: {
average: 86400,
min: 43200,
max: 129600
},
fillRate: {
average: 0.5,
min: 0.2,
max: 0.8
},
fillLevelBalance: 0.85
},
classificationResponseTimes: {
average: 250,
min: 100,
max: 500
}
};
}
}
Editor is loading...
Leave a Comment