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

[BugFix] Econdb JSON loads context #6512

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
67 changes: 47 additions & 20 deletions openbb_platform/providers/econdb/openbb_econdb/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,24 @@
"southeast_asia": ["KH", "ID", "LA", "MY", "PH", "SG", "TH", "VN"],
}

INDICATORS_DESCRIPTIONS = json.load(
(files("openbb_econdb.utils") / "indicators_descriptions.json").open()
)
MULTIPLIERS = json.load((files("openbb_econdb.utils") / "multipliers.json").open())
SCALES = json.load((files("openbb_econdb.utils") / "scales.json").open())
UNITS = json.load((files("openbb_econdb.utils") / "units.json").open())
INDICATOR_COUNTRIES = json.load(
(files("openbb_econdb.utils") / "indicator_countries.json").open()
)
SYMBOL_TO_INDICATOR = json.load(
(files("openbb_econdb.utils") / "symbol_to_indicator.json").open()
)
with (files("openbb_econdb.utils") / "indicators_descriptions.json").open() as f:
INDICATORS_DESCRIPTIONS = json.load(f)

with (files("openbb_econdb.utils") / "multipliers.json").open() as f:
MULTIPLIERS = json.load(f)

with (files("openbb_econdb.utils") / "scales.json").open() as f:
SCALES = json.load(f)

with (files("openbb_econdb.utils") / "units.json").open() as f:
UNITS = json.load(f)

with (files("openbb_econdb.utils") / "symbol_to_indicator.json").open() as f:
SYMBOL_TO_INDICATOR = json.load(f)

with (files("openbb_econdb.utils") / "indicator_countries.json").open() as f:
INDICATOR_COUNTRIES = json.load(f)

HAS_COUNTRIES = {
d: INDICATOR_COUNTRIES.get(d) != ["W00"] for d in INDICATORS_DESCRIPTIONS
}
Expand Down Expand Up @@ -622,28 +628,44 @@ def update_symbol_to_indicator() -> None:
"w", # type: ignore
encoding="utf-8",
) as f:
indicators.set_index("short_ticker").sort_index()["symbol_root"].to_json(f)
json_data = json.dumps(
indicators.set_index("short_ticker")
.sort_index()["symbol_root"]
.to_dict()
)
f.write(json_data)

def update_multipliers() -> None:
"""Update the unit multipliers."""
with open( # type: ignore
files("openbb_econdb.utils") / "multipliers.json", "w", encoding="utf-8"
) as f:
indicators.set_index("short_ticker").sort_index()["multiplier"].to_json(f)
json_data = json.dumps(
indicators.set_index("short_ticker")
.sort_index()["multiplier"]
.to_dict()
)
f.write(json_data)

def update_scales() -> None:
"""Update the scales."""
with open( # type: ignore
files("openbb_econdb.utils") / "scales.json", "w", encoding="utf-8"
) as f:
indicators.set_index("short_ticker").sort_index()["scale"].to_json(f)
json_data = json.dumps(
indicators.set_index("short_ticker").sort_index()["scale"].to_dict()
)
f.write(json_data)

def update_units() -> None:
"""Update the units."""
with open( # type: ignore
files("openbb_econdb.utils") / "units.json", "w", encoding="utf-8"
) as f:
indicators.set_index("short_ticker").sort_index()["currency"].to_json(f)
json_data = json.dumps(
indicators.set_index("short_ticker").sort_index()["currency"].to_dict()
)
f.write(json_data)

def update_descriptions() -> None:
"""Update the indicator descriptions."""
Expand All @@ -656,7 +678,8 @@ def update_descriptions() -> None:
"w",
encoding="utf-8",
) as f:
json.dump(descriptions_dict, f)
json_data = json.dumps(descriptions_dict)
f.write(json_data)

def update_indicator_countries() -> None:
"""Update the indicator countries."""
Expand All @@ -665,9 +688,13 @@ def update_indicator_countries() -> None:
"w",
encoding="utf-8",
) as f:
indicators[indicators["symbol_root"] != "[W00]"].groupby("symbol_root")[
"iso"
].apply(lambda x: x.sort_values().unique().tolist()).to_json(f)
json_data = json.dumps(
indicators[indicators["symbol_root"] != "[W00]"]
.groupby("symbol_root")["iso"]
.apply(lambda x: x.sort_values().unique().tolist())
.to_dict()
)
f.write(json_data)

update_symbol_to_indicator()
update_multipliers()
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading