def setUp(self): stats = Census2010Households(None, 100, 80, 50, 30, 20, 10, 20, 15, 5) stats.geoid_id = '1122233300' stats.save() stats = Census2010Households(None, 1000, 800, 500, 300, 200, 100, 200, 150, 50) stats.geoid_id = '1122233400' stats.save() stats = Census2010Households(None, 200, 160, 100, 60, 40, 20, 40, 30, 10) stats.geoid_id = '1222233300' stats.save() def mkrecord(action_taken, agency_code, countyfp, geoid): record = HMDARecord(as_of_year=2014, respondent_id='1111111111', agency_code=agency_code, loan_amount_000s=222, action_taken=action_taken, statefp='11', countyfp=countyfp) record.geoid_id = geoid record.save() mkrecord(1, '1', '222', '1122233300') mkrecord(1, '1', '222', '1122233300') mkrecord(1, '1', '222', '1122233400') mkrecord(8, '1', '222', '1122233300') mkrecord(1, '2', '222', '1122233300') mkrecord(1, '1', '223', '1122333300')
def setUp(self): stats = Census2010Households(None, 100, 80, 50, 30, 20, 10, 20, 15, 5) stats.geoid_id = '1122233300' stats.save() stats = Census2010Households(None, 1000, 800, 500, 300, 200, 100, 200, 150, 50) stats.geoid_id = '1122233400' stats.save() stats = Census2010Households(None, 200, 160, 100, 60, 40, 20, 40, 30, 10) stats.geoid_id = '1222233300' stats.save() def mkrecord(action_taken, countyfp, geoid): respondent = Institution.objects.get(institution_id="922-333") record = HMDARecord(as_of_year=2014, respondent_id=respondent.respondent_id, agency_code=respondent.agency_id, loan_type=1, property_type=1, loan_purpose=1, owner_occupancy=1, loan_amount_000s=222, preapproval='1', action_taken=action_taken, msamd='01234', statefp='11', countyfp=countyfp, census_tract_number='01234', applicant_ethnicity='1', co_applicant_ethnicity='1', applicant_race_1='1', co_applicant_race_1='1', applicant_sex='1', co_applicant_sex='1', applicant_income_000s='1000', purchaser_type='1', rate_spread='0123', hoepa_status='1', lien_status='1', sequence_number='1', population='1', minority_population='1', ffieic_median_family_income='1000', tract_to_msamd_income='1000', number_of_owner_occupied_units='1', number_of_1_to_4_family_units='1', application_date_indicator=1) record.geo_geoid = geoid record.institution_id = respondent.institution_id record.save() mkrecord(1, '222', '1122233300') mkrecord(1, '222', '1122233300') mkrecord(1, '222', '1122233400') mkrecord(8, '222', '1122233300') mkrecord(1, '222', '1122233300') mkrecord(1, '223', '1122333300')
def mkrecord_household(geoid, total): record = Census2010Households(geoid_id=geoid, total=total, total_family=0, husband_wife=0, total_family_other=0, male_no_wife=0, female_no_husband=0, total_nonfamily=0, living_alone=0, not_living_alone=0) record.save()
def handle_filefive(self, geofile_name, state, geoids_by_record): """File five (XX000052010.sf1) contains household metrics, including divisions by household type, household size, etc. Documentation starts at page 6-38""" file4_name = geofile_name[:-11] + "000052010.sf1" datafile = open(file4_name, 'r') households = [] skip_households = Census2010Households.objects.filter( geoid__state=state).exists() if not skip_households: for row in reader(datafile): recordnum = row[4] if recordnum in geoids_by_record: fields = [None] # Ignore geoid until later # fields match the values in the census fields.extend(int(row[idx]) for idx in range(28, 37)) data = Census2010Households(*fields) data.geoid_id = geoids_by_record[recordnum] households.append(data) datafile.close() if not skip_households: Census2010Households.objects.bulk_create(households)
def setUp(self): stats = Census2010Households(None, 100, 80, 50, 30, 20, 10, 20, 15, 5) stats.geoid_id = '1122233300' stats.save() stats = Census2010Households(None, 1000, 800, 500, 300, 200, 100, 200, 150, 50) stats.geoid_id = '1122233400' stats.save() stats = Census2010Households(None, 200, 160, 100, 60, 40, 20, 40, 30, 10) stats.geoid_id = '1222233300' stats.save() def mkrecord(institution_id, action_taken, countyfp, geoid): respondent = Institution.objects.get(institution_id=institution_id) geo = Geo.objects.get(geoid=geoid) record = HMDARecord(as_of_year=2014, respondent_id=respondent.respondent_id, agency_code=respondent.agency_id, loan_type=1, property_type=1, loan_purpose=1, owner_occupancy=1, loan_amount_000s=222, preapproval='1', action_taken=action_taken, msamd='01234', statefp='11', countyfp=countyfp, census_tract_number='01234', applicant_ethnicity='1', co_applicant_ethnicity='1', applicant_race_1='1', co_applicant_race_1='1', applicant_sex='1', co_applicant_sex='1', applicant_income_000s='1000', purchaser_type='1', rate_spread='0123', hoepa_status='1', lien_status='1', sequence_number='1', population='1', minority_population='1', ffieic_median_family_income='1000', tract_to_msamd_income='1000', number_of_owner_occupied_units='1', number_of_1_to_4_family_units='1', application_date_indicator=1) record.geo = geo record.institution = respondent record.save() #institution #1 records, total = 6; selected institution mkrecord("91000000001", 1, '222', '1122233300') mkrecord("91000000001", 1, '222', '1122233300') mkrecord("91000000001", 1, '222', '1122233400') mkrecord("91000000001", 1, '222', '1122233300') mkrecord("91000000001", 1, '222', '1122233300') mkrecord("91000000001", 1, '223', '1122333300') #institution #2 records, total = 4; >.5 and <2.0; peer mkrecord("91000000002", 1, '222', '1122233300') mkrecord("91000000002", 1, '222', '1122233300') mkrecord("91000000002", 1, '222', '1122233400') mkrecord("91000000002", 1, '222', '1122233300') #institution #3 records, total =2; <.5; not peer mkrecord("91000000003", 1, '222', '1122233300') mkrecord("91000000003", 1, '223', '1122333300') #institution #4 records, total = 13; >2.0; not peer mkrecord("11000000001", 1, '222', '1122233300') mkrecord("11000000001", 1, '222', '1122233300') mkrecord("11000000001", 1, '222', '1122233400') mkrecord("11000000001", 1, '222', '1122233300') mkrecord("11000000001", 1, '222', '1122233300') mkrecord("11000000001", 1, '223', '1122333300') mkrecord("11000000001", 1, '222', '1122233300') mkrecord("11000000001", 1, '222', '1122233300') mkrecord("11000000001", 1, '222', '1122233400') mkrecord("11000000001", 1, '222', '1122233300') mkrecord("11000000001", 1, '222', '1122233300') mkrecord("11000000001", 1, '223', '1122333300') mkrecord("11000000001", 1, '223', '1122333300') #institution #4 records, total = 4; >.5 and <2.0; peer mkrecord("11000000002", 1, '222', '1122233300') mkrecord("11000000002", 1, '222', '1122233300') mkrecord("11000000002", 1, '222', '1122233400') mkrecord("11000000002", 1, '222', '1122233300') mkrecord("11000000002", 1, '222', '1122233300') mkrecord("91000000001", 6, '223', '1222233300') call_command('calculate_loan_stats')