feat: add API to get daily consumption
This commit is contained in:
parent
9c883a8eca
commit
a0acb2950c
18 changed files with 278 additions and 6 deletions
28
server/app/adapters/http/_readings_schemas.py
Normal file
28
server/app/adapters/http/_readings_schemas.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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(**p.__dict__) for p in r.points],
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue