122 lines
2.5 KiB
Python
122 lines
2.5 KiB
Python
import datetime
|
|
from enum import Enum
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class Model(BaseModel):
|
|
class Config:
|
|
use_enum_values = True
|
|
|
|
|
|
class Location(Model):
|
|
id: str
|
|
name: str
|
|
lat: float
|
|
lon: float
|
|
country: str
|
|
district: str
|
|
subdistrict: str
|
|
|
|
|
|
class Cloudness(str, Enum):
|
|
CLEAR = "clear"
|
|
PARTLY_CLOUDY = "party_cloudy"
|
|
CLOUDY = "cloudy"
|
|
MAINLY_CLOUDY = "mainly_cloudy"
|
|
|
|
|
|
class Precipitation(str, Enum):
|
|
NO = "no"
|
|
SMALL_RAIN = "small_rain"
|
|
RAIN = "rain"
|
|
HEAVY_RAIN = "heavy_rain"
|
|
SHOWER = "shower"
|
|
SNOW = "snow"
|
|
HEAVY_SNOW = "heavy_snow"
|
|
|
|
|
|
class Sky(Model):
|
|
cloudness: Cloudness
|
|
precipitation: Precipitation
|
|
thunder: bool
|
|
fog: bool
|
|
|
|
|
|
class WindDirection(str, Enum):
|
|
CALM = "calm"
|
|
N = "N"
|
|
NE = "NE"
|
|
E = "E"
|
|
SE = "SE"
|
|
S = "S"
|
|
SW = "SW"
|
|
W = "W"
|
|
NW = "NW"
|
|
|
|
|
|
class WindDirectionDeg(float):
|
|
@property
|
|
def direction(self) -> WindDirection:
|
|
return self.to_direction()
|
|
|
|
@property
|
|
def value(self) -> float:
|
|
return self
|
|
|
|
# pylint:disable=too-many-return-statements
|
|
def to_direction(self) -> WindDirection:
|
|
if self > 337.5 or self <= 22.25:
|
|
return WindDirection.N
|
|
elif self <= 67.5:
|
|
return WindDirection.NE
|
|
elif self <= 112.5:
|
|
return WindDirection.E
|
|
elif self <= 157.5:
|
|
return WindDirection.SE
|
|
elif self <= 202.5:
|
|
return WindDirection.S
|
|
elif self <= 247.5:
|
|
return WindDirection.SW
|
|
elif self <= 292.5:
|
|
return WindDirection.W
|
|
elif self <= 337.5:
|
|
return WindDirection.NW
|
|
else:
|
|
return WindDirection.CALM
|
|
|
|
@classmethod
|
|
def from_direction(cls, direction: WindDirection) -> "WindDirectionDeg":
|
|
return cls(
|
|
{
|
|
WindDirection.CALM: -1,
|
|
WindDirection.N: 0,
|
|
WindDirection.NE: 45,
|
|
WindDirection.E: 90,
|
|
WindDirection.SE: 135,
|
|
WindDirection.S: 180,
|
|
WindDirection.SW: 225,
|
|
WindDirection.W: 270,
|
|
WindDirection.NW: 315,
|
|
}[direction]
|
|
)
|
|
|
|
|
|
class WeatherValue(Model):
|
|
date: datetime.datetime
|
|
sky: Sky
|
|
temperature: list[int]
|
|
wind_speed: int
|
|
wind_gust: int
|
|
wind_direction: float
|
|
precipitation: float
|
|
pressure: list[int]
|
|
humidity: int
|
|
|
|
|
|
class WeatherResponse(Model):
|
|
location: str
|
|
date: datetime.date
|
|
period: str
|
|
values: list[WeatherValue]
|