Files
strategic/src/reporting/weekly.ts
2026-02-09 21:51:54 -08:00

114 lines
2.7 KiB
TypeScript

/**
* Weekly Status Report Generator
*/
import { transactionExplorer } from "../monitoring/explorer.js";
import { gasTracker } from "../monitoring/gasTracker.js";
import { healthDashboard } from "../monitoring/dashboard.js";
export interface WeeklyReport {
period: {
start: number;
end: number;
};
executions: {
total: number;
successful: number;
failed: number;
successRate: number;
};
gas: {
total: bigint;
average: bigint;
peak: bigint;
trend: "increasing" | "decreasing" | "stable";
};
system: {
status: "healthy" | "degraded" | "down";
uptime: number;
protocols: any[];
};
alerts: {
count: number;
critical: number;
warnings: number;
};
}
/**
* Generate weekly status report
*/
export function generateWeeklyReport(): WeeklyReport {
const now = Date.now();
const weekAgo = now - 7 * 24 * 60 * 60 * 1000;
const stats = transactionExplorer.getStats();
const metrics = healthDashboard.getMetrics();
const avgGas = gasTracker.getAverage(7 * 24 * 60);
const peakGas = gasTracker.getPeak(7 * 24 * 60);
const gasTrend = gasTracker.getTrend(7 * 24 * 60);
return {
period: {
start: weekAgo,
end: now,
},
executions: {
total: stats.total,
successful: stats.successful,
failed: stats.failed,
successRate: stats.total > 0 ? stats.successful / stats.total : 0,
},
gas: {
total: stats.totalGasUsed,
average: avgGas,
peak: peakGas,
trend: gasTrend,
},
system: {
status: healthDashboard.getSystemStatus(),
uptime: metrics.uptime,
protocols: healthDashboard.getProtocolHealth(),
},
alerts: {
count: 0, // Would be populated from alert manager
critical: 0,
warnings: 0,
},
};
}
/**
* Format report as markdown
*/
export function formatWeeklyReport(report: WeeklyReport): string {
return `
# Weekly Status Report
**Period**: ${new Date(report.period.start).toISOString()} - ${new Date(report.period.end).toISOString()}
## Executions
- Total: ${report.executions.total}
- Successful: ${report.executions.successful}
- Failed: ${report.executions.failed}
- Success Rate: ${(report.executions.successRate * 100).toFixed(2)}%
## Gas Usage
- Total: ${report.gas.total.toString()}
- Average: ${report.gas.average.toString()}
- Peak: ${report.gas.peak.toString()}
- Trend: ${report.gas.trend}
## System Status
- Status: ${report.system.status}
- Uptime: ${(report.system.uptime / 1000 / 60 / 60).toFixed(2)} hours
- Protocols: ${report.system.protocols.length} monitored
## Alerts
- Total: ${report.alerts.count}
- Critical: ${report.alerts.critical}
- Warnings: ${report.alerts.warnings}
`;
}