/** * Content Change Predictor (GAP-011) * * Learns content update patterns and predicts when content will change. * Enables optimal polling intervals to minimize unnecessary fetches. * * Features: * - Pattern detection (hourly, daily, weekly, workday, monthly) * - Change prediction with confidence scoring * - Polling interval optimization * - Temporal analysis (time of day, day of week) * * @example * ```typescript * const predictor = new ContentChangePredictor(); * * // Record observations * predictor.recordObservation('news.example.com', '/api/feed', 'hash1', true); * predictor.recordObservation('news.example.com', '/api/feed', 'hash2', true); * * // Get prediction * const analysis = predictor.analyzePattern('news.example.com', '/api/feed'); * console.log(analysis.pattern.detectedPattern); // 'daily' * console.log(analysis.pattern.recommendedPollIntervalMs); // 3600000 * * // Check if we should poll * const recommendation = predictor.shouldCheckNow('news.example.com', '/api/feed'); * if (recommendation.shouldPoll) { * // Fetch content * } * ``` */ import type { ContentChangePattern, ContentChangePredictionConfig, ContentChangeAnalysis, PollRecommendation, UrgencyLevel } from '../types/content-change.js'; /** * Content Change Predictor * * Learns when content changes and predicts future changes. */ export declare class ContentChangePredictor { /** Stored patterns by domain:urlPattern key */ private patterns; /** Configuration */ private config; constructor(config?: Partial); /** * Record an observation of content check */ recordObservation(domain: string, urlPattern: string, contentHash: string | undefined, changed: boolean): ContentChangePattern; /** * Get a pattern by domain and URL pattern */ getPattern(domain: string, urlPattern: string): ContentChangePattern | null; /** * Analyze a pattern and return detailed analysis */ analyzePattern(domain: string, urlPattern: string): ContentChangeAnalysis; /** * Check if we should poll this content now */ shouldCheckNow(domain: string, urlPattern: string, now?: number): PollRecommendation; /** * Get all patterns */ getAllPatterns(): ContentChangePattern[]; /** * Export patterns for persistence */ exportPatterns(): Record; /** * Import patterns from persistence */ importPatterns(data: Record): void; /** * Create a new empty pattern */ private createNewPattern; /** * Calculate frequency statistics from change timestamps */ private calculateFrequencyStats; /** * Analyze timestamps and detect pattern type */ private detectPatternType; /** * Detect hourly pattern (consistent intervals) */ private detectHourlyPattern; /** * Detect daily pattern (same hour each day) */ private detectDailyPattern; /** * Detect workday pattern (weekdays only) */ private detectWorkdayPattern; /** * Detect weekly pattern (specific days of week) */ private detectWeeklyPattern; /** * Detect monthly pattern (specific days of month) */ private detectMonthlyPattern; /** * Find typical hours from a list of hours */ private findTypicalHours; /** * Find typical days of week from a list */ private findTypicalDays; /** * Calculate recommended poll interval based on pattern */ private calculateRecommendedInterval; /** * Generate next change prediction */ private generatePrediction; /** * Analyze and update a pattern in place */ private analyzeAndUpdatePattern; /** * Generate analysis summary and recommendations */ private generateAnalysisSummary; /** * Detect calendar-based triggers (annual dates with consistent changes) * Examples: Government fee updates on Jan 1, fiscal year changes on Apr 1 */ private detectCalendarTriggers; /** * Detect seasonal patterns (month/day probability distributions) */ private detectSeasonalPatterns; /** * Record prediction accuracy for learning * Call this after checking content to compare predicted vs actual change */ recordPredictionAccuracy(domain: string, urlPattern: string, actualChanged: boolean, actualChangeAt?: number): void; /** * Calculate urgency level for refresh prioritization * 0 = Low (static content, check weekly) * 1 = Normal (regular patterns, follow schedule) * 2 = High (approaching predicted change, check soon) * 3 = Critical (calendar trigger imminent, check immediately) */ calculateUrgency(domain: string, urlPattern: string, now?: number): UrgencyLevel; /** * Get urgency for a pattern (convenience method that also updates the pattern) */ updateUrgency(domain: string, urlPattern: string, now?: number): UrgencyLevel; /** * Get all patterns with their urgency levels, sorted by urgency (highest first) */ getPatternsWithUrgency(now?: number): Array; /** * Get prediction accuracy statistics for a pattern */ getAccuracyStats(domain: string, urlPattern: string): { totalPredictions: number; successfulPredictions: number; successRate: number; avgErrorMs: number | null; recentAccuracy: number | null; } | null; } //# sourceMappingURL=content-change-predictor.d.ts.map