Skip to content

Commit

Permalink
Merge pull request #1009 from hackforla/adding-councils-to-hotspots
Browse files Browse the repository at this point in the history
adding councils to hotspot geojson
  • Loading branch information
mattyweb authored Mar 11, 2021
2 parents 9a7864d + 35f8faf commit 4ac7f00
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion server/api/code/lacity_data_api/models/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ async def get_hotspots(cls, type_id: int, start_date: str):
# using ~30m radius (epsilon) and 1+ request/month
query = db.text(f"""
SELECT
councils.council_id,
councils.council_name,
h.hotspot_id,
count(*) as hotspot_count,
ST_X(ST_Centroid(ST_Collect(h.request_point))) as hotspot_long,
Expand All @@ -74,8 +76,10 @@ async def get_hotspots(cls, type_id: int, start_date: str):
WHERE
created_date >= '{start_date}' AND type_id = {type_id}
) as h
JOIN geometries ON ST_Within(request_point, ST_SetSRID(geometry, 4326))
JOIN councils ON (councils.data_code = geometries.nc_id)
WHERE hotspot_id is not null
GROUP BY h.hotspot_id
GROUP BY h.hotspot_id, council_id, council_name
;
""")

Expand Down
2 changes: 2 additions & 0 deletions server/api/code/lacity_data_api/routers/geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def createHotspotFeature(row):
return {
"type": "Feature",
"properties": {
"council_name": item['council_name'],
"council_id": item['council_id'],
"hotspot_id": item['hotspot_id'],
"count": item['hotspot_count'],
},
Expand Down
Empty file.
6 changes: 4 additions & 2 deletions server/api/code/lacity_data_api/services/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
from dateutil.relativedelta import relativedelta

from ..models import (
request_type, council, region, service_request, geometry
request_type, council, region, service_request
)
# from ..config import DEBUG


async def build_cache():
from ..models.geometry import Geometry # avoiding circular imports

open_requests = await service_request.get_open_requests()
open_requests_counts = await service_request.get_open_request_counts()
regions = await region.get_regions_dict()
councils = await council.get_councils_dict()
types = await request_type.get_types_dict()
geojson = await geometry.Geometry.get_council_geojson()
geojson = await Geometry.get_council_geojson()

# for i in councils:
# await council.get_open_request_counts(i)
Expand Down

0 comments on commit 4ac7f00

Please sign in to comment.