Beispiel #1
0
def process_facility_statuses(facility_id, statuses, alerts=True):
    """
    For a given facility and list of statuses, update the appropriate
    data warehouse tables. This should only be called on supply points
    that are facilities.
    """
    facility = get_location(facility_id)
    for status in statuses:
        warehouse_date = _get_window_date(status.status_type,
                                          status.status_date)
        if _is_valid_status(facility, status.status_date, status.status_type):
            org_summary = OrganizationSummary.objects.get_or_create(
                location_id=facility_id, date=warehouse_date)[0]
            group_summary = GroupSummary.objects.get_or_create(
                org_summary=org_summary, title=status.status_type)[0]
            group_summary.total = 1
            if status.status_value not in (
                    SupplyPointStatusValues.REMINDER_SENT,
                    SupplyPointStatusValues.ALERT_SENT):
                # we've responded to this query
                group_summary.responded = 1
                if status.status_value in [
                        SupplyPointStatusValues.SUBMITTED,
                        SupplyPointStatusValues.RECEIVED
                ]:
                    group_summary.complete = 1
                else:
                    group_summary.complete = group_summary.complete or 0
                if group_summary.complete:
                    if is_on_time(status.status_date, warehouse_date,
                                  status.status_type):
                        group_summary.on_time = 1
                    else:
                        group_summary.on_time = group_summary.on_time
                else:
                    group_summary.on_time = 0

                group_summary.save()

                if alerts:
                    if status.status_value == SupplyPointStatusValues.NOT_SUBMITTED \
                            and status.status_type == SupplyPointStatusTypes.R_AND_R_FACILITY:
                        create_alert(facility_id, status.status_date,
                                     const.RR_NOT_SUBMITTED, {'number': 1})

                    if status.status_value == SupplyPointStatusValues.NOT_RECEIVED \
                            and status.status_type == SupplyPointStatusTypes.DELIVERY_FACILITY:
                        create_alert(facility_id, status.status_date,
                                     const.DELIVERY_NOT_RECEIVED,
                                     {'number': 1})
Beispiel #2
0
def process_facility_statuses(facility_id, statuses, alerts=True):
    """
    For a given facility and list of statuses, update the appropriate
    data warehouse tables. This should only be called on supply points
    that are facilities.
    """
    facility = Location.get(facility_id)
    for status in statuses:
        warehouse_date = _get_window_date(status.status_type, status.status_date)
        if _is_valid_status(facility, status.status_date, status.status_type):
            org_summary = OrganizationSummary.objects.get_or_create(
                location_id=facility_id,
                date=warehouse_date
            )[0]
            group_summary = GroupSummary.objects.get_or_create(
                org_summary=org_summary,
                title=status.status_type
            )[0]
            group_summary.total = 1
            if status.status_value not in (SupplyPointStatusValues.REMINDER_SENT,
                                           SupplyPointStatusValues.ALERT_SENT):
                # we've responded to this query
                group_summary.responded = 1
                if status.status_value in [SupplyPointStatusValues.SUBMITTED,
                                           SupplyPointStatusValues.RECEIVED]:
                    group_summary.complete = 1
                else:
                    group_summary.complete = group_summary.complete or 0
                if group_summary.complete:
                    if is_on_time(status.status_date, warehouse_date, status.status_type):
                        group_summary.on_time = 1
                    else:
                        group_summary.on_time = group_summary.on_time
                else:
                    group_summary.on_time = 0

                group_summary.save()

                if alerts:
                    if status.status_value == SupplyPointStatusValues.NOT_SUBMITTED \
                            and status.status_type == SupplyPointStatusTypes.R_AND_R_FACILITY:
                        create_alert(facility_id, status.status_date, const.RR_NOT_SUBMITTED,
                                     {'number': 1})

                    if status.status_value == SupplyPointStatusValues.NOT_RECEIVED \
                            and status.status_type == SupplyPointStatusTypes.DELIVERY_FACILITY:
                        create_alert(facility_id, status.status_date, const.DELIVERY_NOT_RECEIVED,
                                     {'number': 1})
Beispiel #3
0
def not_responding_facility(org_summary):
    for status_type in needed_status_types(org_summary):
        group_summary, created = GroupSummary.objects.get_or_create(org_summary=org_summary, title=status_type)
        group_summary.total = 1
        assert group_summary.responded in (0, 1)
        if group_summary.title == SupplyPointStatusTypes.SOH_FACILITY and not group_summary.responded:
            # TODO: this might not be right unless we also clear it
            create_alert(org_summary.location_id, org_summary.date, "soh_not_responding", {"number": 1})
        elif group_summary.title == SupplyPointStatusTypes.R_AND_R_FACILITY and not group_summary.responded:
            # TODO: this might not be right unless we also clear it
            create_alert(org_summary.location_id, org_summary.date, "rr_not_responded", {"number": 1})
        elif group_summary.title == SupplyPointStatusTypes.DELIVERY_FACILITY and not group_summary.responded:
            # TODO: this might not be right unless we also clear it
            create_alert(org_summary.location_id, org_summary.date, "delivery_not_responding", {"number": 1})
        else:
            # not an expected / needed group. ignore for now
            pass

        group_summary.save()
Beispiel #4
0
def not_responding_facility(org_summary):
    for status_type in needed_status_types(org_summary):
        group_summary, created = GroupSummary.objects.get_or_create(
            org_summary=org_summary, title=status_type)
        group_summary.total = 1
        assert group_summary.responded in (0, 1)
        if group_summary.title == SupplyPointStatusTypes.SOH_FACILITY and not group_summary.responded:
            # TODO: this might not be right unless we also clear it
            create_alert(org_summary.location_id, org_summary.date,
                         'soh_not_responding', {'number': 1})
        elif group_summary.title == SupplyPointStatusTypes.R_AND_R_FACILITY and not group_summary.responded:
            # TODO: this might not be right unless we also clear it
            create_alert(org_summary.location_id, org_summary.date,
                         'rr_not_responded', {'number': 1})
        elif group_summary.title == SupplyPointStatusTypes.DELIVERY_FACILITY and not group_summary.responded:
            # TODO: this might not be right unless we also clear it
            create_alert(org_summary.location_id, org_summary.date,
                         'delivery_not_responding', {'number': 1})
        else:
            # not an expected / needed group. ignore for now
            pass

        group_summary.save()
Beispiel #5
0
def aggregate_response_alerts(location_id, date, alerts, alert_type):
    total = sum([s.number for s in alerts])
    if total > 0:
        create_alert(location_id, date, alert_type, {'number': total})
Beispiel #6
0
def aggregate_response_alerts(location_id, date, alerts, alert_type):
    total = sum([s.number for s in alerts])
    if total > 0:
        create_alert(location_id, date, alert_type, {'number': total})