Skip to content

Commit

Permalink
filter data added to temp table
Browse files Browse the repository at this point in the history
  • Loading branch information
davidu1975 committed Dec 19, 2024
1 parent e454d58 commit 78ebb54
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions dataservices/management/commands/import_comtrade_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ def get_table_data():

json_data = json.loads(comtrade)

if json_data['commodity_code'] == 'TOTAL' or not json_data['fob_trade_value_in_usd']:
continue

if json_data['trade_flow_code'] not in ('X', 'M'):
continue

if json_data['trade_flow_code'] == 'X' and json_data['reporter_country_iso3'] != 'GBR':
continue

if json_data['trade_flow_code'] == 'M' and json_data['partner_country_iso3'] != 'W00':
continue

yield (
(
data_table,
Expand Down Expand Up @@ -266,13 +278,6 @@ def get_temp_data(self):
commodity_code,
fob_trade_value_in_usd
FROM public.{TEMP_TABLE}
WHERE commodity_code <> 'TOTAL'
AND (
(reporter_country_iso3 = 'GBR' AND trade_flow_code = 'X')
OR (partner_country_iso3 = 'W00' AND trade_flow_code = 'M')
)
AND commodity_code <> 'TOTAL'
AND fob_trade_value_in_usd IS NOT NULL
ORDER BY
year,
reporter_country_iso3,
Expand Down

0 comments on commit 78ebb54

Please sign in to comment.