Skip to content

Commit a275135

Browse files
committed
continuation of last commit
1 parent 0d0a74a commit a275135

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

csvimport/zip_geocode.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ def importCsv(self):
3232
"AdminCode2":np.str,"AdminName3":np.str,"AdminCode3":np.str,"Latitude":np.str,"Longitude":np.str,"Accuracy":np.str})
3333

3434
df['Accuracy'] = df['Accuracy'].replace('', '-1')
35-
36-
self.storage.execute_batch_zipgeodata_insert(df)
35+
importframe = pd.DataFrame()
36+
importframe['PostalCode'] = df['PostalCode']
37+
importframe['Latitude'] = df['Latitude']
38+
importframe['Longitude'] = df['Longitude']
39+
self.storage.execute_batch_zipgeodata_insert(importframe)

install.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ def setup_logger(log_level=logging.DEBUG):
2323
zipImport = ZipGeocodeImporter()
2424
zipImport.importCsv()
2525
storage.setup_postalcode_geometry()
26-
26+

main.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
from typing import Optional
21

32
from neighbor.service import NeighborService
43

5-
from fastapi import FastAPI, File
6-
from pydantic import BaseModel, Field
4+
from fastapi import FastAPI
5+
76

8-
import logging
9-
from decimal import Decimal
107
app = FastAPI()
118

129
service = NeighborService()
1310
service.storage.connect()
1411

1512
@app.get("/nearest/{count}/{sourceType}/to/{postalCode}")
1613
async def nearest(count: int, sourceType: str, postalCode: str):
17-
return service.getNearestNeighbor(count, sourceType, postalCode)
14+
return service.getNearestNeighbor(count, sourceType, postalCode, 1000)
1815

1916
@app.get("/nearest/{count}/{sourceType}/to/{postalCode}/within/{miles}")
2017
async def nearestWithin(count: int, sourceType: str, postalCode: str, miles:int):
21-
return service.getNearestNeighborWithin(count, sourceType, postalCode, miles)
18+
return service.getNearestNeighbor(count, sourceType, postalCode, miles)

neighbor/service.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from os import getenv
22
from dotenv import load_dotenv
33
load_dotenv()
4-
4+
import json
55
import io
66
import logging
77
log = logging.getLogger()
@@ -27,13 +27,11 @@ def __exit__(self, exception, exception_value, tb):
2727

2828
self.storage.disconnect()
2929

30-
31-
def getNearestNeighbor(self, count: int, sourceType: str, postalCode: str):
30+
def getNearestNeighbor(self, count: int, sourceType: str, postalCode: str, miles: int):
3231
log.info(f"Getting {count} nearest {sourceType} to postal code {postalCode}")
33-
return self.storage.get_neighbors_by_zip(count, sourceType, postalCode)
34-
35-
def getNearestNeighborWithin(self, count: int, sourceType: str, postalCode: str, miles: int):
36-
log.info(f"Getting {count} nearest {sourceType} to postal code {postalCode}")
37-
return self.storage.get_neighbors_by_zip(count, sourceType, postalCode, miles)
38-
32+
neighbors = self.storage.get_neighbors_by_zip(count, sourceType, postalCode, miles)
33+
for neighbor in neighbors:
34+
neighbor.update(json.loads(neighbor["rowdata"]))
35+
neighbor.pop("rowdata")
3936

37+
return neighbors

0 commit comments

Comments
 (0)