Skip to content

Commit

Permalink
Merge pull request agoenergy#206 from agoenergy/203-hyperlinks-to-ref…
Browse files Browse the repository at this point in the history
…erences

insert clickable markdown links for references in context data
  • Loading branch information
markushal authored Dec 14, 2023
2 parents da2eb7a + 1ff0a4e commit 3f4dfdd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
28 changes: 27 additions & 1 deletion app/context_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,30 @@ def load_context_data():
)
cd["literature"] = pd.read_excel(filename, sheet_name="literature")

return cd
return _insert_clickable_references(cd)


def _insert_clickable_references(context_data):
"""Insert clickable markdown references into the context data text fields."""
literature = context_data["literature"]
literature["markdown_link"] = (
"[" + literature["short_name"] + "](" + literature["url"] + ")"
)
links = literature.set_index("short_name")["markdown_link"].to_dict()

cd_new = {}
cd_new["literature"] = context_data["literature"]
for sheet in [
"demand_countries",
"certification_schemes",
"sustainability",
"supply",
]:
for ref, link in links.items():
df = context_data[sheet]
for col in df.columns:
df[col] = df[col].astype("string").str.replace(ref, link)

cd_new[sheet] = df

return cd_new
14 changes: 8 additions & 6 deletions app/tab_country_fact_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ def _create_fact_sheet_supply_country(context_data: dict, api: PtxboaAPI):

st.subheader(f"{flag} Fact sheet for {region_name}")
with st.expander("**Technical potential for renewable electricity generation**"):
if isinstance(data["re_tech_pot_EWI"], (int, float)):
re_tech_pot_EWI = f"{data['re_tech_pot_EWI']:.0f} TWh/a"
else:
try:
val = float(data["re_tech_pot_EWI"])
re_tech_pot_EWI = f"{val:.0f} TWh/a"
except ValueError:
re_tech_pot_EWI = data["re_tech_pot_EWI"]

if isinstance(data["re_tech_pot_PTXAtlas"], (int, float)):
re_tech_pot_PTXAtlas = f"{data['re_tech_pot_PTXAtlas']:.0f} TWh/a"
else:
try:
val = float(data["re_tech_pot_PTXAtlas"])
re_tech_pot_PTXAtlas = f"{val:.0f} TWh/a"
except ValueError:
re_tech_pot_PTXAtlas = data["re_tech_pot_PTXAtlas"]

text = (
Expand Down

0 comments on commit 3f4dfdd

Please sign in to comment.