Skip to content

Commit

Permalink
update the termnology
Browse files Browse the repository at this point in the history
  • Loading branch information
liniiiiii committed Jan 22, 2025
1 parent 3a6454f commit 54d9c63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
8 changes: 3 additions & 5 deletions Database/EUR_convert.py → Database/convert_currency_EUR.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@
logger.info("Converting USD to EUR")
for cat in ia_utils.monetary_categories:
logger.info(f"Converting currencies in L1 for category {cat}")
l1 = l1.apply(
lambda x: cc_utils.Lasted_Year_USD_Inflated_to_EUR(x, l1_impact=cat, level="l1", impact=cat), axis=1
)
l1 = l1.apply(lambda x: cc_utils.Convert_USD_to_EUR(x, l1_impact=cat, level="l1", impact=cat), axis=1)
logger.info(f"Converting currencies in L2 for category {cat}")
l2[cat] = l2[cat].apply(
lambda x: cc_utils.Lasted_Year_USD_Inflated_to_EUR(x, l1_impact=None, level="l2", impact=cat), axis=1
lambda x: cc_utils.Convert_USD_to_EUR(x, l1_impact=None, level="l2", impact=cat), axis=1
)
logger.info(f"Converting currencies in L3 for category {cat}")
l3[cat] = l3[cat].apply(
lambda x: cc_utils.Lasted_Year_USD_Inflated_to_EUR(x, l1_impact=None, level="l3", impact=cat), axis=1
lambda x: cc_utils.Convert_USD_to_EUR(x, l1_impact=None, level="l3", impact=cat), axis=1
)

logger.info(f"Storing results in {args.output_dir}")
Expand Down
14 changes: 6 additions & 8 deletions Database/scr/normalize_currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ def convert_to_USD_yearly_avg(
)
return amount

# only provide EUR in lastest year in the database
def convert_USD_to_EUR_latest_year_avg(
# only provide EUR in inflation year in the database
def normalize_row_EUR_inflation_year(
self, currency: str, amount: float, year: int, event_id: str, level: str, impact: str
):
try:
Expand All @@ -254,7 +254,7 @@ def convert_USD_to_EUR_latest_year_avg(
), f"Amount is missing or invalid: '{amount}' of type '{type(amount)}'"
assert currency, "Currency is missing"

# always use the lastest year of EUR-USD conversion rate
# always use the inflation year of EUR-USD conversion rate
# extract rate
rate = (
self.currency_conversion_yearly_avg[self.eur]
Expand Down Expand Up @@ -351,9 +351,7 @@ def normalize_row_USD(self, row: pd.DataFrame, l1_impact: None | str, level: str
self.logger.info(f"Could not convert to USD since no year can be inferred. Row: {dict(row)}")
return row

def Lasted_Year_USD_Inflated_to_EUR(
self, row: pd.DataFrame, l1_impact: None | str, level: str, impact: str
) -> pd.DataFrame:
def Convert_USD_to_EUR(self, row: pd.DataFrame, l1_impact: None | str, level: str, impact: str) -> pd.DataFrame:
num_min, num_max, num_unit, num_approx, num_inflation_adjusted, num_inflation_adjusted_year = (
self.num_min,
self.num_max,
Expand Down Expand Up @@ -382,10 +380,10 @@ def Lasted_Year_USD_Inflated_to_EUR(

if year:
if row[num_unit] == self.usd:
row[num_min] = self.convert_USD_to_EUR_latest_year_avg(
row[num_min] = self.normalize_row_EUR_inflation_year(
row[num_unit], row[num_min], year=year, event_id=row[self.event_id], level=level, impact=impact
)
row[num_max] = self.convert_USD_to_EUR_latest_year_avg(
row[num_max] = self.normalize_row_EUR_inflation_year(
row[num_unit], row[num_max], year=year, event_id=row[self.event_id], level=level, impact=impact
)
row[num_approx] = 1 # adjusted value are all approximations
Expand Down
4 changes: 2 additions & 2 deletions releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

| [releases/impactdb.v1.0.dg_filled.db](releases/impactdb.v1.0.dg_filled.db) | A **post-processed** database after applying a final layer of post-processing, excluding the handling of currencies and inflation adjustment (has missing validation rules) |
| [releases/impactdb.v1.1.dg_filled.db](releases/impactdb.v1.1.dg_filled.db) | A **post-processed** database after applying a final layer of post-processing, including the handling of currencies and inflation adjustment. In this release, end years of events are nullable. |
| [releases/impactdb.v1.2.dg_filled.db](releases/impactdb.v1.1.dg_filled.db) **Lastest 2024 USD version** | A **post-processed** database that improves on [releases/impactdb.v1.1.dg_filled.db](releases/impactdb.v1.1.dg_filled.db) by removing events that have no L1/L2/L3 impacts (ie. all impact data in L1 is NULL), most currencies are converted to USD in the database and inflated to 2024 value. |
| [releases/impactdb.v1.3.dg_filled.db](releases/impactdb.v1.1.dg_filled.db) **Lastest 2024 EUR version** | A **post-processed** database that convert 2024 USD to 2024 EUR on [releases/impactdb.v1.2.dg_filled.db](releases/impactdb.v1.1.dg_filled.db) by using a constant conversion rate in 2024 |
| [releases/impactdb.v1.2.dg_filled.db](releases/impactdb.v1.2.dg_filled.db) **Inflation to 2024 USD version** | A **post-processed** database that improves on [releases/impactdb.v1.1.dg_filled.db](releases/impactdb.v1.1.dg_filled.db) by removing events that have no L1/L2/L3 impacts (ie. all impact data in L1 is NULL), most currencies are converted to USD in the database and inflated to 2024 value. |
| [releases/impactdb.v1.3.dg_filled.db](releases/impactdb.v1.3.dg_filled.db) **Inflation to 2024 EUR version** | A **post-processed** database that convert 2024 USD to 2024 EUR on [releases/impactdb.v1.2.dg_filled.db](releases/impactdb.v1.1.dg_filled.db) by using a constant conversion rate in 2024 |

### Additional files and metadata
| File | Description |
Expand Down

0 comments on commit 54d9c63

Please sign in to comment.