Skip to main content

shape_runtime/statistics/
types.rs

1//! Type definitions for statistics module
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Confidence interval for a metric
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct ConfidenceInterval {
9    /// Point estimate (mean)
10    pub estimate: f64,
11    /// Lower bound of confidence interval
12    pub lower_bound: f64,
13    /// Upper bound of confidence interval
14    pub upper_bound: f64,
15    /// Confidence level (e.g., 0.95)
16    pub confidence: f64,
17}
18
19/// Comprehensive statistics report
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct StatisticsReport {
22    /// Basic statistics
23    pub basic: BasicStatistics,
24
25    /// Pattern-specific statistics
26    pub patterns: PatternStatistics,
27
28    /// Time-based analysis
29    pub temporal: TemporalStatistics,
30}
31
32/// Basic statistical measures
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct BasicStatistics {
35    pub total_matches: usize,
36    pub unique_patterns: usize,
37    pub match_rate: f64,
38    pub avg_confidence: f64,
39    pub median_confidence: f64,
40    pub std_dev_confidence: f64,
41}
42
43/// Pattern-specific statistics
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct PatternStatistics {
46    /// Statistics for each pattern type
47    pub by_pattern: HashMap<String, PatternMetrics>,
48
49    /// Pattern combinations that occur together
50    pub correlations: Vec<PatternCorrelation>,
51
52    /// Most frequent patterns
53    pub top_performers: Vec<PatternPerformance>,
54}
55
56/// Metrics for a specific pattern
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct PatternMetrics {
59    pub occurrences: usize,
60    pub success_rate: f64,
61    pub avg_value: f64,
62    pub avg_duration: f64,
63    pub reliability_score: f64,
64}
65
66/// Correlation between patterns
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct PatternCorrelation {
69    pub pattern_a: String,
70    pub pattern_b: String,
71    pub correlation: f64,
72    pub co_occurrence_rate: f64,
73}
74
75/// Pattern performance ranking
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct PatternPerformance {
78    pub pattern_name: String,
79    pub score: f64,
80    pub metrics: PatternMetrics,
81}
82
83/// Time-based statistical analysis
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct TemporalStatistics {
86    /// Best performing time periods
87    pub best_hours: Vec<TimePeriodStats>,
88    pub best_days: Vec<TimePeriodStats>,
89    pub best_months: Vec<TimePeriodStats>,
90
91    /// Seasonality analysis
92    pub seasonality: SeasonalityAnalysis,
93
94    /// Trend analysis
95    pub trends: TrendAnalysis,
96}
97
98/// Statistics for a time period
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct TimePeriodStats {
101    pub period: String,
102    pub success_rate: f64,
103    pub avg_value: f64,
104    pub occurrence_count: usize,
105}
106
107/// Seasonality patterns
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct SeasonalityAnalysis {
110    pub daily_pattern: bool,
111    pub weekly_pattern: bool,
112    pub monthly_pattern: bool,
113    pub quarterly_pattern: bool,
114    pub strength: f64,
115}
116
117/// Trend analysis results
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct TrendAnalysis {
120    pub pattern_frequency_trend: f64,
121    pub success_rate_trend: f64,
122    pub value_trend: f64,
123    pub trend_direction: TrendDirection,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize)]
127pub enum TrendDirection {
128    Increasing,
129    Decreasing,
130    Stable,
131}