agg narative country list
This commit is contained in:
@@ -216,27 +216,42 @@ def _build_overview_narrative(
|
|||||||
f"no prior-year data is available for year-over-year comparison."
|
f"no prior-year data is available for year-over-year comparison."
|
||||||
)
|
)
|
||||||
|
|
||||||
# -- Sentence 3: country ranking ----------------------------------------
|
# -- Sentence 3: country ranking ----------------------------
|
||||||
sent3 = ""
|
sent3 = ""
|
||||||
if ranking_list:
|
if ranking_list:
|
||||||
top3 = ranking_list[:3]
|
first = ranking_list[0]
|
||||||
last = ranking_list[-1]
|
last = ranking_list[-1]
|
||||||
if len(top3) >= 3:
|
middle = ranking_list[1:-1]
|
||||||
after_first = (
|
|
||||||
f"{top3[1]['country_name']} ({_fmt_score(top3[1]['score'])}) and "
|
|
||||||
f"{top3[2]['country_name']} ({_fmt_score(top3[2]['score'])})."
|
|
||||||
)
|
|
||||||
elif len(top3) == 2:
|
|
||||||
after_first = f"{top3[1]['country_name']} ({_fmt_score(top3[1]['score'])})."
|
|
||||||
else:
|
|
||||||
after_first = "."
|
|
||||||
|
|
||||||
sent3 = (
|
if len(ranking_list) == 1:
|
||||||
f"In terms of country performance, {top3[0]['country_name']} led the region "
|
sent3 = (
|
||||||
f"with a score of {_fmt_score(top3[0]['score'])}, followed by {after_first} "
|
f"In terms of country performance, {first['country_name']} was the only "
|
||||||
f"At the other end, {last['country_name']} recorded the lowest score "
|
f"country assessed, scoring {_fmt_score(first['score'])} in {year}."
|
||||||
f"of {_fmt_score(last['score'])} in {year}."
|
)
|
||||||
)
|
elif len(ranking_list) == 2:
|
||||||
|
sent3 = (
|
||||||
|
f"In terms of country performance, {first['country_name']} led the region "
|
||||||
|
f"with a score of {_fmt_score(first['score'])}, while "
|
||||||
|
f"{last['country_name']} recorded the lowest score of "
|
||||||
|
f"{_fmt_score(last['score'])} in {year}."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Susun semua negara di tengah: "B (xx.xx), C (xx.xx), ..., and Y (xx.xx)"
|
||||||
|
middle_parts = [
|
||||||
|
f"{c['country_name']} ({_fmt_score(c['score'])})"
|
||||||
|
for c in middle
|
||||||
|
]
|
||||||
|
if len(middle_parts) == 1:
|
||||||
|
middle_str = middle_parts[0]
|
||||||
|
else:
|
||||||
|
middle_str = ", ".join(middle_parts[:-1]) + f", and {middle_parts[-1]}"
|
||||||
|
|
||||||
|
sent3 = (
|
||||||
|
f"In terms of country performance, {first['country_name']} led the region "
|
||||||
|
f"with a score of {_fmt_score(first['score'])}, followed by {middle_str}. "
|
||||||
|
f"At the other end, {last['country_name']} recorded the lowest score "
|
||||||
|
f"of {_fmt_score(last['score'])} in {year}."
|
||||||
|
)
|
||||||
|
|
||||||
# -- Sentence 4: most improved / declined ------------------------------
|
# -- Sentence 4: most improved / declined ------------------------------
|
||||||
sent4_parts = []
|
sent4_parts = []
|
||||||
|
|||||||
Reference in New Issue
Block a user