Skip to content

Commit 1033ce5

Browse files
committed
Move backend to AWS
1 parent fa69d33 commit 1033ce5

File tree

9 files changed

+73
-66
lines changed

9 files changed

+73
-66
lines changed

Untitled-1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@app.route("/district_int")
2+
def district_intersections():
3+
id = request.args.get("boundid")
4+
namecol = request.args.get("featureid")
5+
6+
if not id or not namecol:
7+
return jsonify({"error": "boundid and featureid are required"}), 400
8+
9+
conn = pg_pool.getconn()
10+
try:
11+
with conn.cursor() as cur:
12+
cur.execute("""
13+
SELECT
14+
id_right AS id,
15+
namecol_right AS namecol,
16+
namealt_right AS namealt,
17+
ST_AsGeoJSON(geom),
18+
intersection_pct
19+
FROM all_intersections
20+
WHERE id_left = %s AND namecol_left = %s
21+
""", (id, namecol))
22+
23+
rows = cur.fetchall()
24+
if not rows:
25+
return jsonify({"error": "No boundaries found"}), 404
26+
27+
features = []
28+
for row in rows:
29+
feature = {
30+
"type": "Feature",
31+
"geometry": json.loads(row[3]),
32+
"properties": {
33+
"id": row[0],
34+
"namecol": row[1],
35+
"namealt": row[2],
36+
"intersection_pct": float(row[4]) if row[4] is not None else None
37+
}
38+
}
39+
features.append(feature)
40+
41+
return jsonify({
42+
"type": "FeatureCollection",
43+
"features": features
44+
})
45+
finally:
46+
pg_pool.putconn(conn)

src/assets/boundaries/index.ts

Lines changed: 16 additions & 49 deletions
Large diffs are not rendered by default.

src/components/Sidebar/AddressDetails.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
async function queryAllDistrictsForCoordinates(lng: number, lat: number) {
1717
districtsIntersectingAddress = [];
1818
isLoading = true;
19-
//const intersectsUrl = `https://betanyc.carto.com/api/v2/sql/?q=SELECT * FROM all_bounds WHERE ST_Intersects(ST_SetSRID(ST_MakePoint(${lng}, ${lat}), 4326),the_geom)&api_key=2J6__p_IWwUmOHYMKuMYjw&format=geojson`;
20-
//const intersectsUrl = `https://yhatmsxmjxmpgnnzdrzy.supabase.co/rest/v1/rpc/address_details?apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InloYXRtc3htanhtcGdubnpkcnp5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDM2OTA4OTQsImV4cCI6MjA1OTI2Njg5NH0.03AZcgwuHf2fAzIuCq8-O8UcSGVGfmvNdMYT6FH08b0&p_lng=${lng}&p_lat=${lat}`;
21-
const intersectsUrl = `https://ycdpugzzikjzmnatwzsq.supabase.co/rest/v1/rpc/address_details?apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InljZHB1Z3p6aWtqem1uYXR3enNxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDU1MjQ1ODcsImV4cCI6MjA2MTEwMDU4N30.Yp8yESCWzz5ccqaP1crVwRJS50jDYCcK_2Qk2aEoZVg&p_lng=${lng}&p_lat=${lat}`;
19+
const intersectsUrl = `https://bm-api.beta.nyc/pt_int?p_lng=${lng}&p_lat=${lat}`;
2220
const options = {
2321
headers: {
2422
'Accept': 'application/geo+json'

src/components/Sidebar/BoundaryDetails.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@
162162
onClick={() => ($selectedDistrict = district.properties?.namecol)}
163163
icon={layers[district.properties?.id].icon}
164164
nameCol={district.properties?.namecol}
165-
area={district.properties?.area}
166-
searea={district.properties?.searea}
165+
intersection_pct={district.properties?.intersection_pct}
167166
formatContent={layers[district.properties?.id].formatContent}
168167
formatUrl={layers[district.properties?.id].formatUrl}
169168
/>

src/components/Sidebar/CoordinateDetails.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
async function queryAllDistrictsForCoordinates(lngLat: LngLat) {
2121
districtsIntersectingAddress = [];
2222
isLoading = true;
23-
//const intersectsUrl = `https://betanyc.carto.com/api/v2/sql/?q=SELECT * FROM all_bounds WHERE ST_Intersects(ST_SetSRID(ST_MakePoint(${lngLat.lng}, ${lngLat.lat}), 4326),the_geom)&api_key=2J6__p_IWwUmOHYMKuMYjw&format=geojson`;
24-
//const intersectsUrl = `https://yhatmsxmjxmpgnnzdrzy.supabase.co/rest/v1/rpc/address_details?apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InloYXRtc3htanhtcGdubnpkcnp5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDM2OTA4OTQsImV4cCI6MjA1OTI2Njg5NH0.03AZcgwuHf2fAzIuCq8-O8UcSGVGfmvNdMYT6FH08b0&p_lng=${lngLat.lng}&p_lat=${lngLat.lat}`;
25-
const intersectsUrl = `https://ycdpugzzikjzmnatwzsq.supabase.co/rest/v1/rpc/address_details?apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InljZHB1Z3p6aWtqem1uYXR3enNxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDU1MjQ1ODcsImV4cCI6MjA2MTEwMDU4N30.Yp8yESCWzz5ccqaP1crVwRJS50jDYCcK_2Qk2aEoZVg&p_lng=${lngLat.lng}&p_lat=${lngLat.lat}`;
23+
const intersectsUrl = `https://bm-api.beta.nyc/pt_int?p_lng=${lngLat.lng}&p_lat=${lngLat.lat}`;
2624
const options = {
2725
headers: {
2826
'Accept': 'application/geo+json'

src/components/Sidebar/DistrictCopyClipboard.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
//filter for features with the layerId, then pull out the name and searea
1212
const features = districts
1313
.filter(district => district.properties?.id === layerId)
14-
.map(({ properties: { searea, area, namecol } }) => [
14+
.map(({ properties: { intersection_pct, namecol } }) => [
1515
layerMeta.name,
1616
namecol,
17-
searea / area
17+
intersection_pct
1818
]);
1919
2020
return [...rows, ...features];

src/components/Sidebar/DistrictDetails.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
boundId: string,
3434
featureId: string
3535
) {
36-
const intersectsUrl = `https://ycdpugzzikjzmnatwzsq.supabase.co/rest/v1/rpc/district_details?apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InljZHB1Z3p6aWtqem1uYXR3enNxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDU1MjQ1ODcsImV4cCI6MjA2MTEwMDU4N30.Yp8yESCWzz5ccqaP1crVwRJS50jDYCcK_2Qk2aEoZVg&boundid=${boundId}&featureid=${featureId}`;
36+
const intersectsUrl = `https://bm-api.beta.nyc/district_int?boundid=${boundId}&featureid=${featureId}`;
3737
const options = {
3838
headers: {
3939
'Accept': 'application/geo+json'

src/components/Sidebar/DistrictLink.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
export let formatContent: Function;
66
export let formatUrl: Function | undefined = undefined;
77
export let nameCol: string;
8-
export let area: number;
9-
export let searea: number;
8+
export let intersection_pct: number | string | undefined = undefined;
109
export let icon: string;
1110
12-
$: intersectingPercentage = ((searea / area) * 100).toFixed(1) + '%';
11+
$: intersectingPercentage = intersection_pct !== undefined ?
12+
(typeof intersection_pct === 'number' ? intersection_pct.toFixed(1) : parseFloat(intersection_pct).toFixed(1)) + '%' : '';
1313
</script>
1414

1515
<div
@@ -28,7 +28,7 @@
2828
<div class="flex flex-row">
2929
{formatContent(nameCol)}
3030
</div>
31-
{#if area}
31+
{#if intersection_pct}
3232
<p class="text-gray-500 tabular-nums ml-2">
3333
{intersectingPercentage}
3434
</p>

src/components/Sidebar/OverlapList.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@
9090
}}
9191
icon={layers[district.properties?.id].icon}
9292
nameCol={district.properties?.namecol}
93-
area={district.properties?.area}
94-
searea={district.properties?.searea}
93+
intersection_pct={district.properties?.intersection_pct}
9594
formatContent={layers[district.properties?.id].formatContent}
9695
formatUrl={layers[district.properties?.id].formatUrl}
9796
/>

0 commit comments

Comments
 (0)