Esempio n. 1
0
def programDetailConsistency(program, unit):
    #returns a chunk of HTML showing the detailed consistency stats for this program
    types = [1, 2] # 1=grants, 2=loans,guarantees,insurance
    type_names = {1: 'Grants', 2: 'Loans'}
    program_obligations = ProgramObligation.objects.filter(program=program, fiscal_year__lte=max(FISCAL_YEARS)).order_by('fiscal_year')
    html = []
    if program_obligations.count() > 0:
        for ty in types:
            obligations = program_obligations.filter(type=ty)
            if obligations:
                    html.append('<li><table><thead>')
                    html.append('<tr><th class="arrow"></th><th class="reviewed">Consistency (%s)</th>' % type_names[ty])
                    for fy in FISCAL_YEARS: html.append('<th>' + str(fy) + '</th>')
                    html.append('</tr></thead><tbody>')
                    values, trends = getConsistencyTrends(obligations, unit)
                    count = 0
                    for metric in ['Over Reported', 'Under Reported', 'Not Reported']:
                        html.append('<tr class="%s"><td title="trend over time" ><span class="%s"></span></td>' % (getRowClass(count), trends[count] ))
                        html.append('<td class="reviewed">'+metric+'</td>')
                        for row in values[count]:
                            if row:
                                if unit == 'dollars': row = moneyfmt(Decimal(str(row)), places=0, curr='$', sep=',', dp='')
                                else: row = "%d" % (row * 100) + '%'
                                html.append('<td>%s</td>' % row ) 
                            else:
                                html.append('<td>&mdash;</td>')
                        html.append('</tr>')
                        count += 1

                    html.append('</tbody></table></li>')
                
    return ''.join(html)    
Esempio n. 2
0
    def make_detail_record(program_id):
        consistency = consistency_lookup.get(program_id)
        under_reported_field = ('%s%%' % consistency.under_reported_pct) if consistency and consistency.under_reported_pct else None
        over_reported_field = ('%s%%' % consistency.over_reported_pct) if consistency and consistency.over_reported_pct else None

        timeliness = timeliness_lookup.get(program_id)
        if timeliness is None or timeliness.total_rows == 0:
            # None if there is no timeliness data for the program
            # 0 if there is timeliness data for the program, but not for this fiscal year
            timeliness_field = None
        else:
            timeliness_field = '%0.2f%%' % (float(timeliness.late_rows) / float(timeliness.total_rows))

        completeness = completeness_lookup.get(program_id)
        if completeness is None:
            completeness_field = None
        else:
            pct = completeness.failed_pct
            if pct is None:
                completeness_field = None
            else:
                completeness_field = '%.2f%%' % pct

        return [program_id,
                obligation_lookup[program_id].program.program_number,
                obligation_lookup[program_id].program.program_title,
                under_reported_field,
                over_reported_field,
                completeness_field,
                timeliness_field,
                moneyfmt(obligation_lookup[program_id].obligation, curr='$', places=0, sep=',', dp='')
               ]
Esempio n. 3
0
def programDetailConsistency(program, unit):
    #returns a chunk of HTML showing the detailed consistency stats for this program
    types = [1, 2] # 1=grants, 2=loans,guarantees,insurance
    type_names = {1: 'Grants', 2: 'Loans'}
    program_obligations = ProgramObligation.objects.filter(program=program, fiscal_year__gte=min(FISCAL_YEARS), fiscal_year__lte=max(FISCAL_YEARS)).order_by('fiscal_year')
    program_obligations_by_year = {}
    for o in program_obligations:
        program_obligations_by_year[o.fiscal_year] = o

    html = []
    if program_obligations.count() > 0:
        for ty in types:
            obligations = program_obligations.filter(type=ty)
            if obligations:
                    html.append('<li><table><thead>')
                    html.append('<tr><th class="arrow"></th><th class="reviewed">Consistency (%s)</th>' % type_names[ty])
                    for fy in FISCAL_YEARS: html.append('<th>' + str(fy) + '</th>')
                    html.append('</tr><tr><td></td><td colspan="4"><em>percent or dollar amount of obligations that were over/under reported, or not reported at all</em></td></tr></thead><tbody>')
                    values, trends = getConsistencyTrends(obligations, unit)
                    count = 0
                    for metric in ['Over Reported', 'Under Reported', 'Not Reported']:
                        html.append('<tr class="%s"><td title="trend over time" ><span class="%s"></span></td>' % (getRowClass(count), trends[count] ))
                        html.append('<td class="reviewed">'+metric+'</td>')
                        for (year_idx, row) in enumerate(values[count]):
                            if row:
                                if unit == 'dollars':
                                    row = moneyfmt(Decimal(str(row)), 
                                                   places=0, curr='$', sep=',', dp='')
                                else:
                                    row = "%d" % (row * 100) + '%'
                                    o = program_obligations_by_year.get(FISCAL_YEARS[year_idx])
                                    if o is not None and o.obligation == Decimal('0.0') and o.usaspending_obligation != Decimal('0.0'):
                                        row += '<sup>&dagger;</sup>'
                                    
                                html.append('<td>%s</td>' % row ) 
                            else:
                                html.append('<td>&mdash;</td>')
                        html.append('</tr>')
                        count += 1

                    html.append('</tbody></table></li>')
                
    return ''.join(html)    
Esempio n. 4
0
    def make_detail_record(program_id):
        consistency = consistency_lookup.get(program_id)
        under_reported_field = (
            '%s%%' % consistency.under_reported_pct
        ) if consistency and consistency.under_reported_pct else None
        over_reported_field = (
            '%s%%' % consistency.over_reported_pct
        ) if consistency and consistency.over_reported_pct else None

        timeliness = timeliness_lookup.get(program_id)
        if timeliness is None or timeliness.total_rows == 0:
            # None if there is no timeliness data for the program
            # 0 if there is timeliness data for the program, but not for this fiscal year
            timeliness_field = None
        else:
            timeliness_field = '%0.2f%%' % (float(timeliness.late_rows) /
                                            float(timeliness.total_rows))

        completeness = completeness_lookup.get(program_id)
        if completeness is None:
            completeness_field = None
        else:
            pct = completeness.failed_pct
            if pct is None:
                completeness_field = None
            else:
                completeness_field = '%.2f%%' % pct

        return [
            program_id, obligation_lookup[program_id].program.program_number,
            obligation_lookup[program_id].program.program_title,
            under_reported_field, over_reported_field, completeness_field,
            timeliness_field,
            moneyfmt(obligation_lookup[program_id].obligation,
                     curr='$',
                     places=0,
                     sep=',',
                     dp='')
        ]
Esempio n. 5
0
def programDetailGeneral(program_id, unit, field_names, proper_names, coll,
                         metric):

    html = []
    com_totals = {}
    if metric == 'Completeness':
        totals = ProgramCompleteness.objects.filter(program=program_id)
        for t in totals:
            com_totals[t.fiscal_year] = t.completeness_total_dollars

    if coll:
        html.append(
            '<li><table><thead><tr><th class="arrow"></th><th class="reviewed">'
            + metric + '</th>')
        for fy in FISCAL_YEARS:
            html.append('<th>' + str(fy) + '</th>')
        html.append('</tr><tr><td colspan="4">')
        if metric == "Completeness":
            html.append(
                'percent or dollar amount of obligations that failed each field'
            )
        else:
            html.append(
                'percent or dollar amount of obligations that were late')
        html.append('</td></tr></thead><tbody>')
        count = 0
        for f in field_names:
            temp_html = []
            first = None
            last = None
            temp_html.append(
                '<td class="reviewed">%s</td>' % proper_names[count])
            year_count = 0
            for y in FISCAL_YEARS:
                item = get_first(coll.filter(fiscal_year=y))
                if item:
                    if not first and item.__dict__[f]:
                        first = item.__dict__[f]
                    elif item.__dict__[f]:
                        last = item.__dict__[f]

                    if item.__dict__[f]:
                        if unit == 'pct' and f != 'avg_lag_rows':
                            if metric == 'Completeness':
                                val = '%d' % ((
                                    (item.__dict__[f] / com_totals[y]) or 0) *
                                              100)
                                val += '%'
                            elif f != 'total_dollars':
                                val = str((item.__dict__[f] or 0) * 100) + '%'
                            else:
                                val = "%s" % moneyfmt((item.__dict__[f] or 0),
                                                      places=0,
                                                      curr='$',
                                                      sep=',',
                                                      dp='')
                        elif f != 'avg_lag_rows':
                            val = '%s' % moneyfmt(
                                Decimal(str(item.__dict__[f] or 0)),
                                places=0,
                                curr='$',
                                sep=',',
                                dp='')
                        else:
                            val = item.__dict__[f]
                        temp_html.append('<td>%s</td>' % val)
                    else:
                        temp_html.append('<td>&mdash;</td>')
                else:
                    temp_html.append('<td>&mdash;</td>')

                year_count += 1

            trend = 'arrow'
            if first and last:
                if last > first: trend = 'redarrow'
                elif first > last: trend = 'greenarrow'
            html.append(
                '<tr class="%s"><td title="trend over time"><span class="%s"></span></td>%s</tr>'
                % (getRowClass(count), trend, ''.join(temp_html)))
            count += 1

        html.append('</tbody></table></li>')

    return ''.join(html)
Esempio n. 6
0
def programDetailGeneral(program_id, unit, field_names, proper_names, coll,
                         metric):

    html = []
    com_totals = {}
    if metric == 'Completeness':
        totals = ProgramCompleteness.objects.filter(program=program_id)
        for t in totals:
            com_totals[t.fiscal_year] = t.completeness_total_dollars

    if coll:
        html.append(
            '<li><table><thead><tr><th class="arrow"></th><th class="reviewed">'
            + metric + '</th>')
        for fy in FISCAL_YEARS:
            html.append('<th>' + str(fy) + '</th>')
        html.append('</tr><tr><td></td><td colspan="4"><em>')
        if metric == "Completeness":
            html.append(
                'percent or dollar amount of obligations that failed each field'
            )
        else:
            html.append(
                'percent or dollar amount of obligations that were late')
        html.append('</em></td></tr></thead><tbody>')
        count = 0
        for f in field_names:
            temp_html = []
            first = None
            last = None
            temp_html.append('<td class="reviewed">%s</td>' %
                             proper_names[count])
            year_count = 0
            for y in FISCAL_YEARS:
                item = get_first(coll.filter(fiscal_year=y))
                if item:
                    if not first and item.__dict__[f]:
                        first = item.__dict__[f]
                    elif item.__dict__[f]:
                        last = item.__dict__[f]

                    if item.__dict__[f]:
                        if unit == 'pct' and f != 'avg_lag_rows':
                            if metric == 'Completeness':
                                val = '%d' % ((
                                    (item.__dict__[f] / com_totals[y]) or 0) *
                                              100)
                                val += '%'
                            elif f != 'total_dollars':
                                val = str((item.__dict__[f] or 0)) + '%'
                            else:
                                val = "%s" % moneyfmt((item.__dict__[f] or 0),
                                                      places=0,
                                                      curr='$',
                                                      sep=',',
                                                      dp='')
                        elif f != 'avg_lag_rows':
                            val = '%s' % moneyfmt(Decimal(
                                str(item.__dict__[f] or 0)),
                                                  places=0,
                                                  curr='$',
                                                  sep=',',
                                                  dp='')
                        else:
                            val = item.__dict__[f]
                        temp_html.append('<td>%s</td>' % val)
                    else:
                        temp_html.append('<td>&mdash;</td>')
                else:
                    temp_html.append('<td>&mdash;</td>')

                year_count += 1

            trend = 'arrow'
            if first and last:
                if last > first: trend = 'redarrow'
                elif first > last: trend = 'greenarrow'
            html.append(
                '<tr class="%s"><td title="trend over time"><span class="%s"></span></td>%s</tr>'
                % (getRowClass(count), trend, ''.join(temp_html)))
            count += 1

        html.append('</tbody></table></li>')

    return ''.join(html)
Esempio n. 7
0
def programDetailConsistency(program, unit):
    #returns a chunk of HTML showing the detailed consistency stats for this program
    types = [1, 2]  # 1=grants, 2=loans,guarantees,insurance
    type_names = {1: 'Grants', 2: 'Loans'}
    program_obligations = ProgramObligation.objects.filter(
        program=program,
        fiscal_year__gte=min(FISCAL_YEARS),
        fiscal_year__lte=max(FISCAL_YEARS)).order_by('fiscal_year')
    program_obligations_by_year = {}
    for o in program_obligations:
        program_obligations_by_year[o.fiscal_year] = o

    html = []
    if program_obligations.count() > 0:
        for ty in types:
            obligations = program_obligations.filter(type=ty)
            if obligations:
                html.append('<li><table><thead>')
                html.append(
                    '<tr><th class="arrow"></th><th class="reviewed">Consistency (%s)</th>'
                    % type_names[ty])
                for fy in FISCAL_YEARS:
                    html.append('<th>' + str(fy) + '</th>')
                html.append(
                    '</tr><tr><td></td><td colspan="4"><em>percent or dollar amount of obligations that were over/under reported, or not reported at all</em></td></tr></thead><tbody>'
                )
                values, trends = getConsistencyTrends(obligations, unit)
                count = 0
                for metric in [
                        'Over Reported', 'Under Reported', 'Not Reported'
                ]:
                    html.append(
                        '<tr class="%s"><td title="trend over time" ><span class="%s"></span></td>'
                        % (getRowClass(count), trends[count]))
                    html.append('<td class="reviewed">' + metric + '</td>')
                    for (year_idx, row) in enumerate(values[count]):
                        if row:
                            if unit == 'dollars':
                                row = moneyfmt(Decimal(str(row)),
                                               places=0,
                                               curr='$',
                                               sep=',',
                                               dp='')
                            else:
                                row = "%d" % (row * 100) + '%'
                                o = program_obligations_by_year.get(
                                    FISCAL_YEARS[year_idx])
                                if o is not None and o.obligation == Decimal(
                                        '0.0'
                                ) and o.usaspending_obligation != Decimal(
                                        '0.0'):
                                    row += '<sup>&dagger;</sup>'

                            html.append('<td>%s</td>' % row)
                        else:
                            html.append('<td>&mdash;</td>')
                    html.append('</tr>')
                    count += 1

                html.append('</tbody></table></li>')

    return ''.join(html)