Skip to content

Commit

Permalink
Merge branches 'main' and 'main' of https://github.com/peterprescott/…
Browse files Browse the repository at this point in the history
  • Loading branch information
devdave25 committed Oct 14, 2023
2 parents a986d3b + 27629a8 commit 4643840
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions backend/fullstack_api/resources.py
Expand Up @@ -35,6 +35,7 @@ def clean_postcode(postcode_str: str) -> str:


def get_postcode(postcode: str) -> dict:
print(postcode)
data = db.session.execute(
db.text(
f"SELECT * FROM postcode WHERE REPLACE(postcode, ' ','') = '{postcode}'"
Expand All @@ -53,7 +54,9 @@ def get_postcode(postcode: str) -> dict:
class Churches(Resource):
def get(self, postcode_str):
postcode = clean_postcode(postcode_str)
print(postcode_str)
postcode = get_postcode(postcode)["postcode"]
print(postcode)
churches = pd.read_csv(data_dir / "church_dc.csv")
postcode_district_churches = churches[
churches["postcode"].apply(lambda x: str(x).split(" ")[0])
Expand Down Expand Up @@ -91,11 +94,17 @@ def get(self, postcode_str):
).fetchone()

if data:
print(data)
return {
"success": True,
"postcode": data.postcode,
"latitude": data.latitude,
"longitude": data.longitude,
"income_score": data.income_score,
"employment_score": data.employment_score,
"education_score": data.education_score,
"health_score": data.health_score,
"crime_score": data.crime_score,
}
else:
return {
Expand Down
Binary file modified data/latlon.csv.gz
Binary file not shown.
8 changes: 7 additions & 1 deletion frontend/fullstack_ui/js/maps.js
Expand Up @@ -2,13 +2,19 @@ console.log('maps.js loading...');

async function getPostcodeCoords() {
const postcode = document.getElementById('postcode-input').value;

r = await get(API_URL + 'postcode/' + postcode);
console.log(r)
churches = await get(API_URL + 'churches/' + postcode);

count_churches = churches.length;
church_msg = 'There are ' + count_churches + ' churches in ' +
churches[0].postcode.split(' ')[0] + '.';
churches[0].postcode.split(' ')[0] + '.' + '\n' +
'Income Score: ' + r.income_score + ' // Employment Score: ' + r.employment_score + ' // Crime Score: ' + r.crime_score + ' // Health Score: ' + r.health_score + ' // Education Score: ' + r.education_score + '.' ;

msgFooter(church_msg)


churches.forEach(c => markChurch(c));

centerMap(r);
Expand Down

0 comments on commit 4643840

Please sign in to comment.