Spaces:
Running
Running
File size: 3,902 Bytes
174e0f0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
"""
Data models for the Modius Agent Performance application.
"""
from dataclasses import dataclass
from datetime import datetime
from typing import Optional, List, Dict, Any
@dataclass
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
@dataclass
class AgentInfo:
"""Represents basic agent information."""
agent_id: int
agent_name: str
type_id: int
@dataclass
class AgentType:
"""Represents an agent type."""
type_id: int
type_name: str
@dataclass
class AttributeDefinition:
"""Represents an attribute definition."""
attr_def_id: int
attr_name: str
@dataclass
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
@dataclass
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
@dataclass
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 []
|