Skip to content

Commit

Permalink
Merge pull request #396 from Open-Earth-Foundation/mendoza_EIE_integr…
Browse files Browse the repository at this point in the history
…ation

Mendoza eie integration
  • Loading branch information
evanp committed Mar 28, 2024
2 parents 2b37a5a + b039d5e commit d1c166c
Show file tree
Hide file tree
Showing 24 changed files with 4,031 additions and 55 deletions.
22 changes: 22 additions & 0 deletions global-api/importer/argentinian_datasets/ENARGAS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ENARGAS
Gas consumption data for argentinian provinces

1. Extract the activity data from the source [ENARGAS](https://dod.enargas.gob.ar/) (manually):
- variable: consumo de gas
- aspectos: tipo de usuario
- distribuidora: todos
- desagregación espacial: provincia
- desagregación temporal: anual
- año: 2018 al 2022 (para tener años completos)

**data accesed: March, 12th 2023**

2. Transform activity data into emissions data aligned with the global API schema:
```bash
python ./importer/argentinian_datasets/ENARGAS/transformation_ENARGAS.py --filepath [path where the transformed data will be saved]
```

3. Extract the activity row from the source:
```bash
psql -U ccglobal -d ccglobal -f ./importer/argentinian_datasets/ENARGAS/load_ENARGAS.sql
```
34 changes: 34 additions & 0 deletions global-api/importer/argentinian_datasets/ENARGAS/load_ENERGAS.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Create a staging table
CREATE TEMP TABLE IF NOT EXISTS ENARGAS_staging (LIKE regionwide_emissions INCLUDING ALL);

-- Clear the staging table
TRUNCATE ENARGAS_staging;

-- Load the staging table from the downloaded file
\copy ENARGAS_staging ("GPC_refno",activity_name,activity_units,activity_value,emission_factor_units,emission_factor_value,emissions_units,emissions_value,gas_name,id,region_name,region_code,source_name,temporal_granularity,year) FROM '/Users/maureenfonseca/Documents/OEF/Cities/CityCatalyst/global-api/importer/argentinian_datasets/ENARGAS/processed_enargas_gas_consumption_AR.csv' WITH (FORMAT CSV, HEADER);

-- Update the main table with the staging table
INSERT INTO regionwide_emissions ("GPC_refno",activity_name,activity_units,activity_value,emission_factor_units,emission_factor_value,emissions_units,emissions_value,gas_name,id,region_name,region_code,source_name,temporal_granularity,year)
SELECT "GPC_refno",activity_name,activity_units,activity_value,emission_factor_units,emission_factor_value,emissions_units,emissions_value,gas_name,id,region_name,region_code,source_name,temporal_granularity,year
FROM ENARGAS_staging
ON CONFLICT ON CONSTRAINT regionwide_emissions_pkey
DO UPDATE SET
id = excluded.id,
source_name = excluded.source_name,
"GPC_refno" = excluded."GPC_refno",
region_name = excluded.region_name,
region_code = excluded.region_code,
temporal_granularity = excluded.temporal_granularity,
year = excluded.year,
activity_name = excluded.activity_name,
activity_value = excluded.activity_value,
activity_units = excluded.activity_units,
gas_name = excluded.gas_name,
emission_factor_value = excluded.emission_factor_value,
emission_factor_units = excluded.emission_factor_units,
emissions_value = excluded.emissions_value,
emissions_units = excluded.emissions_units;

-- Drop the staging table
DROP TABLE ENARGAS_staging;

Large diffs are not rendered by default.

Loading

0 comments on commit d1c166c

Please sign in to comment.