Skip to content

Commit

Permalink
added FHLB data to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
saylorsd committed Dec 12, 2024
1 parent d8b60ce commit 6097183
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3 as build
FROM python:3 AS build
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

Expand All @@ -14,7 +14,7 @@ RUN pip install -r requirements.txt
COPY . /code/


FROM build as migrate
FROM build AS migrate

COPY ./docker-entrypoint.sh /code/

Expand Down
73 changes: 73 additions & 0 deletions api/housing_data/housing_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class Meta:
db_table = '6234dd27-79f4-43d3-b098-19f12692ce55'


class FHLBFundingID(LookupTable):
class Meta:
managed = False
db_table = 'c1d26547-f13f-40bd-8363-e7fcc4584508'


# These are directly tied to datasets on the datacenter's CKAN datastore
# The table names are the datasets' CKAN resource IDs.
class HousingDataset(DatastoreDataset):
Expand Down Expand Up @@ -602,3 +608,70 @@ class PHFAStats(HousingDataset):
class Meta:
managed = False
db_table = 'a6b93b7b-e04e-42c9-96f9-ee788e4f0978'


class FHLBRentalProperties(HousingDataset):
fhlb_funding_id = models.IntegerField(blank=True, null=True)

full_text = models.TextField(db_column='_full_text', blank=True, null=True)
hud_property_name = models.TextField(blank=True, null=True)
application_type_name = models.TextField(blank=True, null=True)
property_street_address = models.TextField(blank=True, null=True)
city = models.TextField(blank=True, null=True)
county = models.TextField(blank=True, null=True)
state = models.TextField(blank=True, null=True)
zip_code = models.TextField(blank=True, null=True)

assisted_units = models.IntegerField(blank=True, null=True)
units = models.IntegerField(blank=True, null=True)

retention_expiration = models.DateField(blank=True, null=True)

_50_percent_ami_limit = models.IntegerField(db_column="50_percent_ami_limit", blank=True, null=True)
_60_percent_ami_limit = models.IntegerField(db_column="60_percent_ami_limit", blank=True, null=True)
_80_percent_ami_limit = models.IntegerField(db_column="80_percent_ami_limit", blank=True, null=True)
greater_than_80_ami = models.IntegerField(blank=True, null=True)

latitude = models.FloatField(blank=True, null=True)
longitude = models.FloatField(blank=True, null=True)

hc_index_fields = ('fhlb_funding_id',)

class Meta:
managed = False
db_table = 'afba564f-cc68-42f0-b37b-fc8d70e8ef47'


class FHLBRentalProjects(HousingDataset):
fhlb_funding_id = models.IntegerField(blank=True, null=True)

full_text = models.TextField(db_column='_full_text', blank=True, null=True)

parcel_count = models.IntegerField(blank=True, null=True)
hud_property_name = models.TextField(blank=True, null=True)
application_type_name = models.TextField(blank=True, null=True)

address_line_1_list = models.TextField(blank=True, null=True)
property_street_address = models.TextField(blank=True, null=True)
city = models.TextField(blank=True, null=True)
county = models.TextField(blank=True, null=True)
state = models.TextField(blank=True, null=True)
zip_code = models.TextField(blank=True, null=True)

_50_percent_ami_limit = models.IntegerField(db_column="50_percent_ami_limit", blank=True, null=True)
_60_percent_ami_limit = models.IntegerField(db_column="60_percent_ami_limit", blank=True, null=True)
_80_percent_ami_limit = models.IntegerField(db_column="80_percent_ami_limit", blank=True, null=True)
greater_than_80_ami = models.IntegerField(blank=True, null=True)

assisted_units = models.IntegerField(blank=True, null=True)
units = models.IntegerField(blank=True, null=True)
retention_expiration = models.DateField(blank=True, null=True)

latitude = models.FloatField(blank=True, null=True)
longitude = models.FloatField(blank=True, null=True)

hc_index_fields = ('fhlb_funding_id',)

class Meta:
managed = False
db_table = 'ecdbf89a-bbe7-4e82-b902-d6b774758d3a'
4 changes: 3 additions & 1 deletion api/housing_data/management/commands/connect_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ def handle(self, *args, **options):
"7d4ad5ee-7229-4aa6-b3a2-69779fe5c52a",
"f6a77bc1-e3c1-403a-86bc-40b906124af6",
"fcb7cd5d-71f6-4f38-bb78-a3002be47ed6",
"a6b93b7b-e04e-42c9-96f9-ee788e4f0978"
"a6b93b7b-e04e-42c9-96f9-ee788e4f0978",
"afba564f-cc68-42f0-b37b-fc8d70e8ef47",
"ecdbf89a-bbe7-4e82-b902-d6b774758d3a"
)
FROM SERVER datastore INTO datastore;
Expand Down
14 changes: 13 additions & 1 deletion api/housing_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
NormalizeStateID,
PMIndx,
LookupTable,
HouseCatSubsidyListing,
HouseCatSubsidyListing, FHLBFundingID, FHLBRentalProperties, FHLBRentalProjects,
)

DATASETS: list[Type[HousingDataset]] = [
Expand Down Expand Up @@ -386,6 +386,10 @@ def normalized_state_id_set(self) -> list[str]:
def pmindx_set(self) -> list[str]:
return get_fkeys(PMIndx, self.id)

@property
def fhlb_funding_id_set(self) -> list[str]:
return get_fkeys(FHLBFundingID, self.id)

@property
def property_id_set(self) -> list[str]:
return [self.property_id]
Expand Down Expand Up @@ -473,6 +477,14 @@ def phfa_stats(self):
def subsidy_info(self):
return self.get_related_data(HouseCatSubsidyListing)

@property
def fhlb_properties(self):
return self.get_related_data(FHLBRentalProperties)

@property
def fhlb_projects(self):
return self.get_related_data(FHLBRentalProjects)

def __str__(self):
return f'{self.id}: {self.hud_property_name}'

Expand Down
59 changes: 58 additions & 1 deletion api/housing_data/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
HUDPublicHousingDevelopments, HUDPublicHousingBuildings, SubsidyExtractFromHUDInsuredMultifamilyProperties, \
SubsidyExtractFromMultifamilyAssistanceAndSection8Contracts, MultifamilyAssistanceAndSection8Contracts, \
HUDInsuredMultifamilyProperties, HUDMultifamilyInspectionScores, LIHTCDataFromPHFA, \
DemographicsByHousingProjectFromPHFA, HouseCatSubsidyListing
DemographicsByHousingProjectFromPHFA, HouseCatSubsidyListing, FHLBRentalProperties, FHLBRentalProjects
from housing_data.models import ProjectIndex


Expand Down Expand Up @@ -478,6 +478,57 @@ class Meta:
)


class FHLBRentalPropertiesSerializer(serializers.ModelSerializer):
class Meta:
model = FHLBRentalProperties
fields = (
"fhlb_funding_id",
"hud_property_name",
"application_type_name",
"property_street_address",
"city",
"county",
"state",
"zip_code",
"assisted_units",
"units",
"retention_expiration",
"_50_percent_ami_limit",
"_60_percent_ami_limit",
"_80_percent_ami_limit",
"greater_than_80_ami",
"latitude",
"longitude",
)



class FHLBRentalProjectsSerializer(serializers.ModelSerializer):
class Meta:
model = FHLBRentalProjects
fields = (
'fhlb_funding_id',
'parcel_count',
'hud_property_name',
'application_type_name',
'address_line_1_list',
'property_street_address',
'city',
'county',
'state',
'zip_code',
'_50_percent_ami_limit',
'_60_percent_ami_limit',
'_80_percent_ami_limit',
'greater_than_80_ami',
'assisted_units',
'units',
'retention_expiration',
'latitude',
'longitude',
)


###################
# Project Index

Expand All @@ -500,6 +551,9 @@ class ProjectIndexSerializer(serializers.ModelSerializer):
demographics_by_housing_project_from_phfa = DemographicsByHousingProjectFromPHFASerializer(many=True)
phfa_stats = PHFAStatsSerializer(many=True)
subsidy_info = HouseCatSubsidyListingSerializer(many=True)
fhlb_properties = FHLBRentalPropertiesSerializer(many=True)
fhlb_projects = FHLBRentalProjectsSerializer(many=True)


class Meta:
model = ProjectIndex
Expand Down Expand Up @@ -545,6 +599,9 @@ class Meta:
'demographics_by_housing_project_from_phfa',
'phfa_stats',
'subsidy_info',

'fhlb_properties',
'fhlb_projects'
)


Expand Down
5 changes: 4 additions & 1 deletion explorer/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { HiChevronDown, HiChevronUp } from 'react-icons/hi';
interface Props {
protect?: boolean;
}
const ENV = process.env.NODE_ENV || 'development';

export default function Navbar({ protect = true }) {
const [isOpen, setIsOpen] = useState<boolean>(false);
Expand All @@ -20,7 +21,9 @@ export default function Navbar({ protect = true }) {
}

const onError = () => {
if (protect) router.push(LOGIN_URL);
if (ENV !== 'development') {
if (protect) router.push(LOGIN_URL);
}
};
const { data: currentUser } = useLoggedIn(onError);

Expand Down
7 changes: 0 additions & 7 deletions explorer/pages/map/[[...id]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import styles from '../../styles/Map.module.css';

import {
useHousingProjectMap,
useLoggedIn,
usePublicHousingProject,
} from '@wprdc-connections/housecat';

import { LoadingMessage } from '@wprdc-components/loading-message';
import { LOGIN_URL } from '../../settings';

function MapPage() {
const boardRef = React.useRef<HTMLDivElement>(null);
Expand All @@ -39,11 +37,6 @@ function MapPage() {
const { data: affordableHousingProject, isLoading } =
usePublicHousingProject(currentProject);

const onError = () => {
router.push(LOGIN_URL);
};
const { data: currentUser } = useLoggedIn(onError);

const router = useRouter();

// handle query params
Expand Down

0 comments on commit 6097183

Please sign in to comment.