Skip to content

Commit

Permalink
Adjust README and some PEP8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
higs4281 committed Dec 25, 2016
1 parent e03dde8 commit 582b5f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Owning a Home API

This project feeds detailed mortgage market data to the Consumer Financial Protection Bureau's [Owning a Home suite of tools](http://www.consumerfinance.gov/owning-a-home/). Unfortunately, the raw data set it uses is not available publicly and is not in this repository.
This project feeds detailed mortgage market data to the Consumer Financial Protection Bureau's [Owning a Home suite of tools](http://www.consumerfinance.gov/owning-a-home/). Unfortunately, the main data set it uses is not available publicly and is not in this repository.

What is included is the API code and some basic geographical data. If you want to give it a spin, here's how:

Expand Down Expand Up @@ -47,7 +47,7 @@ pip install -r requirements/test.txt

```shell
python manage.py migrate --noinput
python manage.py load_county_limits ~/workspace/owning-a-home-api/data/county_limit_data-flat.csv --confirm=y
python manage.py loaddata countylimits.json
python manage.py runserver
```

Expand Down
55 changes: 36 additions & 19 deletions countylimits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

abbr_to_name = dict(STATE_CHOICES)

""" We are using Federal Information Processing Standard (FIPS) state and county codes.
More information can be found in the following articles:
http://en.wikipedia.org/wiki/Federal_Information_Processing_Standard_state_code
http://en.wikipedia.org/wiki/FIPS_county_code """
"""
We use Federal Information Processing Standard (FIPS) state and county codes.
More information can be found in the following articles:
http://en.wikipedia.org/wiki/Federal_Information_Processing_Standard_state_code
http://en.wikipedia.org/wiki/FIPS_county_code
"""


class State(models.Model):
""" A basic State object. """
state_fips = models.CharField(max_length=2, help_text='A two-digit FIPS code for the state')
state_fips = models.CharField(
max_length=2, help_text='A two-digit FIPS code for the state')
state_abbr = USStateField(help_text='A two-letter state abbreviation')

def __unicode__(self):
Expand All @@ -22,7 +25,9 @@ def __unicode__(self):

class County(models.Model):
""" A basic state county object. """
county_fips = models.CharField(max_length=3, help_text='A three-digit FIPS code for the state\'s county')
county_fips = models.CharField(
max_length=3,
help_text='A three-digit FIPS code for the state\'s county')
county_name = models.CharField(max_length=100, help_text='The county name')
state = models.ForeignKey(State)

Expand All @@ -35,15 +40,18 @@ class CountyLimit(models.Model):
fha_limit = models.DecimalField(
max_digits=12,
decimal_places=2,
help_text='Federal Housing Administration loan lending limit for the county')
help_text='Federal Housing Administration '
'loan lending limit for the county')
gse_limit = models.DecimalField(
max_digits=12,
decimal_places=2,
help_text='Loan limit for mortgages acquired by the Government-Sponsored Enterprises')
help_text='Loan limit for mortgages acquired '
'by the Government-Sponsored Enterprises')
va_limit = models.DecimalField(
max_digits=12,
decimal_places=2,
help_text='The Department of Veterans Affairs loan guaranty program limit')
help_text='The Department of Veterans Affairs '
'loan guaranty program limit')
county = models.OneToOneField(County)

def __unicode__(self):
Expand All @@ -54,7 +62,10 @@ def county_limits_by_state(state):
""" Get a list of state counties with limits. """
data = []
# state value can be a State FIPS or a state abbr.
result = County.objects.filter(models.Q(state__state_fips=state) | models.Q(state__state_abbr=state))
result = County.objects.filter(
models.Q(state__state_fips=state) |
models.Q(state__state_abbr=state)
)
counties = {}
state_abbr = ''
state_fips = ''
Expand All @@ -67,14 +78,20 @@ def county_limits_by_state(state):
'county_fips': county.county_fips
}

result = CountyLimit.objects.filter(models.Q(county__state__state_fips=state) | models.Q(county__state__state_abbr=state))
result = CountyLimit.objects.filter(
models.Q(county__state__state_fips=state) |
models.Q(county__state__state_abbr=state)
)
for countylimit in result:
data.append({
'state': abbr_to_name[state_abbr],
'county': counties[countylimit.county_id]['county_name'],
'complete_fips': '%s%s' % (state_fips, counties[countylimit.county_id]['county_fips']),
'gse_limit': countylimit.gse_limit,
'fha_limit': countylimit.fha_limit,
'va_limit': countylimit.va_limit,
})
data.append(
{'state': abbr_to_name[state_abbr],
'county': counties[countylimit.county_id]['county_name'],
'complete_fips': '{}{}'.format(
state_fips,
counties[countylimit.county_id]['county_fips']
),
'gse_limit': countylimit.gse_limit,
'fha_limit': countylimit.fha_limit,
'va_limit': countylimit.va_limit}
)
return data

0 comments on commit 582b5f0

Please sign in to comment.