class SupervisionTable(MonthTable): code = Column(value=lambda cell: cell.object.code, name="MSD Code", sort_key_fn=lambda obj: obj.code, titleized=False) name = Column(name="Facility Name", value=lambda cell: cell.object.name, sort_key_fn=lambda obj: obj.name, link=supply_point_link) supervision_this_quarter = Column( sortable=False, name="Supervision This Quarter", value=lambda cell: _latest_status_or_none( cell, SupplyPointStatusTypes.SUPERVISION_FACILITY, "name")) date = DateColumn( sortable=False, value=lambda cell: _latest_status_or_none( cell, SupplyPointStatusTypes.SUPERVISION_FACILITY, "status_date")) response_rate = Column( name="Historical Response Rate", safe=True, value=lambda cell: _hrr_super(cell.object), sort_key_fn=lambda sp: historical_response_rate( sp, SupplyPointStatusTypes.SUPERVISION_FACILITY)) class Meta: per_page = 9999 order_by = ["Facility Name"]
class StockOnHandTable(MonthTable): code = Column(value=lambda cell: cell.object.code, name="MSD Code", sort_key_fn=lambda obj: obj.code, titleized=False, css_class=_msd_class) name = Column(name="Facility Name", value=lambda cell: cell.object.name, sort_key_fn=lambda obj: obj.name, link=supply_point_link, css_class=_fac_name_class) delivery_group = Column(css_class=_dg_class, value=lambda cell: _dg(cell.object), sort_key_fn=_dg, name="D G") last_reported = Column( css_class=_ontime_class, value=lambda cell: last_report_span(cell.object, cell.row.table.year, cell.row.table.month, format=False)) response_rate = Column(name="Hist. Resp. Rate", safe=True, value=lambda cell: _hrr_soh(cell.object), sort_key_fn=lambda sp: historical_response_rate( sp, SupplyPointStatusTypes.SOH_FACILITY)) class Meta: per_page = 9999 order_by = ["D G", "Facility Name"]
class RandRReportingHistoryTable(MonthTable): code = Column() name = Column(name="Facility Name", value=lambda cell: cell.object.name, sort_key_fn=lambda obj: obj.name, link=supply_point_link) submitted = RandRSubmittedColumn(name="R&R Status", value=_randr_value, format="d M Y", css_class=_randr_css_class, sortable=False) contact = Column(name="Contact", value=lambda cell: _default_contact(cell.object), sort_key_fn=_default_contact) response_rate = Column(name="Historical Response Rate", safe=True, value=lambda cell: _hrr_randr(cell.object), sort_key_fn=lambda sp: historical_response_rate( sp, SupplyPointStatusTypes.R_AND_R_FACILITY)) @property def submitting_group(self): return DeliveryGroups(self.month).current_submitting_group() class Meta: per_page = 9999 order_by = ["Facility Name"]
def _response_rate(self, type=None): num = 0.0 denom = 0.0 for f in self.dg.submitting(self.facilities): hrr = historical_response_rate(f, type) if hrr: num += hrr[0] denom += 1 if denom: return "%.1f%%" % ((num / denom) * 100.0) else: return "<span class='no_data'>None</span>"
def soh_historical_response(facility): r = historical_response_rate(facility, SupplyPointStatusTypes.SOH_FACILITY) return "<span title='%d of %d'>%s%%</span>" % ( r[1], r[2], floatformat(r[0] * 100.0)) if r else "No data"
def soh_historical_response(facility): r = historical_response_rate(facility, SupplyPointStatusTypes.SOH_FACILITY) return "<span title='%d of %d'>%s%%</span>" % (r[1], r[2], floatformat(r[0]*100.0)) if r else "No data"
def _hrr_super(sp): r = historical_response_rate(sp, SupplyPointStatusTypes.SUPERVISION_FACILITY) return "<span title='%d of %d'>%s%%</span>" % ( r[1], r[2], floatformat(r[0] * 100.0)) if r else "No data"
def _hrr_super(sp): r = historical_response_rate(sp, SupplyPointStatusTypes.SUPERVISION_FACILITY) return "<span title='%d of %d'>%s%%</span>" % (r[1], r[2], floatformat(r[0]*100.0)) if r else "No data"