add: hub template
This commit is contained in:
33
hub/app/entities/agent_data.py
Normal file
33
hub/app/entities/agent_data.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, field_validator
|
||||
|
||||
|
||||
class AccelerometerData(BaseModel):
|
||||
x: float
|
||||
y: float
|
||||
z: float
|
||||
|
||||
|
||||
class GpsData(BaseModel):
|
||||
latitude: float
|
||||
longitude: float
|
||||
|
||||
|
||||
class AgentData(BaseModel):
|
||||
user_id: int
|
||||
accelerometer: AccelerometerData
|
||||
gps: GpsData
|
||||
timestamp: datetime
|
||||
|
||||
@classmethod
|
||||
@field_validator('timestamp', mode='before')
|
||||
def parse_timestamp(cls, value):
|
||||
# Convert the timestamp to a datetime object
|
||||
if isinstance(value, datetime):
|
||||
return value
|
||||
try:
|
||||
return datetime.fromisoformat(value)
|
||||
except (TypeError, ValueError):
|
||||
raise ValueError(
|
||||
"Invalid timestamp format. Expected ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)."
|
||||
)
|
||||
Reference in New Issue
Block a user