def get_context_data(self, **kwargs): context = super(DistrictMap, self).get_context_data(**kwargs) druid_result = get_druid_data( dimensions=[ 'target_area_id', 'target_area_name', 'target_area_structures', 'rhc_name', 'district_name', 'rhc_id', 'district_id' ], filter_list=[['district_id', operator.eq, self.object.pk]]) data, totals = process_druid_data(druid_result) district_druid_data = process_location_data(self.object.__dict__, data) district_data = AreaSerializer(self.object, druid_data=district_druid_data).data rhc_druid_data_list = [] rhc_list = Location.objects.filter(level='RHC', parent=self.object) for rhc in rhc_list: rhc_druid_data = [x for x in data if x['rhc_id'] == str(rhc.id)] rhc_data = process_location_data(rhc.__dict__, rhc_druid_data) rhc_data['rhc_id'] = rhc.id rhc_druid_data_list.append(rhc_data) rhc_geojson_data = AreaSerializer(rhc_list, druid_data=rhc_druid_data_list, many=True).data context['district_data'] = JSONRenderer().render(district_data) context['hh_geojson'] = JSONRenderer().render(rhc_geojson_data) return context
def get_context_data(self, **kwargs): context = super(RHCMap, self).get_context_data(**kwargs) druid_result = get_druid_data( filter_list=[['rhc_id', operator.eq, self.object.pk]]) data, totals = process_druid_data(druid_result) rhc_druid_data = process_location_data(self.object.__dict__, data) rhc_data = AreaSerializer(self.object, druid_data=rhc_druid_data).data ta_data = TargetAreaSerializer( self.object.get_children().filter(level='ta'), druid_data=data, many=True).data context['rhc_data'] = JSONRenderer().render(rhc_data) context['hh_geojson'] = JSONRenderer().render(ta_data) return context
def get_context_data(self, **kwargs): context = super(DistrictView, self).get_context_data(**kwargs) context.update(DEFINITIONS['RHC']) druid_result = get_druid_data(dimensions=[ 'target_area_id', 'target_area_name', 'target_area_structures', 'rhc_name', 'district_name', 'rhc_id' ]) data, totals = process_druid_data(druid_result) object_list = Location.objects.filter(level='RHC', parent=self.object).values( 'id', 'name', 'structures', 'level') for rhc in object_list: rhc_data = [x for x in data if x['rhc_id'] == str(rhc['id'])] result = process_location_data(rhc, rhc_data) rhc.update(result) context['object_list'] = object_list return context
def get_context_data(self, **kwargs): context = super(Home, self).get_context_data(**kwargs) context.update(DEFINITIONS['district']) druid_result = get_druid_data(dimensions=[ 'target_area_id', 'target_area_name', 'target_area_structures', 'rhc_name', 'district_name', 'district_id' ]) data, totals = process_druid_data(druid_result) object_list = Location.objects.filter(level='district', parent=None).values( 'id', 'name', 'structures', 'level') for district in object_list: district_data = [ x for x in data if x['district_id'] == str(district['id']) ] result = process_location_data(district, district_data) district.update(result) context['object_list'] = object_list return context
def health_facility_catchment(spray_day_obj_id, force=False): """ Checks each submission for evidence that it represents data from a new RHC. If this is the case, then we send a summary of the 'previous RHC' """ try: spray_day_obj = SprayDay.objects.get(pk=spray_day_obj_id) except SprayDay.DoesNotExist: pass else: current_rhc = spray_day_obj.location.parent if current_rhc: should_continue = False if force: should_continue = True else: threshold = settings.HEALTH_FACILITY_CATCHMENT_THRESHOLD upper_threshold = threshold * 2 # count number of records for this RHC current_rhc_records = SprayDay.objects.filter( location__parent=current_rhc).count() if upper_threshold >= current_rhc_records >= threshold: should_continue = True if should_continue: # get previous RHC by looking for RHC with records from a # previous date previous_record = (SprayDay.objects.exclude( location__parent__id=current_rhc.id).filter( location__parent__parent__id=current_rhc.parent.id ).filter(spray_date__lt=spray_day_obj.spray_date).order_by( "-spray_date").first()) previous_rhc = None if previous_record: previous_rhc = previous_record.location.parent if previous_rhc: # get summary data and send to flow dimensions = [ "target_area_id", "target_area_name", "target_area_structures", "rhc_id", "rhc_name", "district_id", "district_name", ] druid_result = get_druid_data( dimensions, [["rhc_id", operator.eq, previous_rhc.id]]) data, _ = process_druid_data(druid_result) payload = process_location_data(previous_rhc.__dict__, data) payload["rhc_id"] = previous_rhc.id payload["rhc_name"] = previous_rhc.name payload["sprayed_coverage"] = int( payload["sprayed_coverage"]) payload["sprayed_percentage"] = int( payload["sprayed_percentage"]) payload["visited_percentage"] = int( payload["visited_percentage"]) if previous_rhc.parent: payload["district_id"] = previous_rhc.parent.id payload["district_name"] = previous_rhc.parent.name return start_flow(settings.RAPIDPRO_HF_CATCHMENT_FLOW_ID, payload) return None