def child_care_dashboard(): cc_fields = datapoints.child_care fields = [cc_fields[1], cc_fields[3], cc_fields[5], cc_fields[6]] values = [] for f in fields: point = get_field(ChildCare, f).strip() value = float(ChildCare.objects.filter(fhsis__date__year=year_now).aggregate(sum=Sum(point))['sum'] or 0) values.append(value) tb = datapoints.tuberculosis[0] malaria = datapoints.malaria[0] malaria_point = get_field(Malaria, malaria).strip() value = float(Malaria.objects.filter(fhsis__date__year=year_now).aggregate(sum=Sum(malaria_point))['sum']) values.append(value) fields.append(malaria) tb_point = get_field(Tuberculosis, tb).strip() value = float(Tuberculosis.objects.filter(fhsis__date__year=year_now).aggregate(sum=Sum(tb_point))['sum']) values.append(value) fields.append(tb) return { 'fields': fields, 'values': values }
def maternal_dashboard(view): maternal_fields = datapoints.maternal fields = [maternal_fields[0], maternal_fields[2]] # for view if view is not None: values = [] for f in fields: point = get_field(MaternalCare, f).strip() value = float( MaternalCare.objects.filter( fhsis__date__year=year_now).aggregate( sum=Sum(point))['sum'] or 0) values.append({f: value}) return values values = [] for f in fields: point = get_field(MaternalCare, f).strip() value = float( MaternalCare.objects.filter(fhsis__date__year=year_now).aggregate( sum=Sum(point))['sum'] or 0) values.append(value) return {'fields': fields, 'values': values}
def given_totals(): data = [] for vitamin in datapoints.micronutrient: field = get_field(ChildCare, vitamin) total = ChildCare.objects.filter(fhsis__date__year=year_now).aggregate(sum=Sum(field))['sum'] data.append(int(total)) return data
def get_data_child_care_year(fields, model, year): barangays = Barangay.objects.all().order_by('name') data = [] for b in barangays: sub_data = [b.name] for f in fields: point = get_field(model, f) total = model.objects.filter(fhsis__date__year=year, fhsis__barangay=b).aggregate(sum=Sum(point))['sum'] sub_data.append(int(total)) data.append(sub_data) return data
def micro_per_barangay_year(year): data = [] for b in Barangay.objects.all().order_by('name'): sub_data = [b.name] for vitamin in datapoints.micronutrient: field = get_field(ChildCare, vitamin) total = ChildCare.objects.filter(fhsis__date__year=year, fhsis__barangay=b).aggregate(sum=Sum(field))['sum'] sub_data.append(int(total)) data.append(sub_data) return data
def maternal_report_per_year(year): barangays = Barangay.objects.all().order_by('name') data = [] for b in barangays: sub_data = [b.name] for f in datapoints.maternal: field = get_field(MaternalCare, f) total = MaternalCare.objects.filter( fhsis__date__year=year, fhsis__barangay=b).aggregate(sum=Sum(field))['sum'] sub_data.append(int(total)) data.append(sub_data) return data
def highest(order): main_data = [] for vitamin in datapoints.micronutrient: field = get_field(ChildCare, vitamin) data = {} for b in Barangay.objects.all(): total = ChildCare.objects.filter(fhsis__date__year=year_now, fhsis__barangay=b).aggregate(sum=Sum(field))['sum'] data[b.name] = int(total) maximum = max(data, key=data.get) minimum = min(data, key=data.get) if order == 0: main_data.append((maximum, data[maximum])) else: main_data.append((minimum, data[minimum])) return main_data
def top3_barangays(order): barangays = Barangay.objects.all() data = [] for b in barangays: sub_data = {'barangay': b.name} values = {} total_vitamin = 0 for vitamin in datapoints.micronutrient: field = get_field(ChildCare, vitamin) sub_total = ChildCare.objects.filter(fhsis__date__year=year_now, fhsis__barangay=b).aggregate( sum=Sum(field) )['sum'] values[vitamin] = int(sub_total) total_vitamin += int(sub_total) sub_data['values'] = values sub_data['total'] = total_vitamin data.append(sub_data) if order == 0: new_list = sorted(data, key=operator.itemgetter('total'))[:3] else: new_list = sorted(data, key=operator.itemgetter('total'), reverse=True)[:3] bars = [b['barangay'] for b in new_list] vit_a = [b['values'][list(b['values'].keys())[0]] for b in new_list] iron = [b['values'][list(b['values'].keys())[1]] for b in new_list] mnp = [b['values'][list(b['values'].keys())[2]] for b in new_list] return { 'barangays': bars, 'vitaminA': vit_a, 'iron': iron, 'mnp': mnp }
def get_value_until_present(source, field): point = field # hard coded if point == revised_datapoints.SOCIOECONOMIC[0]: point = 'Well' elif point == revised_datapoints.SOCIOECONOMIC[1]: point = 'Open Pit' elif point == revised_datapoints.SOCIOECONOMIC[2]: point = 'None' elif point == revised_datapoints.SOCIOECONOMIC[3]: point = 'Elementary Undergraduate' elif point == revised_datapoints.SOCIOECONOMIC[4]: point = 'Number of families practicing family planning' elif point == revised_datapoints.SOCIOECONOMIC[5]: point = 'Number of families using iodized salt' if source == 'Family Profile': if point in datapoints.water_sources: start_year = [ d.year for d in FamilyProfileLine.objects.dates( 'family_profile__date', 'year') ][0] data = {} while start_year <= weights.year_now: count = FamilyProfileLine.objects.filter( family_profile__date__year=start_year, water_sources=point).count() data[start_year] = count start_year = start_year + 1 return json.dumps(data) if point in datapoints.food_production: start_year = [ d.year for d in FamilyProfileLine.objects.dates( 'family_profile__date', 'year') ][0] data = {} while start_year <= weights.year_now: count = FamilyProfileLine.objects.filter( family_profile__date__year=start_year, food_production_activity=point).count() data[start_year] = count start_year = start_year + 1 return json.dumps(data) if point in datapoints.educational_attainment_for_r: start_year = [ d.year for d in FamilyProfileLine.objects.dates( 'family_profile__date', 'year') ][0] data = {} while start_year <= weights.year_now: count = FamilyProfileLine.objects.filter( family_profile__date__year=start_year, educational_attainment=point).count() data[start_year] = count start_year = start_year + 1 return json.dumps(data) if point in datapoints.toilet_type: start_year = [ d.year for d in FamilyProfileLine.objects.dates( 'family_profile__date', 'year') ][0] data = {} while start_year <= weights.year_now: count = FamilyProfileLine.objects.filter( family_profile__date__year=start_year, toilet_type=point).count() data[start_year] = count start_year = start_year + 1 return json.dumps(data) field = consolidators.get_field(FamilyProfileLine, point) start_year = [ d.year for d in FamilyProfileLine.objects.dates( 'family_profile__date', 'year') ][0] data = {} while start_year <= weights.year_now: count = 0 for f in FamilyProfileLine.objects.filter( family_profile__date__year=start_year): if getattr(f, field): count = count + 1 data[start_year] = count start_year = start_year + 1 return json.dumps(data) elif source == 'Maternal Care': field = consolidators.get_field(MaternalCare, point) start_year = [ d.year for d in MaternalCare.objects.all().dates('fhsis__date', 'year') ][0] data = {} while start_year <= weights.year_now: data[start_year] = float( MaternalCare.objects.filter( fhsis__date__year=start_year).aggregate( sum=Sum(field))['sum']) start_year += 1 return json.dumps(data) elif source == 'Child Care': field = consolidators.get_field(ChildCare, point) start_year = [ d.year for d in ChildCare.objects.all().dates('fhsis__date', 'year') ][0] data = {} while start_year <= weights.year_now: data[start_year] = float( ChildCare.objects.filter( fhsis__date__year=start_year).aggregate( sum=Sum(field))['sum']) start_year += 1 return json.dumps(data) elif source == 'Malaria': field = consolidators.get_field(Malaria, point) start_year = [ d.year for d in Malaria.objects.all().dates('fhsis__date', 'year') ][0] data = {} while start_year <= weights.year_now: data[start_year] = float( Malaria.objects.filter(fhsis__date__year=start_year).aggregate( sum=Sum(field))['sum']) start_year += 1 return json.dumps(data) elif source == 'Immunization': field = consolidators.get_field(Immunization, point) start_year = [ d.year for d in Immunization.objects.all().dates('fhsis__date', 'year') ][0] data = {} while start_year <= weights.year_now: data[start_year] = float( Immunization.objects.filter( fhsis__date__year=start_year).aggregate( sum=Sum(field))['sum']) start_year += 1 return json.dumps(data) elif source == 'Tuberculosis': field = consolidators.get_field(Tuberculosis, point) start_year = [ d.year for d in Tuberculosis.objects.all().dates('fhsis__date', 'year') ][0] data = {} while start_year <= weights.year_now: data[start_year] = float( Tuberculosis.objects.filter( fhsis__date__year=start_year).aggregate( sum=Sum(field))['sum']) start_year += 1 return json.dumps(data) return "Wow"
def get_distribution_per_barangay(source, data_point): if source == 'Family Profile': query = FamilyProfileLine.objects.filter( family_profile__date__year=year_now) if data_point == 'Number of families using a Well as water source': data = [] for barangay in Barangay.objects.all(): total = query.filter(family_profile__barangay=barangay).filter( water_sources='Well').count() data.append([barangay.name, int(total)]) return data if data_point == 'Number of families using an Open Pit toilet type': data = [] for barangay in Barangay.objects.all(): total = query.filter(family_profile__barangay=barangay).filter( toilet_type='Open Pit').count() data.append([barangay.name, int(total)]) return data if data_point == 'Number of families who do not have toilets': data = [] for barangay in Barangay.objects.all(): total = query.filter(family_profile__barangay=barangay).filter( toilet_type='None').count() data.append([barangay.name, int(total)]) return data if data_point == 'Number of Elementary Undergraduate Parents': data = [] for barangay in Barangay.objects.all(): total = query.filter(family_profile__barangay=barangay).filter( educational_attainment='Elementary Undergraduate').count() data.append([barangay.name, int(total)]) return data if data_point == 'Number of families using iodized salt': data = [] for barangay in Barangay.objects.all(): total = query.filter(family_profile__barangay=barangay).filter( is_using_iodized_salt=True).count() data.append([barangay.name, int(total)]) return data if data_point == 'Number of families practicing Family Planning': data = [] for barangay in Barangay.objects.all(): total = query.filter(family_profile__barangay=barangay).filter( is_family_planning=True).count() data.append([barangay.name, int(total)]) return data trimmed = source.replace(' ', '') model = apps.get_model('datainput', trimmed) field = get_field(model, data_point) query = model.objects.all().filter(fhsis__date__year=year_now) data = [] for barangay in Barangay.objects.all(): total = query.filter(fhsis__barangay=barangay).aggregate( sum=Sum(field))['sum'] data.append([barangay.name, int(total)]) return data
def get_value(field): if field not in revised_datapoints.SOCIOECONOMIC: # filter the fields if field == 'Number of Tuberculosis Identified': model = Tuberculosis elif field == 'Number of Malaria Cases': model = Malaria elif field in revised_datapoints.MATERNAL: model = MaternalCare elif field in datapoints.immunizations: model = Immunization elif field in revised_datapoints.INFORMAL: model = InformalSettlers # compute informal settlers a = InformalSettlers.objects.dates('date', 'year') year_start = a[0].year values = {} while year_start < year_now: total = InformalSettlers.objects.filter( date__year=year_start).aggregate( sum=Sum('families_count'))['sum'] values[year_start] = int(total) year_start += 1 return values, model.__name__ else: model = ChildCare model_field = get_field(model, field) return get_fhsis(model, model_field, None), model.__name__ else: # SOCIOECONOMIC years = FamilyProfile.objects.dates('date', 'year') start_year = sorted(years)[0].year query = FamilyProfileLine.objects.all() if field == revised_datapoints.SOCIOECONOMIC[0]: # water source well values = {} while start_year < year_now: total = query.filter( family_profile__date__year=start_year).filter( water_sources__contains='Well').count() values[start_year] = int(total) start_year += 1 # return values elif field == revised_datapoints.SOCIOECONOMIC[1]: # open pit values = {} while start_year < year_now: total = query.filter( family_profile__date__year=start_year).filter( toilet_type__contains='Open Pit').count() values[start_year] = int(total) start_year += 1 # return values elif field == revised_datapoints.SOCIOECONOMIC[2]: # no toilet values = {} while start_year < year_now: total = query.filter( family_profile__date__year=start_year).filter( toilet_type__contains='None').count() values[start_year] = int(total) start_year += 1 # return values elif field == revised_datapoints.SOCIOECONOMIC[ 3]: # undergraduate parents values = {} while start_year < year_now: total = query.filter( family_profile__date__year=start_year ).filter( educational_attainment__contains='Elementary Undergraduate' ).count() values[start_year] = int(total) start_year += 1 # return values elif field == revised_datapoints.SOCIOECONOMIC[ 4]: # practicing family planning values = {} while start_year < year_now: total = query.filter( family_profile__date__year=start_year).filter( is_family_planning=True).count() values[start_year] = int(total) start_year += 1 # return values elif field == revised_datapoints.SOCIOECONOMIC[5]: # iodized salt values = {} while start_year < year_now: total = query.filter( family_profile__date__year=start_year).filter( is_using_iodized_salt=True).count() values[start_year] = int(total) start_year += 1 # return values return values, 'Family Profile'