示例#1
0
def lookup_median(lender, metro):
    """Look up median. If not present, calculate it."""
    if lender:
        lender_str = str(lender.agency_id) + lender.ffiec_id
        if metro:
            stat = LendingStats.objects.filter(lender=lender_str,
                                               geoid=metro.geoid).first()
            if stat:
                return stat.median_per_tract
        return calculate_median_loans(lender_str, metro)
示例#2
0
def lookup_median(lender, metro):
    """Look up median. If not present, calculate it."""
    if lender:
        lender_str = lender.institution_id
        if metro:
            stat = LendingStats.objects.filter(
                institution_id=lender_str, geo_id=metro.geoid).first()
            if stat:
                return stat.lar_median
        return calculate_median_loans(lender_str, metro)
示例#3
0
def lookup_median(lender, metro):
    """Look up median. If not present, calculate it."""
    if lender:
        lender_str = str(lender.agency_id) + lender.ffiec_id
        if metro:
            stat = LendingStats.objects.filter(
                lender=lender_str, geoid=metro.geoid).first()
            if stat:
                return stat.median_per_tract
        return calculate_median_loans(lender_str, metro)
示例#4
0
def lookup_median(lender, metro):
    """Look up median. If not present, calculate it."""
    if lender:
        lender_str = lender.institution_id
        if metro:
            stat = LendingStats.objects.filter(institution_id=lender_str,
                                               geo_id=metro.geoid).first()
            if stat:
                return stat.lar_median
        return calculate_median_loans(lender_str, metro)
示例#5
0
 def test_calculate_median_loans(self):
     lender_id = self.respondent.institution_id
     # 1 in tract 1, 3 in 2, 8 in 3, 0 in 4;             avg: 4, med: 3
     self.assertEqual(3, calculate_median_loans(lender_id, self.metro))
     # 1 in tract 1, 3 in 2, 8 in 3, 0 in 4; 7 in 5, 16 in 6; avg:6, med:7
     self.assertEqual(7, calculate_median_loans(lender_id, None))
示例#6
0
 def test_calculate_median_loans(self):
     lender_id = self.respondent.institution_id
     # 1 in tract 1, 3 in 2, 8 in 3, 0 in 4;             avg: 4, med: 3
     self.assertEqual(3, calculate_median_loans(lender_id, self.metro))
     # 1 in tract 1, 3 in 2, 8 in 3, 0 in 4; 7 in 5, 16 in 6; avg:6, med:7
     self.assertEqual(7, calculate_median_loans(lender_id, None))