/** * Print Statistics Service * * Tracks and aggregates print job statistics including success rates, * performance metrics, and breakdowns by date/driver. * * @example * ```typescript * const stats = new PrintStatistics(); * stats.trackJobStart('job-1', { driver: 'EscPos' }); * stats.trackJobComplete('job-1', 1024, 500); * const report = stats.getStatistics(); * const json = stats.exportToJSON(); * ``` */ /** * Print statistics data interface (returned by getStatistics) */ export interface PrintStatisticsData { /** Total jobs submitted */ totalJobs: number; /** Successfully completed jobs */ completedJobs: number; /** Failed jobs */ failedJobs: number; /** Cancelled jobs */ cancelledJobs: number; /** Total bytes printed */ totalBytes: number; /** Average print time in milliseconds */ averagePrintTime: number; /** Success rate (0-1) */ successRate: number; /** Breakdown by date (YYYY-MM-DD) */ byDate: Record; /** Breakdown by driver name */ byDriver: Record; } /** * Job tracking metadata */ export interface JobTrackingMeta { /** Driver name */ driver?: string; /** Device ID */ deviceId?: string; /** Device name */ deviceName?: string; /** Priority */ priority?: number; /** Additional metadata */ [key: string]: unknown; } /** * Internal job record */ interface JobRecord { id: string; status: 'started' | 'completed' | 'failed' | 'cancelled'; startedAt: number; completedAt?: number; bytes?: number; duration?: number; error?: string; driver?: string; deviceId?: string; deviceName?: string; metadata?: Record; } /** * Print Statistics Service * * Collects and aggregates print job metrics for analytics and monitoring. * Provides breakdown by date and driver for detailed reporting. */ export declare class PrintStatistics { private readonly logger; /** Internal job records map */ private readonly jobs; /** Statistics counters */ private totalJobs; private completedJobs; private failedJobs; private cancelledJobs; private totalBytes; private totalPrintTime; /** Date-based breakdown: YYYY-MM-DD -> { completed, failed } */ private byDate; /** Driver-based breakdown: driverName -> { completed, failed } */ private byDriver; /** * Track a job start event * * @param jobId - Unique job identifier * @param metadata - Optional job metadata (driver, device info, etc.) */ trackJobStart(jobId: string, metadata?: JobTrackingMeta): void; /** * Track a job completion event * * @param jobId - Unique job identifier * @param bytes - Number of bytes printed * @param duration - Print duration in milliseconds */ trackJobComplete(jobId: string, bytes: number, duration: number): void; /** * Track a job failure event * * @param jobId - Unique job identifier * @param error - Error message or error object */ trackJobFail(jobId: string, error: unknown): void; /** * Track a job cancellation event * * @param jobId - Unique job identifier */ trackJobCancel(jobId: string): void; /** * Get current statistics * * @returns Complete statistics object */ getStatistics(): PrintStatisticsData; /** * Export statistics as JSON string * * @param pretty - Whether to format with indentation (default: true) * @returns JSON string representation */ exportToJSON(pretty?: boolean): string; /** * Import statistics from JSON string * * @param json - JSON string to import * @returns Number of records imported */ importFromJSON(json: string): number; /** * Get statistics for a specific date range * * @param startDate - Start date (timestamp or Date) * @param endDate - End date (timestamp or Date) * @returns Filtered statistics */ getStatisticsByDateRange(startDate: Date | number, endDate: Date | number): PrintStatisticsData; /** * Get breakdown by date * * @returns Date-based breakdown object */ getByDate(): Record; /** * Get breakdown by driver * * @returns Driver-based breakdown object */ getByDriver(): Record; /** * Reset all statistics */ reset(): void; /** * Get job record by ID * * @param jobId - Job identifier * @returns Job record or undefined */ getJobRecord(jobId: string): JobRecord | undefined; private formatDateKey; private formatError; private aggregateByDate; private aggregateByDriver; /** * Generic aggregation helper. Groups jobs by a key function and counts * completed/failed per group. Skips jobs whose key is null/undefined. */ private aggregateByKey; /** * Update driver and date breakdown stats for a job record. * Shared by trackJobComplete and trackJobFail. */ private incrementBreakdownStats; } /** Singleton instance for convenience */ export declare const printStatistics: PrintStatistics; export {};