Example #1
0
def print_program_list(fiscal_year, best_program_ids):
    best_program_consistencies = list(
        ProgramConsistency.objects.filter(fiscal_year=fiscal_year,
                                          type=1,
                                          program__in=best_program_ids))
    best_program_consistencies.sort(compare_consistencies)

    fmtstr = "{program:<8} {consistency:>14} {completeness:>12} {timeliness:>11} {cfda:>21}"
    print fmtstr.format(program='PROGRAM',
                        consistency='INCONSISTENT',
                        completeness='INCOMPLETE',
                        timeliness='LATE',
                        cfda='CFDA OBLIGATION')
    for prog_consistency in best_program_consistencies:
        program = Program.objects.get(pk=prog_consistency.program_id)
        program_obligation = ProgramObligation.objects.get(
            fiscal_year=fiscal_year,
            type=1,
            program=prog_consistency.program_id)

        prog_completeness = ProgramCompleteness.objects.get(
            fiscal_year=fiscal_year, program=prog_consistency.program_id)
        try:
            prog_timeliness = ProgramTimeliness.objects.get(
                fiscal_year=fiscal_year, program=prog_consistency.program_id)
        except:
            prog_timeliness = None

        if prog_consistency.over_reported_pct not in (None, ''):
            over_or_under = "-" + str(prog_consistency.over_reported_pct)
        elif prog_consistency.under_reported_pct not in (None, ''):
            over_or_under = "-" + str(prog_consistency.under_reported_pct)
        else:
            over_or_under = None

        values = {
            'program':
            str(program.program_number),
            'consistency':
            (str(over_or_under) + '%' if over_or_under else '---'),
            'completeness':
            str(round(prog_completeness.failed_pct)) +
            '%' if prog_completeness.failed_pct is not None else '---',
            'timeliness':
            str(round(prog_timeliness.late_pct)) + '%' if prog_timeliness
            and prog_timeliness.late_pct is not None else '---',
            'cfda':
            pretty_money(program_obligation.obligation)
        }
        print fmtstr.format(**values)
Example #2
0
def print_program_list(fiscal_year, best_program_ids):
    best_program_consistencies = list(ProgramConsistency.objects.filter(fiscal_year=fiscal_year,
                                                                        type=1,
                                                                        program__in=best_program_ids))
    best_program_consistencies.sort(compare_consistencies)

    fmtstr = "{program:<8} {consistency:>14} {completeness:>12} {timeliness:>11} {cfda:>21}"
    print fmtstr.format(
        program='PROGRAM',
        consistency='INCONSISTENT',
        completeness='INCOMPLETE',
        timeliness='LATE',
        cfda='CFDA OBLIGATION'
    )
    for prog_consistency in best_program_consistencies:
        program = Program.objects.get(pk=prog_consistency.program_id)
        program_obligation = ProgramObligation.objects.get(fiscal_year=fiscal_year,
                                                           type=1,
                                                           program=prog_consistency.program_id)

        prog_completeness = ProgramCompleteness.objects.get(fiscal_year=fiscal_year,
                                                            program=prog_consistency.program_id)
        try:
            prog_timeliness = ProgramTimeliness.objects.get(fiscal_year=fiscal_year,
                                                            program=prog_consistency.program_id)
        except:
            prog_timeliness = None


        if prog_consistency.over_reported_pct not in (None, ''):
            over_or_under = "-" + str(prog_consistency.over_reported_pct)
        elif prog_consistency.under_reported_pct not in (None, ''):
            over_or_under = "-" + str(prog_consistency.under_reported_pct)
        else:
            over_or_under = None

        values = {
            'program': str(program.program_number),
            'consistency': (str(over_or_under) + '%'
                            if over_or_under else '---'),
            'completeness': str(round(prog_completeness.failed_pct)) + '%' if prog_completeness.failed_pct is not None else '---',
            'timeliness': str(round(prog_timeliness.late_pct)) + '%' if prog_timeliness and prog_timeliness.late_pct is not None else '---',
            'cfda': pretty_money(program_obligation.obligation)
        }
        print fmtstr.format(**values)
Example #3
0
 def __unicode__(self):
     return "<USASpendingAggregate(%d, %s)>" % (self.fiscal_year, unicode(pretty_money(self.total_federal_funding)))
from django.db.models import Sum
from numpy import mean, std
from metrics.models import ProgramTimeliness, AgencyTimeliness, USASpendingAggregate
from utils import pretty_money
from settings import FISCAL_YEARS


print "----- Sample Size -----"
for fy in FISCAL_YEARS:
    timeliness_sum = ProgramTimeliness.objects.filter(fiscal_year=fy).aggregate(Sum('total_dollars'))['total_dollars__sum']
    usaspending_sum = USASpendingAggregate.objects.get(fiscal_year=fy).total_federal_funding
    sample_pct = timeliness_sum * 100 / usaspending_sum
    print "%d: %.2f%% (%s / %s)" % (fy, round(sample_pct, 2),
                                    pretty_money(timeliness_sum),
                                    pretty_money(usaspending_sum))

print "----- Average Lag (program) -----"
for fy in FISCAL_YEARS:
    lag_values = [pt.avg_lag_rows for pt in ProgramTimeliness.objects.filter(fiscal_year=fy)]
    print "%d: %d mean (days), %.1f stdev" % (fy, mean(lag_values), std(lag_values))

print "----- Average Lag (agency) -----"
for fy in FISCAL_YEARS:
    lag_values = [at.avg_lag_rows for at in AgencyTimeliness.objects.filter(fiscal_year=fy)]
    print "%d: %d mean (days), %.1f stdev" % (fy, mean(lag_values), std(lag_values))
Example #5
0
        # fail completeness?
            if metric == 'all' or metric == 'completeness':
                comp = ProgramCompleteness.objects.filter(program=program, fiscal_year=fy)
                if len(comp) > 0:
                    comp = comp[0]
                    if comp.completeness_total_dollars and (float(comp.completeness_failed_dollars / comp.completeness_total_dollars) > .5):
                        total += ob.obligation
                        agency_totals = add_to_agency(agency_totals, program.agency.name, fy, ob.obligation)
                        writer.writerow((program.program_number, "%s" % program.program_title.encode('ascii', 'ignore'), 'completeness', ob.obligation))
                        continue


    count += 1
    all_obs = ProgramObligation.objects.filter(program__in=fins, fiscal_year=fy, type=TYPE).aggregate(summ=Sum('obligation'))['summ']
    if all_obs:
        print "%s - Total failed obligations: %s out of total obligations: %s (%s%%)" % (fy, pretty_money(total), 
                                                                                     pretty_money(all_obs),
                                                                                     round(total * 100 / all_obs, 2))
    else:
        print "No obligations for %s " % fy

data = []
agency_names = []
for k in agency_totals.keys():
    points = []
    for fy in FISCAL_YEARS:
        if agency_totals[k].has_key(fy):
            points.append((fy, float(agency_totals[k][fy])))
        else:
            points.append((fy, 0))
    data.append(points)
from django.db.models import Sum
from numpy import mean, std
from metrics.models import ProgramTimeliness, AgencyTimeliness, USASpendingAggregate
from utils import pretty_money
from settings import FISCAL_YEARS

print "----- Sample Size -----"
for fy in FISCAL_YEARS:
    timeliness_sum = ProgramTimeliness.objects.filter(
        fiscal_year=fy).aggregate(Sum('total_dollars'))['total_dollars__sum']
    usaspending_sum = USASpendingAggregate.objects.get(
        fiscal_year=fy).total_federal_funding
    sample_pct = timeliness_sum * 100 / usaspending_sum
    print "%d: %.2f%% (%s / %s)" % (fy, round(
        sample_pct,
        2), pretty_money(timeliness_sum), pretty_money(usaspending_sum))

print "----- Average Lag (program) -----"
for fy in FISCAL_YEARS:
    lag_values = [
        pt.avg_lag_rows
        for pt in ProgramTimeliness.objects.filter(fiscal_year=fy)
    ]
    print "%d: %d mean (days), %.1f stdev" % (fy, mean(lag_values),
                                              std(lag_values))

print "----- Average Lag (agency) -----"
for fy in FISCAL_YEARS:
    lag_values = [
        at.avg_lag_rows
        for at in AgencyTimeliness.objects.filter(fiscal_year=fy)
Example #7
0
                        agency_totals = add_to_agency(agency_totals,
                                                      program.agency.name, fy,
                                                      ob.obligation)
                        writer.writerow(
                            (program.program_number, "%s" %
                             program.program_title.encode('ascii', 'ignore'),
                             'completeness', ob.obligation))
                        continue

    count += 1
    all_obs = ProgramObligation.objects.filter(
        program__in=fins, fiscal_year=fy,
        type=TYPE).aggregate(summ=Sum('obligation'))['summ']
    if all_obs:
        print "%s - Total failed obligations: %s out of total obligations: %s (%s%%)" % (
            fy, pretty_money(total), pretty_money(all_obs),
            round(total * 100 / all_obs, 2))
    else:
        print "No obligations for %s " % fy

data = []
agency_names = []
for k in agency_totals.keys():
    points = []
    for fy in FISCAL_YEARS:
        if agency_totals[k].has_key(fy):
            points.append((fy, float(agency_totals[k][fy])))
        else:
            points.append((fy, 0))
    data.append(points)
    agency_names.append(k)