Skip to content

Commit

Permalink
Code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
dgboss committed Feb 13, 2025
1 parent 84df186 commit 191d096
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
16 changes: 9 additions & 7 deletions wps_shared/wps_shared/schemas/percentiles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" This module contains pydandict schemas relating to the percentile calculator for the API.
"""
from typing import List, Dict
from typing import List, Dict, Optional
from pydantic import BaseModel
from wps_shared.schemas.stations import WeatherStation

Expand All @@ -20,18 +20,20 @@ class PercentileRequest(BaseModel):

class StationSummary(BaseModel):
""" The summary of daily weather data for a given station. """
ffmc: float = None
isi: float = None
bui: float = None

ffmc: Optional[float] = None
isi: Optional[float] = None
bui: Optional[float] = None
years: List[int]
station: WeatherStation


class MeanValues(BaseModel):
""" The mean percentile values for set of stations. """
ffmc: float = None
isi: float = None
bui: float = None

ffmc: Optional[float] = None
isi: Optional[float] = None
bui: Optional[float] = None


class CalculatedResponse(BaseModel):
Expand Down
5 changes: 3 additions & 2 deletions wps_shared/wps_shared/schemas/weather_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ class WeatherModelRun(BaseModel):
class WeatherModelPrediction(BaseModel):
""" Weather model prediction for a particular weather station. """
station: WeatherStation
model_run: WeatherModelRun = None
model_run: Optional[WeatherModelRun] = None
values: List[WeatherModelPredictionValues] = []


class ModelRunPredictions(BaseModel):
""" Predictions for a model run """
model_run: WeatherModelRun = None

model_run: Optional[WeatherModelRun] = None
values: List[WeatherModelPredictionValues] = []


Expand Down
8 changes: 5 additions & 3 deletions wps_shared/wps_shared/utils/polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def polygonize_in_memory(geotiff_filename, layer, field) -> ogr.Layer:
del dst_ds, dst_layer


def polygonize_geotiff_to_shapefile(raster_source_filename, vector_dest_filename):
def polygonize_geotiff_to_shapefile(
raster_source_filename: str, vector_dest_filename: str
):
"""
TODO: Automate this.
At the moment this function isn't used as part of any automated process,
Expand All @@ -70,9 +72,9 @@ def polygonize_geotiff_to_shapefile(raster_source_filename, vector_dest_filename
<vector_dest_filename>.shp, and inserts polygonized contents of source
file into destination file.
"""
if raster_source_filename[-3:] != ".tif":
if not raster_source_filename.endswith(".tif"):
return f"{raster_source_filename} is an invalid file format for raster source"
if vector_dest_filename[-3:] != ".shp":
if not vector_dest_filename.endswith(".shp"):
vector_dest_filename += ".shp"

source_data = gdal.Open(raster_source_filename, gdal.GA_ReadOnly)
Expand Down
4 changes: 2 additions & 2 deletions wps_shared/wps_shared/utils/s3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Utils to help with s3"""

import logging
from typing import Generator, Tuple
from typing import AsyncGenerator, Tuple
from contextlib import asynccontextmanager
from aiobotocore.client import AioBaseClient
from aiobotocore.session import get_session
Expand All @@ -13,7 +13,7 @@


@asynccontextmanager
async def get_client() -> Generator[Tuple[AioBaseClient, str], None, None]:
async def get_client() -> AsyncGenerator[Tuple[AioBaseClient, str], None, None]:
"""Return AioBaseClient client and bucket"""
server = config.get("OBJECT_STORE_SERVER")
user_id = config.get("OBJECT_STORE_USER_ID")
Expand Down
3 changes: 1 addition & 2 deletions wps_shared/wps_shared/wildfire_one/validation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
""" Validation functions that indicate sound response or clean them to our specific standards"""
import math
from typing import Union
from wps_shared.schemas.observations import WeatherReading
from wps_shared.schemas.forecasts import NoonForecast


def get_valid_flags(record: Union[WeatherReading, NoonForecast]):
def get_valid_flags(record: WeatherReading | NoonForecast):
""" Validate fields and return flags indiciating their validity """
temp_valid = record.temperature is not None
rh_valid = record.relative_humidity is not None and validate_metric(
Expand Down
2 changes: 1 addition & 1 deletion wps_shared/wps_shared/wildfire_one/wfwx_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ async def get_daily_actuals_for_stations_between_dates(session: ClientSession, h
end_timestamp = math.floor(end_datetime.timestamp() * 1000)

cache_expiry_seconds: Final = int(config.get("REDIS_DAILIES_BY_STATION_CODE_CACHE_EXPIRY", 300))
use_cache = cache_expiry_seconds is not None and config.get("REDIS_USE") == "True"
use_cache = config.get("REDIS_USE") == "True"

# Iterate through "raw" hourlies data.
dailies_iterator = fetch_paged_response_generator(
Expand Down
2 changes: 1 addition & 1 deletion wps_shared/wps_shared/wildfire_one/wildfire_fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def prepare_fetch_hourlies_query(raw_station: dict, start_timestamp: datetime, e

station_id = raw_station["id"]
params = {"startTimestamp": query_start_timestamp, "endTimestamp": query_end_timestamp, "stationId": station_id}
endpoint = "/v1/hourlies/search/" "findHourliesByWeatherTimestampBetweenAndStationIdEqualsOrderByWeatherTimestampAsc"
endpoint = "/v1/hourlies/search/findHourliesByWeatherTimestampBetweenAndStationIdEqualsOrderByWeatherTimestampAsc"
url = f"{base_url}{endpoint}"

return url, params
Expand Down

0 comments on commit 191d096

Please sign in to comment.