Spaces:
Sleeping
Sleeping
| """ | |
| Data models for the Modius Agent Performance application. | |
| """ | |
| from dataclasses import dataclass | |
| from datetime import datetime | |
| from typing import Optional, List, Dict, Any | |
| class AgentMetric: | |
| """Represents a single agent performance metric.""" | |
| agent_id: int | |
| agent_name: str | |
| timestamp: datetime | |
| metric_type: str | |
| apr: Optional[float] = None | |
| adjusted_apr: Optional[float] = None | |
| roi: Optional[float] = None | |
| volume: Optional[float] = None | |
| agent_hash: Optional[str] = None | |
| is_dummy: bool = False | |
| class AgentInfo: | |
| """Represents basic agent information.""" | |
| agent_id: int | |
| agent_name: str | |
| type_id: int | |
| class AgentType: | |
| """Represents an agent type.""" | |
| type_id: int | |
| type_name: str | |
| class AttributeDefinition: | |
| """Represents an attribute definition.""" | |
| attr_def_id: int | |
| attr_name: str | |
| class AgentStatistics: | |
| """Represents statistical data for an agent.""" | |
| agent_id: int | |
| agent_name: str | |
| total_points: int | |
| apr_points: int | |
| performance_points: int | |
| real_apr_points: int | |
| real_performance_points: int | |
| avg_apr: Optional[float] = None | |
| avg_performance: Optional[float] = None | |
| max_apr: Optional[float] = None | |
| min_apr: Optional[float] = None | |
| avg_adjusted_apr: Optional[float] = None | |
| max_adjusted_apr: Optional[float] = None | |
| min_adjusted_apr: Optional[float] = None | |
| latest_timestamp: Optional[str] = None | |
| class ChartData: | |
| """Represents data for chart visualization.""" | |
| x_values: List[datetime] | |
| y_values: List[float] | |
| agent_name: str | |
| metric_type: str | |
| color: str | |
| visible: bool = True | |
| class MovingAverageData: | |
| """Represents moving average data.""" | |
| timestamp: datetime | |
| value: float | |
| moving_avg: Optional[float] = None | |
| adjusted_moving_avg: Optional[float] = None | |
| class APIResponse: | |
| """Base class for API responses.""" | |
| def __init__(self, data: Dict[str, Any], status_code: int = 200): | |
| self.data = data | |
| self.status_code = status_code | |
| self.success = status_code == 200 | |
| def is_success(self) -> bool: | |
| return self.success | |
| def get_data(self) -> Dict[str, Any]: | |
| return self.data if self.success else {} | |
| class AgentTypeResponse(APIResponse): | |
| """Response for agent type API calls.""" | |
| def get_agent_type(self) -> Optional[AgentType]: | |
| if self.success and self.data: | |
| return AgentType( | |
| type_id=self.data.get('type_id'), | |
| type_name=self.data.get('type_name') | |
| ) | |
| return None | |
| class AttributeDefinitionResponse(APIResponse): | |
| """Response for attribute definition API calls.""" | |
| def get_attribute_definition(self) -> Optional[AttributeDefinition]: | |
| if self.success and self.data: | |
| return AttributeDefinition( | |
| attr_def_id=self.data.get('attr_def_id'), | |
| attr_name=self.data.get('attr_name') | |
| ) | |
| return None | |
| class AgentsListResponse(APIResponse): | |
| """Response for agents list API calls.""" | |
| def get_agents(self) -> List[AgentInfo]: | |
| if self.success and isinstance(self.data, list): | |
| return [ | |
| AgentInfo( | |
| agent_id=agent.get('agent_id'), | |
| agent_name=agent.get('agent_name'), | |
| type_id=agent.get('type_id') | |
| ) | |
| for agent in self.data | |
| if agent.get('agent_id') and agent.get('agent_name') | |
| ] | |
| return [] | |
| class AttributeValuesResponse(APIResponse): | |
| """Response for attribute values API calls.""" | |
| def get_attribute_values(self) -> List[Dict[str, Any]]: | |
| if self.success and isinstance(self.data, list): | |
| return self.data | |
| return [] | |