39 lines
1 KiB
Python
39 lines
1 KiB
Python
from datetime import datetime
|
|
from pydantic import BaseModel
|
|
|
|
from domain.entities import ConsumptionResponse
|
|
|
|
|
|
class ConsumptionPointSchema(BaseModel):
|
|
period: datetime
|
|
pulse_count_start: int
|
|
pulse_count_end: int
|
|
delta_pulses: int
|
|
delta_m3: float
|
|
|
|
|
|
class ConsumptionResponseSchema(BaseModel):
|
|
dev_eui: str
|
|
start: datetime
|
|
end: datetime
|
|
granularity: str
|
|
points: list[ConsumptionPointSchema]
|
|
|
|
@classmethod
|
|
def from_domain(cls, r: ConsumptionResponse) -> "ConsumptionResponseSchema":
|
|
return cls(
|
|
dev_eui=r.dev_eui,
|
|
start=r.start,
|
|
end=r.end,
|
|
granularity=r.granularity,
|
|
points=[
|
|
ConsumptionPointSchema(
|
|
period=p.period,
|
|
pulse_count_start=p.pulse_count_start,
|
|
pulse_count_end=p.pulse_count_end,
|
|
delta_pulses=p.delta_pulses,
|
|
delta_m3=p.delta_m3,
|
|
)
|
|
for p in r.points
|
|
],
|
|
)
|