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

Get government function data from V2 cube for expediture breakdown #680

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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