-
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.
Updates 2024-08-01 - Created trade barriers bronze asset
- Loading branch information
1 parent
ae421ec
commit 8e780ab
Showing
11 changed files
with
96 additions
and
59 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 |
---|---|---|
|
@@ -181,4 +181,5 @@ scripts/.build | |
df.parquet | ||
workspace.yaml | ||
quick_check.ipynb | ||
tmp* | ||
tmp* | ||
test.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
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
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
49 changes: 0 additions & 49 deletions
49
analytics_platform_dagster/assets/trade_data_assets/analytics_platform_dbt_assets.py
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
..._platform_dagster/assets/trade_data_assets/analytics_platform_dbt_trade_barrier_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,37 @@ | ||
|
||
from pydantic import ValidationError | ||
from dagster import asset, op, AssetExecutionContext | ||
|
||
from ...utils.requests_helper.requests_helper import return_json | ||
from ...models.trade_data_models.trade_barriers_model import TradingBarriers | ||
from ...utils.variables_helper.url_links import asset_urls | ||
|
||
@op | ||
def validate_model(trade_barriers_data) -> None: | ||
"""Validate json against pydantic model""" | ||
try: | ||
TradingBarriers.model_validate(trade_barriers_data) | ||
except ValidationError as e: | ||
print("Validation errors:") | ||
for error in e.errors(): | ||
print(f"Field: {error['loc']}, Error: {error['msg']}") | ||
raise | ||
|
||
@asset( | ||
group_name="trade_assets", | ||
io_manager_key="S3Json" | ||
) | ||
def dbt_trade_barriers_bronze(context: AssetExecutionContext): | ||
""" | ||
Load data into bronze bucket | ||
""" | ||
try: | ||
url = asset_urls.get("dbt_trading_bariers_asset") | ||
data = return_json(url) | ||
validate_model(data) | ||
context.log.info("Model Validation Successful") | ||
return data | ||
except Exception as error: | ||
print(f"Error in dbt_trade_barriers: {str(error)}") | ||
raise error | ||
|
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
44 changes: 44 additions & 0 deletions
44
analytics_platform_dagster/models/trade_data_models/trade_barriers_model.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,44 @@ | ||
from typing import List, Any, Optional | ||
from pydantic import BaseModel | ||
|
||
class Category(BaseModel): | ||
pass | ||
|
||
class OverseasRegion(BaseModel): | ||
id: str | ||
name: str | ||
|
||
class TradingBloc(BaseModel): | ||
code: str | ||
name: str | ||
overseas_regions: List[OverseasRegion] | ||
short_name: str | ||
|
||
class Country(BaseModel): | ||
name: str | ||
trading_bloc: Optional[TradingBloc] = None | ||
|
||
class Sector(BaseModel): | ||
name: str | ||
|
||
class Barrier(BaseModel): | ||
categories: List[Category] | ||
caused_by_trading_bloc: Optional[Any] = None | ||
country: Country | ||
id: str | ||
is_resolved: bool | ||
last_published_on: str | ||
location: str | ||
reported_on: Optional[str] = None | ||
sectors: List[Sector] | ||
status_date: str | ||
summary: str | ||
title: str | ||
trading_bloc: Optional[str] = None | ||
|
||
class TradingBarriers(BaseModel): | ||
barriers: List[Barrier] | ||
|
||
model_config = { | ||
"extra": "ignore" | ||
} |
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
Empty file.
5 changes: 3 additions & 2 deletions
5
analytics_platform_dagster/utils/variables_helper/url_links.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
asset_urls = { | ||
"dbt_asset":"https://data.api.trade.gov.uk/v1/datasets/market-barriers/versions/latest/data?format=json", | ||
"dbt_trading_bariers_asset":"https://data.api.trade.gov.uk/v1/datasets/market-barriers/versions/latest/data?format=json", | ||
"ea_flood_areas":"https://environment.data.gov.uk/flood-monitoring/id/floodAreas?_limit=9999", | ||
"ea_floods":"https://environment.data.gov.uk/flood-monitoring/id/floodAreas?_limit=9999", | ||
"london_data_store":"https://data.london.gov.uk/api/datasets/export.json", | ||
"national_charge_points": "https://ukpowernetworks.opendatasoft.com/api/explore/v2.1/catalog/datasets/ozev-ukpn-national-chargepoint-register/exports/json?lang=en&timezone=Europe%2FLondon", | ||
"national_charge_points_api": "https://ukpowernetworks.opendatasoft.com/api/explore/v2.1/catalog/datasets/ozev-ukpn-national-chargepoint-register/records?limit=1" | ||
"national_charge_points_api": "https://ukpowernetworks.opendatasoft.com/api/explore/v2.1/catalog/datasets/ozev-ukpn-national-chargepoint-register/records?limit=1", | ||
"carbon_intensity_api": "https://api.carbonintensity.org.uk/regional/regionid/" | ||
} |