Skip to content

Commit

Permalink
Merge pull request #962 from CodeForPhilly/lebovits/fix-phs-propertie…
Browse files Browse the repository at this point in the history
…s-flitch

Fix for a glitch caused by changes to PHS data
  • Loading branch information
nlebovits authored Oct 18, 2024
2 parents 397635d + c8c7451 commit 82bf136
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
3 changes: 1 addition & 2 deletions data/src/constants/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
]

PHS_LAYERS_TO_LOAD = [
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/ArcGIS/rest/services/PHS_CommunityLandcare/FeatureServer/0/",
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/ArcGIS/rest/services/PHS_PhilaLandCare_Maintenance/FeatureServer/0/",
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/ArcGIS/rest/services/phs_landcare/FeatureServer/0",
]

RCOS_LAYERS_TO_LOAD = [
Expand Down
32 changes: 21 additions & 11 deletions data/src/data_utils/phs_properties.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
from classes.featurelayer import FeatureLayer
from constants.services import PHS_LAYERS_TO_LOAD

def phs_properties(primary_featurelayer: FeatureLayer) -> FeatureLayer:
"""
Perform a spatial join between the primary feature layer and the PHS properties layer,
then update the primary feature layer with a new column 'phs_care_program' indicating
if the property is part of the PHS care program.
def phs_properties(primary_featurelayer):
Args:
primary_featurelayer (FeatureLayer): The primary feature layer to join with the PHS properties layer.
Returns:
FeatureLayer: The updated primary feature layer with the 'phs_care_program' column.
"""

phs_properties = FeatureLayer(
name="PHS Properties", esri_rest_urls=PHS_LAYERS_TO_LOAD, cols=["BRT_ID"]
name="PHS Properties", esri_rest_urls=PHS_LAYERS_TO_LOAD, cols=["program"]
)

phs_properties.gdf.loc[:, "phs_partner_agency"] = "PHS"

primary_featurelayer.opa_join(
phs_properties.gdf,
"brt_id",
)
# Perform spatial join between primary feature layer and PHS properties
primary_featurelayer.spatial_join(phs_properties)

primary_featurelayer.gdf.loc[:, "phs_partner_agency"] = primary_featurelayer.gdf[
"phs_partner_agency"
].fillna("None")
# Initialize 'phs_care_program' column with default "no" for all rows
primary_featurelayer.gdf["phs_care_program"] = "no"

# Set 'phs_care_program' to "yes" for matched rows
primary_featurelayer.gdf.loc[primary_featurelayer.gdf["phs_care_program"] != "no", "phs_care_program"] = "yes"

# Rebuild the GeoDataFrame after updates
primary_featurelayer.rebuild_gdf()

return primary_featurelayer
2 changes: 1 addition & 1 deletion data/src/data_utils/priority_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def priority_level(dataset):

# Decision Points
guncrime_density_percentile = row["gun_crimes_density_percentile"]
in_phs_landcare = row["phs_partner_agency"] == "PHS"
in_phs_landcare = row["phs_care_program"] == "yes"
has_li_complaint_or_violation = (
row["li_complaints"] is not None
and float(row["all_violations_past_year"]) > 0
Expand Down

0 comments on commit 82bf136

Please sign in to comment.