123456789101112131415161718192021222324252627 |
- from datetime import datetime
- from typing import Literal
- from ninja import Schema
- from ninja.errors import ValidationError
- from pydantic import Field, model_validator
- class StatsV2Schema(Schema):
- category: Literal["error", "transaction"]
- interval: Literal["1d", "1h", "1m"] | None = "1h"
- project: list[int] | None = Field(default=None, ge=-1)
- field: Literal["sum(quantity)", "sum(times_seen)"]
- start: datetime
- end: datetime
- @model_validator(mode="after")
- def validate(self):
- series_quantity = (self.end - self.start).days
- if self.interval == "1h":
- series_quantity *= 24
- elif self.interval == "1m":
- series_quantity *= 1440
- if series_quantity > 1000:
- raise ValidationError([{"end": "Too many intervals"}])
- return self
|