def get_country_indicators(country, questions, agencies_data): indicator_data = calc_country_indicators(country) indicators = {} for indicator in indicator_data: ind = indicators[indicator] = {} data = indicator_data[indicator][0] ind["baseline_value"] = none_num(data[0]) ind["baseline_year"] = data[1] ind["latest_value"] = none_num(data[2]) ind["latest_year"] = data[3] if indicators["3G"]["latest_value"] != NA_STR: indicators["3G"]["hs_budget_gap"] = 15 - indicators["3G"]["latest_value"] else: indicators["3G"]["hs_budget_gap"] = None indicators["other"] = {} other_indicators = indicators["other"] baseline_denom = questions["18"]["baseline_value"] / 10000.0 latest_denom = questions["18"]["latest_value"] / 10000.0 # Outpatient Visits other_indicators["outpatient_visits_baseline"] = questions["19"]["baseline_value"] / baseline_denom other_indicators["outpatient_visits_latest"] = questions["19"]["latest_value"] / latest_denom other_indicators["outpatient_visits_change"], other_indicators["outpatient_visits_change_dir"] = calc_change(other_indicators["outpatient_visits_latest"], other_indicators["outpatient_visits_baseline"]) # Skilled Personnel other_indicators["skilled_personnel_baseline"] = questions["17"]["baseline_value"] / baseline_denom other_indicators["skilled_personnel_latest"] = questions["17"]["latest_value"] / latest_denom other_indicators["skilled_personnel_change"], other_indicators["skilled_personnel_change_dir"] = calc_change(other_indicators["skilled_personnel_latest"], other_indicators["skilled_personnel_baseline"]) # Health Workforce other_indicators["health_workforce_perc_of_budget_baseline"] = questions["20"]["baseline_value"] / questions["7"]["baseline_value"] other_indicators["health_workforce_perc_of_budget_latest"] = questions["20"]["latest_value"] / questions["7"]["latest_value"] other_indicators["health_workforce_spent_change"], other_indicators["health_workforce_spent_change_dir"] = calc_change(questions["20"]["latest_value"], questions["20"]["baseline_value"]) other_indicators["pfm_diff"] = questions["9"]["latest_value"] - questions["9"]["baseline_value"] def sum_agency_values(question_number, field): sum = 0 for agency in agencies_data: if question_number in agencies_data[agency]: try: sum += float(agencies_data[agency][question_number][field]) except ValueError: pass return sum coordinated_programmes = sum_agency_values("5", "latest_value") - sum_agency_values("4", "latest_value") if coordinated_programmes > 0.51: other_indicators["coordinated_programmes"] = models.Rating.TICK elif coordinated_programmes >= 0.11: other_indicators["coordinated_programmes"] = models.Rating.ARROW else: other_indicators["coordinated_programmes"] = models.Rating.CROSS return indicators
def get_country_questions(country): questions = {} for question in models.GovQuestion.objects.filter(submission__country=country): qvals = questions[question.question_number] = {} qvals["baseline_year"] = question.baseline_year qvals["latest_year"] = question.latest_year qvals["comments"] = question.comments qvals["baseline_value"] = none_num(question.base_val) qvals["latest_value"] = none_num(question.cur_val) return questions