Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eur db release #198

Merged
merged 7 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Database/EUR_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@
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.USD_to_EUR(x, l1_impact=cat, level="l1", impact=cat), axis=1)
l1 = l1.apply(
lambda x: cc_utils.Lasted_Year_USD_Inflated_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.USD_to_EUR(x, l1_impact=None, level="l2", impact=cat), axis=1)
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
)
logger.info(f"Converting currencies in L3 for category {cat}")
l3[cat] = l3[cat].apply(lambda x: cc_utils.USD_to_EUR(x, l1_impact=None, level="l3", impact=cat), axis=1)
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
)

logger.info(f"Storing results in {args.output_dir}")
pathlib.Path(args.output_dir).mkdir(parents=True, exist_ok=True)
Expand Down
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
21 changes: 15 additions & 6 deletions Database/scr/normalize_currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ def convert_to_USD_yearly_avg(
)
return amount

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

# always use the current year of EUR-USD conversion rate
rate = 0.919600999999999
# always use the lastest year of EUR-USD conversion rate
# extract rate
rate = (
self.currency_conversion_yearly_avg[self.eur]
.loc[self.currency_conversion_yearly_avg[self.eur].Year == year]
i-be-snek marked this conversation as resolved.
Show resolved Hide resolved
.Rate.tolist()[0]
)
return round(amount * rate)

except BaseException as err:
self.logger.debug(
f"{event_id} - {level} - {impact}: Could not convert to EUR (yearly average) for year '{year}', currency '{currency}' and amount '{amount}'. Error: {err}"
Expand Down Expand Up @@ -344,7 +351,9 @@ 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 USD_to_EUR(self, row: pd.DataFrame, l1_impact: None | str, level: str, impact: str) -> pd.DataFrame:
def Lasted_Year_USD_Inflated_to_EUR(
i-be-snek marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -373,10 +382,10 @@ def USD_to_EUR(self, row: pd.DataFrame, l1_impact: None | str, level: str, impac

if year:
if row[num_unit] == self.usd:
row[num_min] = self.convert_to_EUR_yearly_avg(
row[num_min] = self.convert_USD_to_EUR_latest_year_avg(
i-be-snek marked this conversation as resolved.
Show resolved Hide resolved
row[num_unit], row[num_min], year=year, event_id=row[self.event_id], level=level, impact=impact
)
row[num_max] = self.convert_to_EUR_yearly_avg(
row[num_max] = self.convert_USD_to_EUR_latest_year_avg(
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
Loading
Loading