Example #1
0
 def extract_report(r):
     data = u.extract_report(r)
     fug_id = data['facility']
     fug = _loc(fug_id)
     data['fug'] = fug.name
     data['facility'] = fug.parent_id
     return data
Example #2
0
def load_reports():
    reports = [u.extract_report(r) for r in PBFReport.objects.all().select_related()]

    wait_buckets = [(2, '<2'), (4, '2-4'), (None, '>4')]

    for r in reports:
        u.anonymize_contact(r)
        ts = datetime.strptime(r['timestamp'], '%Y-%m-%dT%H:%M:%S')
        r['month'] = ts.strftime('%b %Y')
        r['_month'] = ts.strftime('%Y-%m')
        for thresh, label in wait_buckets:
            if thresh is None or r['waiting_time'] < thresh:
                r['wait_bucket'] = label
                break

    return reports
Example #3
0
    def extract_report(r):
        data = u.extract_report(r)
        loc_id = data['facility']

        fug = fugs(loc_id)
        if fug:
            data['fug'] = fug.name
            data['facility'] = fug.parent_id

        elif facs.get(loc_id):
            data['fug'] = None
            data['facility'] = loc_id

        else:
            data['fug'] = None
            data['facility'] = None

        return data
Example #4
0
def load_reports(user=None):
    # TODO: filtering by state
    PBFReport = get_model('dashboard', 'PBFReport')
    ReportComment = get_model('dashboard', 'ReportComment')
    ReportCommentView = get_model('dashboard', 'ReportCommentView')

    facilities = map_reduce(get_facilities(), lambda e: [(e['id'], e)], lambda v: v[0])
    reports = [u.extract_report(r) for r in PBFReport.objects.all().select_related()]
    comments = map_reduce(ReportComment.objects.filter(pbf_report__isnull=False), lambda c: [(c.pbf_report_id, c)])

    wait_buckets = [(2, '<2'), (4, '2-4'), (None, '>4')]

    views = []
    if user:
        views = ReportCommentView.objects.filter(user=user)\
                                         .values_list('report_comment', flat=True)
    def _get_json(comment):  # Add whether or not the comment has been viewed.
        json = comment.json()
        json.update({'viewed': comment.pk in views if user else None})
        return json

    for r in reports:
        u.anonymize_contact(r)
        ts = datetime.strptime(r['timestamp'], '%Y-%m-%dT%H:%M:%S')
        r['thread'] = [_get_json(c) for c in sorted(comments.get(r['id'], []), key=lambda c: c.date)]
        r['month'] = ts.strftime('%b %Y')
        r['_month'] = ts.strftime('%Y-%m')
        r['display_time'] = datetime.strptime(r['timestamp'], '%Y-%m-%dT%H:%M:%S').strftime('%d/%m/%y at %H:%M')
        r['site_name'] = facilities[r['facility']]['name'] if r['for_this_site'] else r['site_other']
        if r['waiting_time'] is not None:
            for thresh, label in wait_buckets:
                if thresh is None or r['waiting_time'] < thresh:
                    r['wait_bucket'] = label
                    break
        else:
            r['wait_bucket'] = None

    return reports