Mercurial > personal > weather-server
comparison weather_server/types.py @ 11:52ef21607b31
server: Create endpoint to get some recent readings.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Sun, 06 Oct 2019 13:11:11 -0400 |
| parents | efe7a1eff167 |
| children | beb42c835c52 |
comparison
equal
deleted
inserted
replaced
| 10:6d59f038a58b | 11:52ef21607b31 |
|---|---|
| 3 import datetime | 3 import datetime |
| 4 import math | 4 import math |
| 5 import typing as t | 5 import typing as t |
| 6 | 6 |
| 7 import attr | 7 import attr |
| 8 import pytz | 8 |
| 9 from . import common | |
| 9 | 10 |
| 10 | 11 |
| 11 def c_to_f(c: float) -> float: | 12 def c_to_f(c: float) -> float: |
| 12 return c * 9 / 5 + 32 | 13 return c * 9 / 5 + 32 |
| 13 | 14 |
| 53 def as_dict(self) -> t.Dict[str, t.Any]: | 54 def as_dict(self) -> t.Dict[str, t.Any]: |
| 54 return attr.asdict(self, recurse=False) | 55 return attr.asdict(self, recurse=False) |
| 55 | 56 |
| 56 @classmethod | 57 @classmethod |
| 57 def from_now(cls, **kwargs) -> 'Reading': | 58 def from_now(cls, **kwargs) -> 'Reading': |
| 58 return cls(ingest_time=_utc_now(), **kwargs) | 59 return cls(ingest_time=common.utc_now(), **kwargs) |
| 59 | 60 |
| 60 @property | 61 @property |
| 61 def _gamma(self) -> float: | 62 def _gamma(self) -> float: |
| 62 return ( | 63 return ( |
| 63 math.log(self.rh_pct / 100) + | 64 math.log(self.rh_pct / 100) + |
| 64 _MAGNUS_B * self.temp_c / (_MAGNUS_C + self.temp_c)) | 65 _MAGNUS_B * self.temp_c / (_MAGNUS_C + self.temp_c)) |
| 65 | |
| 66 | |
| 67 def _utc_now(): | |
| 68 return datetime.datetime.utcnow().replace(tzinfo=pytz.UTC) |
