Skip to content
Open
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
49 changes: 33 additions & 16 deletions scorecard/profile_data/indicators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ def get_muni_specifics(cls, api_data):
items = v1_data[year]

results = {
"local": {"amount": 0, },
"government": {"amount": 0, },
"local": {
"amount": 0,
},
"government": {
"amount": 0,
},
"year": year,
"ref": api_data.references["lges"],
}
Expand Down Expand Up @@ -194,7 +198,11 @@ def get_muni_specifics(cls, api_data):
contracting_code = "4200"

total = sum(x["amount.sum"] for x in results)
contracting_items = [x["amount.sum"] for x in results if x["item.code"] == contracting_code]
contracting_items = [
x["amount.sum"]
for x in results
if x["item.code"] == contracting_code
]
contracting = percent(contracting_items[0], total)
# Prefer KeyError but crash before we use it in case we have more than expectexd
assert len(contracting_items) <= 1
Expand All @@ -203,7 +211,11 @@ def get_muni_specifics(cls, api_data):
contracting = None

values.append(
{"date": year, "result": contracting, "rating": "", }
{
"date": year,
"result": contracting,
"rating": "",
}
)

return {
Expand Down Expand Up @@ -246,7 +258,11 @@ def get_muni_specifics(cls, api_data):
staff = None

values.append(
{"date": year, "result": staff, "rating": "", }
{
"date": year,
"result": staff,
"rating": "",
}
)

return {
Expand All @@ -269,7 +285,8 @@ def get_muni_specifics(cls, api_data):
}
GAPD_label = "Governance, Administration, Planning and Development"

results = api_data.results["expenditure_functional_breakdown_v2"]
results = api_data.results["expenditure_functional_breakdown"]
results.extend(api_data.results["expenditure_functional_breakdown_v2"])
grouped_results = []
GAPD_total = 0.0
GAPD_values = []
Expand Down Expand Up @@ -302,17 +319,17 @@ def get_muni_specifics(cls, api_data):
}
)

grouped_results.append(
{
"amount": GAPD_total,
"percent": percent(GAPD_total, total),
"item": GAPD_label,
"date": year_name,
}
)
if GAPD_total > 0:
grouped_results.append(
{
"amount": GAPD_total,
"percent": percent(GAPD_total, total),
"item": GAPD_label,
"date": year_name,
}
)
except (KeyError, IndexError):
continue

grouped_results = sorted(
grouped_results, key=lambda r: (r["date"], r["item"]))
grouped_results = sorted(grouped_results, key=lambda r: (r["date"], r["item"]))
return {"values": grouped_results}
Loading