Spaces:
Running
Running
Create data_models/metrics.py
Browse files
insight_and_tasks/data_models/metrics.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# data_models/metrics.py
|
2 |
+
from dataclasses import dataclass, field
|
3 |
+
from typing import List, Dict, Any, Literal
|
4 |
+
|
5 |
+
# Define literal types for more specific type hinting
|
6 |
+
MetricType = Literal['time_series', 'aggregate', 'categorical']
|
7 |
+
TimeGranularity = Literal['daily', 'weekly', 'monthly', 'yearly', 'other'] # Added 'yearly' and 'other'
|
8 |
+
|
9 |
+
@dataclass
|
10 |
+
class TimeSeriesMetric:
|
11 |
+
"""Structure for time-series based metrics"""
|
12 |
+
metric_name: str
|
13 |
+
values: List[float] = field(default_factory=list)
|
14 |
+
timestamps: List[str] = field(default_factory=list) # Consider using datetime objects or ISO format strings
|
15 |
+
metric_type: MetricType = 'time_series'
|
16 |
+
time_granularity: TimeGranularity = 'monthly'
|
17 |
+
unit: Optional[str] = None # e.g., 'count', '%', 'USD'
|
18 |
+
description: Optional[str] = None # Optional description of the metric
|
19 |
+
|
20 |
+
def __post_init__(self):
|
21 |
+
if len(self.values) != len(self.timestamps):
|
22 |
+
# Or log a warning, or handle as appropriate for your application
|
23 |
+
raise ValueError(f"Length of values ({len(self.values)}) and timestamps ({len(self.timestamps)}) must match for metric '{self.metric_name}'.")
|
24 |
+
|
25 |
+
@dataclass
|
26 |
+
class AgentMetrics:
|
27 |
+
"""
|
28 |
+
Enhanced structure for agent metrics with time-awareness and more details.
|
29 |
+
"""
|
30 |
+
agent_name: str
|
31 |
+
analysis_summary: str # Summary text from the agent's analysis
|
32 |
+
|
33 |
+
# Specific metric categories
|
34 |
+
time_series_metrics: List[TimeSeriesMetric] = field(default_factory=list)
|
35 |
+
aggregate_metrics: Dict[str, float] = field(default_factory=dict) # Key-value pairs for single value metrics
|
36 |
+
categorical_metrics: Dict[str, Any] = field(default_factory=dict) # For distributions, counts by category, etc.
|
37 |
+
# Example: {'industry_distribution': {'Tech': 100, 'Finance': 50}}
|
38 |
+
|
39 |
+
# Contextual information
|
40 |
+
time_periods_covered: List[str] = field(default_factory=list) # e.g., ["2023-01", "2023-02"] or ["Q1 2023", "Q2 2023"]
|
41 |
+
data_sources_used: List[str] = field(default_factory=list) # Information about the input data
|
42 |
+
generation_timestamp: str = field(default_factory=lambda: datetime.utcnow().isoformat()) # When these metrics were generated
|
43 |
+
|
44 |
+
# Optional fields for richer reporting
|
45 |
+
key_insights: List[str] = field(default_factory=list) # Bullet points of key findings
|
46 |
+
potential_errors_or_warnings: List[str] = field(default_factory=list) # Any issues encountered during analysis
|
47 |
+
|
48 |
+
|