mirror of
https://github.com/jdejaegh/python-irceline.git
synced 2025-06-26 19:35:40 +02:00
Add docstring
This commit is contained in:
parent
59b584d943
commit
3daaacf03b
4 changed files with 33 additions and 3 deletions
|
@ -197,7 +197,20 @@ class IrcelineRioClient(IrcelineBaseClient):
|
|||
class IrcelineForecastClient(IrcelineBaseClient):
|
||||
"""API client for forecast IRCEL - CELINE open data"""
|
||||
|
||||
async def get_forecast(self, day: date, features: List[ForecastFeature], position: Tuple[float, float]) -> dict:
|
||||
async def get_forecasts(self,
|
||||
day: date,
|
||||
features: List[ForecastFeature],
|
||||
position: Tuple[float, float]
|
||||
) -> Dict[Tuple[ForecastFeature, date], FeatureValue]:
|
||||
"""
|
||||
Get forecasted concentrations for the given features at the given position. The forecasts are downloaded for
|
||||
the specified day and the 4 next days as well
|
||||
:param day: date at which the forecast are computed (generally today). If unavailable, the day before will be
|
||||
tried as well
|
||||
:param features: pollutants to get the forecasts for
|
||||
:param position: (lat, long)
|
||||
:return: dict where key is (ForecastFeature, date of the forecast) and value is a FeatureValue
|
||||
"""
|
||||
x, y = round_coordinates(position[0], position[1])
|
||||
|
||||
result = dict()
|
||||
|
@ -227,6 +240,14 @@ class IrcelineForecastClient(IrcelineBaseClient):
|
|||
|
||||
@staticmethod
|
||||
def extract_result_from_csv(x: float, y: float, csv_text: str) -> float | None:
|
||||
"""
|
||||
Find the value of the forecast for the given (x, y) position in the csv text.
|
||||
x, y should already be rounded to match the positions found in the csv
|
||||
:param x: latitude (rounded)
|
||||
:param y: longitude (rounded)
|
||||
:param csv_text: text of the CSV file
|
||||
:return: value matching the position if found, else None
|
||||
"""
|
||||
f = StringIO(csv_text)
|
||||
for row in csv.reader(f, delimiter=';'):
|
||||
try:
|
||||
|
|
|
@ -34,5 +34,6 @@ class ForecastFeature(StrEnum):
|
|||
|
||||
|
||||
class FeatureValue(TypedDict):
|
||||
# Timestamp at which the value was computed
|
||||
timestamp: datetime | date
|
||||
value: int | float | None
|
||||
|
|
|
@ -29,7 +29,7 @@ class SizedDict(OrderedDict):
|
|||
raise NotImplementedError()
|
||||
|
||||
|
||||
def epsg_transform(position: Tuple[float, float]) -> tuple:
|
||||
def epsg_transform(position: Tuple[float, float]) -> Tuple[int, int]:
|
||||
"""
|
||||
Convert 'EPSG:4326' coordinates to 'EPSG:31370' coordinates
|
||||
:param position: (x, y) coordinates
|
||||
|
@ -39,6 +39,13 @@ def epsg_transform(position: Tuple[float, float]) -> tuple:
|
|||
return round(result[0]), round(result[1])
|
||||
|
||||
|
||||
def round_coordinates(x: float, y: float, step=.05):
|
||||
def round_coordinates(x: float, y: float, step=.05) -> Tuple[float, float]:
|
||||
"""
|
||||
Round the coordinate to the precision given by step
|
||||
:param x: latitude
|
||||
:param y: longitude
|
||||
:param step: precision of the rounding
|
||||
:return: x and y round to the closest step increment
|
||||
"""
|
||||
n = 1 / step
|
||||
return round(x * n) / n, round(y * n) / n
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from src.open_irceline.utils import SizedDict, round_coordinates, epsg_transform
|
||||
import pytest
|
||||
|
||||
|
||||
def test_size_dict():
|
||||
s_dict = SizedDict(5)
|
||||
assert len(s_dict) == 0
|
||||
|
|
Loading…
Add table
Reference in a new issue