Skip to content

Commit ef5c54c

Browse files
committed
Fix flake8
1 parent 175ada0 commit ef5c54c

File tree

8 files changed

+41
-52
lines changed

8 files changed

+41
-52
lines changed

src/wqie/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
defs = Definitions(
1515
assets=[county_stations],
1616
jobs=[process_county_stations],
17-
)
17+
)

src/wqie/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pydantic import BaseModel
1212
from typing import List, Dict, Any
1313

14+
1415
class Station(BaseModel):
1516
station_id: str
1617
name: str
@@ -23,5 +24,6 @@ class Station(BaseModel):
2324
provider: str
2425
datastreams: List[Dict[str, Any]]
2526

27+
2628
class StationsData(BaseModel):
27-
stations: List[Station]
29+
stations: List[Station]

src/wqie/ops/datastreams.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import logging
1+
22
from csv import DictReader
33
from datetime import datetime
44
from io import StringIO
55
from pytz import timezone
66
import re
77
from requests import Session
8-
from typing import Iterable, Dict, List
9-
from dagster import op, job, Out, get_dagster_logger
8+
from typing import Iterable
9+
from dagster import get_dagster_logger
1010

1111
from wqie.env import RESULTS_URL, NLDI_URL
1212
from wqie.util import make_uuid, url_join
1313
from wqie.mapping import MAPPING
1414

1515
LOGGER = get_dagster_logger()
1616

17+
1718
def fetch_datastreams(station_id: str):
1819
"""
1920
Load datasets from USBR RISE API
@@ -59,7 +60,10 @@ def yield_datastreams(station_identifier: str,
5960
kwargs = {}
6061
monitoring_location_identifier = \
6162
dataset['MonitoringLocationIdentifier']
62-
url = url_join(NLDI_URL, "linked-data/wqp", monitoring_location_identifier)
63+
url = url_join(
64+
NLDI_URL,
65+
"linked-data/wqp",
66+
monitoring_location_identifier)
6367
try:
6468
result = http.get(url)
6569
feature = result.json()['features'][0]

src/wqie/ops/fetch.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# =================================================================
1010

1111
from dagster import op, Out
12-
from io import BytesIO
1312
import requests
1413
from typing import Dict, Any, List
1514
import csv
@@ -18,7 +17,7 @@
1817

1918

2019
@op(out={"sites": Out(list)})
21-
def fetch_station_metadata( county: str) -> List[Dict[str, Any]]:
20+
def fetch_station_metadata(county: str) -> List[Dict[str, Any]]:
2221
"""
2322
Fetch station metadata for a single county.
2423
"""
@@ -30,12 +29,13 @@ def fetch_station_metadata( county: str) -> List[Dict[str, Any]]:
3029
}
3130
response = requests.get(RESULTS_URL, params=params)
3231
response.raise_for_status()
33-
32+
3433
stations = []
3534
for row in csv.DictReader(response.text.splitlines()):
3635
stations.append(row)
3736
return stations
3837

38+
3939
@op(out={"station_details": Out(list)})
4040
def fetch_site_metadata(site_ids: List[str]) -> List[Dict[str, Any]]:
4141
"""
@@ -47,7 +47,7 @@ def fetch_site_metadata(site_ids: List[str]) -> List[Dict[str, Any]]:
4747
}
4848
response = requests.post(STATION_URL, data=params)
4949
response.raise_for_status()
50-
50+
5151
details = []
5252
for row in csv.DictReader(response.text.splitlines()):
5353
details.append(row)

src/wqie/ops/transform.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#
99
# =================================================================
1010

11-
import logging
1211
from dagster import op, get_dagster_logger
1312
from typing import List, Dict, Any
1413
import requests
@@ -29,13 +28,14 @@ def upsert_collection_item(collection: str, item: Dict[str, Any]) -> bool:
2928
response = requests.post(api_url, json=item)
3029
return response.status_code == 201 # Return True if creation is successful
3130

31+
3232
@op
3333
def transform_stations(stations: List[Dict[str, Any]]) -> StationsData:
3434
"""
3535
Transform raw station data into structured format.
3636
"""
3737
transformed_stations = []
38-
38+
3939
for row in stations:
4040
station = Station(
4141
station_id=row['MonitoringLocationIdentifier'],
@@ -50,27 +50,28 @@ def transform_stations(stations: List[Dict[str, Any]]) -> StationsData:
5050
datastreams=[]
5151
)
5252
transformed_stations.append(station)
53-
53+
5454
return StationsData(stations=transformed_stations)
5555

56+
5657
@op
5758
def publish_station_collection(stations_data: StationsData) -> None:
5859
"""
5960
Publishes station collection to API config and backend.
60-
61+
6162
Takes in the transformed station data and sends it to the SensorThings API.
62-
63+
6364
:param stations_data: The transformed station data.
6465
:returns: `None`
6566
"""
6667
# Iterate over the transformed stations data
6768
for station in stations_data.stations:
6869
station_identifier = station.station_id
69-
70+
7071
try:
7172
datastreams = load_datastreams(station_identifier)
7273
except Exception:
73-
LOGGER.warning(f"Failed to load datastreams for {station_identifier}")
74+
LOGGER.warning(f"Failed to load datastreams for {station_identifier}") # noqa
7475
continue
7576

7677
try:
@@ -100,9 +101,9 @@ def publish_station_collection(stations_data: StationsData) -> None:
100101
}],
101102
'properties': {
102103
'mainstem': mainstem,
103-
'hu08': url_join(GEOCONNEX_URL, 'ref/hu08', station.huc_code),
104-
'state': url_join(GEOCONNEX_URL, 'ref/states', station.state_code),
105-
'county': url_join(GEOCONNEX_URL, 'ref/counties', f"{station.state_code}{station.county_code}"),
104+
'hu08': url_join(GEOCONNEX_URL, 'ref/hu08', station.huc_code), # noqa
105+
'state': url_join(GEOCONNEX_URL, 'ref/states', station.state_code), # noqa
106+
'county': url_join(GEOCONNEX_URL, 'ref/counties', f"{station.state_code}{station.county_code}"), # noqa
106107
'provider': station.provider
107108
},
108109
'Datastreams': list(datastreams)
@@ -118,6 +119,7 @@ def publish_station_collection(stations_data: StationsData) -> None:
118119

119120
return
120121

122+
121123
def get_mainstem_uri(id):
122124
# Convert the input geom to GeoJSON using Shapely
123125

src/wqie/partitions.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from dagster import StaticPartitionsDefinition, get_dagster_logger
1212
import requests
1313
from typing import List
14-
import logging
1514

16-
logger = logging.getLogger(__name__)
15+
LOGGER = get_dagster_logger()
16+
1717

1818
def load_us_counties() -> List[str]:
1919
"""
@@ -22,24 +22,25 @@ def load_us_counties() -> List[str]:
2222
url = "https://reference.geoconnex.us/collections/counties/items"
2323
params = {"limit": 100}
2424
counties = []
25-
get_dagster_logger().debug(url)
25+
LOGGER.debug(url)
2626
while True:
2727
response = requests.get(url, params=params)
2828
response.raise_for_status()
2929
data = response.json()
30-
30+
3131
for feature in data["features"]:
3232
props = feature["properties"]
3333
county_code = f"US:{props['statefp']}:{props['countyfp']}"
3434
counties.append(county_code)
35-
35+
3636
if len(data["features"]) < params["limit"]:
3737
break
38-
38+
3939
params["offset"] = params.get("offset", 0) + params["limit"]
40-
40+
4141
return sorted(counties)
4242

43+
4344
county_partitions = StaticPartitionsDefinition(
4445
load_us_counties()
4546
)

src/wqie/util.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Union, Any
55
from uuid import UUID
66

7+
78
def get_typed_value(value) -> Union[float, int, str]:
89
"""
910
Derive true type from data value
@@ -25,6 +26,7 @@ def get_typed_value(value) -> Union[float, int, str]:
2526

2627
return value2
2728

29+
2830
def extract_coord(p):
2931
"""
3032
helper function to extract coordinate
@@ -46,6 +48,7 @@ def clean_word(input: str, delim: str = ' ') -> str:
4648
"""
4749
return delim.join(re.findall(r'\w+', input))
4850

51+
4952
def url_join(*parts: str) -> str:
5053
"""
5154
helper function to join a URL from a number of parts/fragments.
@@ -61,6 +64,7 @@ def url_join(*parts: str) -> str:
6164

6265
return '/'.join([str(p).strip().strip('/') for p in parts]).rstrip('/')
6366

67+
6468
def get_env(key: str, fallback: Any = None) -> str:
6569
"""Fetch environment variable"""
6670
val = os.environ.get(key, fallback)
@@ -69,6 +73,7 @@ def get_env(key: str, fallback: Any = None) -> str:
6973

7074
return val
7175

76+
7277
def make_uuid(input: str, raw: bool = False) -> UUID:
7378
"""
7479
helper function to make uuid

uv.lock

-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)