def rows(self): rows = [] if self.config['location_id']: locations = SQLLocation.objects.filter(parent__location_id=self.config['location_id']) for loc in locations: total_responses = 0 total_possible = 0 for g in GroupSummary.objects.filter(org_summary__date__lte=datetime(int(self.config['year']), int(self.config['month']), 1), org_summary__supply_point=loc.location_id, title=SupplyPointStatusTypes.SUPERVISION_FACILITY): if g: total_responses += g.responded total_possible += g.total if total_possible: response_rate = "%.1f%%" % (100.0 * total_responses / total_possible) else: response_rate = "<span class='no_data'>None</span>" url = make_url(FacilityDetailsReport, self.config['domain'], '?location_id=%s&filter_by_program=%s%s', (loc.location_id, self.config['program'], self.config['prd_part_url'])) latest = latest_status_or_none(loc.location_id, SupplyPointStatusTypes.SUPERVISION_FACILITY, int(self.config['month']), int(self.config['year'])) rows.append([ loc.site_code, link_format(loc.name, url), latest.name if latest else None, latest.status_date if latest else None, response_rate ]) return rows
def rows(self): rows = [] locations = SQLLocation.objects.filter(parent__location_id=self.config['location_id']) dg = [] for date in list(rrule.rrule(rrule.MONTHLY, dtstart=self.config['startdate'], until=self.config['enddate'])): dg.extend(DeliveryGroups().delivering(locations, date.month)) for child in dg: group_summary = GroupSummary.objects.filter( org_summary__date__lte=self.config['startdate'], org_summary__location_id=child.location_id, title=SupplyPointStatusTypes.DELIVERY_FACILITY, total=1 ).exists() if not group_summary: continue latest = latest_status_or_none( child.location_id, SupplyPointStatusTypes.DELIVERY_FACILITY, self.config['startdate'], self.config['enddate'] ) status_name = latest.name if latest else "" status_date = latest.status_date.strftime("%d-%m-%Y") if latest else "None" url = make_url(FacilityDetailsReport, self.config['domain'], '?location_id=%s&filter_by_program=%s&' 'datespan_type=%s&datespan_first=%s&datespan_second=%s', (child.location_id, self.config['program'], self.config['datespan_type'], self.config['datespan_first'], self.config['datespan_second'])) cycle_lead_time = get_this_lead_time( child.location_id, self.config['startdate'], self.config['enddate'] ) avg_lead_time = get_avg_lead_time(child.location_id, self.config['startdate'], self.config['enddate']) rows.append( [ child.site_code, link_format(child.name, url), status_name, status_date, cycle_lead_time, avg_lead_time ] ) return rows
def rows(self): rows = [] if self.config['location_id']: locations = SQLLocation.active_objects.filter( parent__location_id=self.config['location_id']) for loc in locations: total_responses = 0 total_possible = 0 group_summaries = GroupSummary.objects.filter( org_summary__date__lte=self.config['startdate'], org_summary__location_id=loc.location_id, title=SupplyPointStatusTypes.SUPERVISION_FACILITY, total=1) if not group_summaries: continue for group_summary in group_summaries: if group_summary: total_responses += group_summary.responded total_possible += group_summary.total if total_possible: response_rate = "%.1f%%" % (100.0 * total_responses / total_possible) else: response_rate = "<span class='no_data'>None</span>" url = make_url( FacilityDetailsReport, self.config['domain'], '?location_id=%s&filter_by_program=%s&' 'datespan_type=%s&datespan_first=%s&datespan_second=%s', (loc.location_id, self.config['program'], self.config['datespan_type'], self.config['datespan_first'], self.config['datespan_second'])) latest = latest_status_or_none( loc.location_id, SupplyPointStatusTypes.SUPERVISION_FACILITY, self.config['startdate'], self.config['enddate']) rows.append([ loc.site_code, link_format(loc.name, url), latest.name if latest else None, latest.status_date.strftime('%b. %d, %Y') if latest else '', response_rate ]) return rows
def rows(self): rows = [] if self.config['location_id']: locations = SQLLocation.objects.filter(parent__location_id=self.config['location_id']) for loc in locations: total_responses = 0 total_possible = 0 group_summaries = GroupSummary.objects.filter( org_summary__date__lte=self.config['startdate'], org_summary__location_id=loc.location_id, title=SupplyPointStatusTypes.SUPERVISION_FACILITY, total=1 ) if not group_summaries: continue for group_summary in group_summaries: if group_summary: total_responses += group_summary.responded total_possible += group_summary.total if total_possible: response_rate = "%.1f%%" % (100.0 * total_responses / total_possible) else: response_rate = "<span class='no_data'>None</span>" url = make_url(FacilityDetailsReport, self.config['domain'], '?location_id=%s&filter_by_program=%s&' 'datespan_type=%s&datespan_first=%s&datespan_second=%s', (loc.location_id, self.config['program'], self.config['datespan_type'], self.config['datespan_first'], self.config['datespan_second'])) latest = latest_status_or_none(loc.location_id, SupplyPointStatusTypes.SUPERVISION_FACILITY, self.config['startdate'], self.config['enddate']) rows.append([ loc.site_code, link_format(loc.name, url), latest.name if latest else None, latest.status_date.strftime('%b. %d, %Y') if latest else '', response_rate ]) return rows