-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added in uk charge point data asset and refactored some pydantic models
- Loading branch information
1 parent
9884b4e
commit fed4bea
Showing
14 changed files
with
673 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,3 +186,4 @@ test.py | |
creds.py | ||
.streamlit | ||
poetry.lock | ||
data_testing/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 0 additions & 129 deletions
129
...ter/assets/infrastructure_data_assets/analytics_platform_national_charge_points_assets.py
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
...latform_dagster/assets/infrastructure_data_assets/national_charge_points_london_assets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
This currently only provides data for London only | ||
""" | ||
import pandas as pd | ||
import io | ||
|
||
from pydantic import ValidationError | ||
from ...utils.requests_helper.requests_helper import return_json | ||
from ...utils.variables_helper.url_links import asset_urls | ||
from ...models.infrastructure_data_models.national_charge_point_london_model import ( | ||
ChargeDevice, | ||
) | ||
from dagster import AssetExecutionContext, AssetIn, asset | ||
from ...utils.slack_messages.slack_message import with_slack_notification | ||
|
||
@asset(group_name="infrastructure_assets", io_manager_key="S3Parquet") | ||
def national_charge_point_london_bronze(context: AssetExecutionContext): | ||
""" | ||
Fetches json data and uploads charge point data to S3 using IO Manager | ||
Returns: | ||
A parquet file in S3 | ||
""" | ||
|
||
# Fetch url | ||
url = asset_urls.get("national_charge_point_london") | ||
if url is None: | ||
raise ValueError("API_ENDPOINT can't be None") | ||
|
||
response = return_json(url) | ||
validation_errors = [] | ||
|
||
|
||
try: | ||
ChargeDevice.model_validate(response) | ||
except ValidationError as e: | ||
validation_errors = e.errors() | ||
|
||
df = pd.DataFrame(response) | ||
df = df.astype(str) | ||
|
||
context.log.info(f"Processed {len(df)} records with {len(validation_errors)} validation errors") | ||
|
||
parquet_buffer = io.BytesIO() | ||
df.to_parquet(parquet_buffer, engine="pyarrow") | ||
parquet_bytes = parquet_buffer.getvalue() | ||
|
||
context.log.info("Successfully processed batch into Parquet format") | ||
return parquet_bytes | ||
|
||
@asset( | ||
group_name="infrastructure_assets", | ||
io_manager_key="DeltaLake", | ||
metadata={"mode": "overwrite"}, | ||
ins={ | ||
"national_charge_point_london_bronze": AssetIn( | ||
"national_charge_point_london_bronze" | ||
) | ||
}, | ||
required_resource_keys={"slack"} | ||
) | ||
@with_slack_notification("National EV Charge Point Data London") | ||
def national_charge_point_london_silver( | ||
context: AssetExecutionContext, national_charge_point_london_bronze | ||
) -> pd.DataFrame: | ||
""" | ||
Write charge point data out to Delta Lake | ||
Returns: | ||
Delta Lake table in S3. | ||
""" | ||
try: | ||
df = pd.DataFrame(national_charge_point_london_bronze) | ||
return df | ||
|
||
except Exception as e: | ||
context.log.error(f"Error processing data: {e}") | ||
raise |
Oops, something went wrong.