From 88e9dfb42f614bf5a90e87084a3326040e289662 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Fri, 13 Dec 2019 16:32:41 -0500 Subject: [PATCH 1/7] nyc zip --- bloclink/apps/bis/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bloclink/apps/bis/views.py b/bloclink/apps/bis/views.py index 77444b8..e137816 100644 --- a/bloclink/apps/bis/views.py +++ b/bloclink/apps/bis/views.py @@ -38,7 +38,7 @@ class SubmitBuilding(View): country = address[-1] zip = int(address[-2].split(" ")[-1]) if country == " United States": - if 10001 <= zip <= 11697: + if 10001 <= zip <= 11429: surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='NYC')[0].id) elif 94501 <= zip <= 94705: surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='Oakland')[0].id) -- GitLab From 27f3a847f0d1b15ba025807eff80d082d61f4140 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Thu, 9 Jan 2020 16:10:50 -0500 Subject: [PATCH 2/7] new library --- bloclink/apps/bis/views.py | 1 + requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bloclink/apps/bis/views.py b/bloclink/apps/bis/views.py index e137816..8c9c2e0 100644 --- a/bloclink/apps/bis/views.py +++ b/bloclink/apps/bis/views.py @@ -20,6 +20,7 @@ from django.template.loader import render_to_string from django.core.mail import EmailMessage from django.db import connections import re +import uszipcode class SubmitBuilding(View): def put(self, request): diff --git a/requirements.txt b/requirements.txt index e0bd14e..92a0a7a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -git+https://[YOUR-GITHUB-TOKEN]:x-oauth-basic@github.com/Blocp/bpengine.git@v0.8.5 +git+https://ecb14bb2a11a108a1664b899a97d88c73e004c39:x-oauth-basic@github.com/Blocp/bpengine.git@v0.8.6 celery==4.0.2 Django==1.10.6 numpy==1.17.4 @@ -13,3 +13,4 @@ python-pptx==0.6.18 django-cors-headers==2.1.0 djangorestframework==3.10.2 boto3==1.9.214 +uszipcode==0.2.4 \ No newline at end of file -- GitLab From 69633fdde34d0e2c41f05d6511598964e9f3000c Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Fri, 10 Jan 2020 11:01:44 -0500 Subject: [PATCH 3/7] Solved isuue of zipcodes --- bloclink/apps/bis/views.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bloclink/apps/bis/views.py b/bloclink/apps/bis/views.py index 8c9c2e0..5417055 100644 --- a/bloclink/apps/bis/views.py +++ b/bloclink/apps/bis/views.py @@ -20,7 +20,7 @@ from django.template.loader import render_to_string from django.core.mail import EmailMessage from django.db import connections import re -import uszipcode +from uszipcode import SearchEngine class SubmitBuilding(View): def put(self, request): @@ -35,21 +35,29 @@ class SubmitBuilding(View): # Get Survey ID from entered address address = put['address'].split(",") + nyc_area = ['New York', 'Brooklyn', 'Queens', 'Bronx', 'Staten Island'] if (len(address) > 3): country = address[-1] - zip = int(address[-2].split(" ")[-1]) - if country == " United States": - if 10001 <= zip <= 11429: + zip = address[-2].split(" ")[-1] + if zip and country == " United States": + search = SearchEngine(simple_zipcode=True) + zipcode = search.by_zipcode(zip) + if zipcode.major_city in nyc_area and zipcode.state == 'NY': surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='NYC')[0].id) - elif 94501 <= zip <= 94705: + elif zipcode.major_city == 'Oakland' and zipcode.state == 'CA': surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='Oakland')[0].id) - elif 53201 <= zip <= 53295: + elif zipcode.major_city == 'Milwaukee' and zipcode.state == 'WI': surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='Milwaukee')[0].id) else: return JsonResponse({ 'success': False, 'message': 'Sorry! Area not covered at the moment.' }, status=400) + else: + return JsonResponse({ + 'success': False, + 'message': 'Please enter proper address.' + }, status=400) else: return JsonResponse({ 'success': False, -- GitLab From 9a15b18b388b148a0b0b4c2feec9cc3c373af88e Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Fri, 10 Jan 2020 12:01:51 -0500 Subject: [PATCH 4/7] Solved isuue of zipcodes --- bloclink/apps/bis/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bloclink/apps/bis/views.py b/bloclink/apps/bis/views.py index 5417055..12638d0 100644 --- a/bloclink/apps/bis/views.py +++ b/bloclink/apps/bis/views.py @@ -39,7 +39,7 @@ class SubmitBuilding(View): if (len(address) > 3): country = address[-1] zip = address[-2].split(" ")[-1] - if zip and country == " United States": + if zip.isnumeric() == True and country == " United States": search = SearchEngine(simple_zipcode=True) zipcode = search.by_zipcode(zip) if zipcode.major_city in nyc_area and zipcode.state == 'NY': -- GitLab From 97a074656642eec7c2c5a8b6b59b968268697de5 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Fri, 10 Jan 2020 12:45:29 -0500 Subject: [PATCH 5/7] BI-742 --- bloclink/apps/bis/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bloclink/apps/bis/views.py b/bloclink/apps/bis/views.py index 12638d0..2f32b70 100644 --- a/bloclink/apps/bis/views.py +++ b/bloclink/apps/bis/views.py @@ -35,14 +35,14 @@ class SubmitBuilding(View): # Get Survey ID from entered address address = put['address'].split(",") - nyc_area = ['New York', 'Brooklyn', 'Queens', 'Bronx', 'Staten Island'] + nyc_area = ['New York County', 'Kings County', 'Queens County', 'Bronx County', 'Richmond County'] if (len(address) > 3): country = address[-1] zip = address[-2].split(" ")[-1] if zip.isnumeric() == True and country == " United States": search = SearchEngine(simple_zipcode=True) zipcode = search.by_zipcode(zip) - if zipcode.major_city in nyc_area and zipcode.state == 'NY': + if zipcode.county in nyc_area and zipcode.state == 'NY': surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='NYC')[0].id) elif zipcode.major_city == 'Oakland' and zipcode.state == 'CA': surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='Oakland')[0].id) -- GitLab From db96814085d6f808ae7cd7c2661dcd607728f4e1 Mon Sep 17 00:00:00 2001 From: Jinal Soni <22827279+Jinal-7@users.noreply.github.com> Date: Fri, 10 Jan 2020 15:22:43 -0500 Subject: [PATCH 6/7] Update requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 92a0a7a..82b1092 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -git+https://ecb14bb2a11a108a1664b899a97d88c73e004c39:x-oauth-basic@github.com/Blocp/bpengine.git@v0.8.6 +git+https://[YOUR-GITHUB-TOKEN]:x-oauth-basic@github.com/Blocp/bpengine.git@v0.8.6 celery==4.0.2 Django==1.10.6 numpy==1.17.4 @@ -13,4 +13,4 @@ python-pptx==0.6.18 django-cors-headers==2.1.0 djangorestframework==3.10.2 boto3==1.9.214 -uszipcode==0.2.4 \ No newline at end of file +uszipcode==0.2.4 -- GitLab From beb14713c9d88e1a134a69e1d240a33e29301eb3 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Fri, 10 Jan 2020 16:28:02 -0500 Subject: [PATCH 7/7] Code Refactoring --- bloclink/apps/bis/views.py | 75 +++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/bloclink/apps/bis/views.py b/bloclink/apps/bis/views.py index 2f32b70..33f426d 100644 --- a/bloclink/apps/bis/views.py +++ b/bloclink/apps/bis/views.py @@ -36,49 +36,50 @@ class SubmitBuilding(View): # Get Survey ID from entered address address = put['address'].split(",") nyc_area = ['New York County', 'Kings County', 'Queens County', 'Bronx County', 'Richmond County'] - if (len(address) > 3): - country = address[-1] - zip = address[-2].split(" ")[-1] - if zip.isnumeric() == True and country == " United States": - search = SearchEngine(simple_zipcode=True) - zipcode = search.by_zipcode(zip) - if zipcode.county in nyc_area and zipcode.state == 'NY': - surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='NYC')[0].id) - elif zipcode.major_city == 'Oakland' and zipcode.state == 'CA': - surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='Oakland')[0].id) - elif zipcode.major_city == 'Milwaukee' and zipcode.state == 'WI': - surveyId = int(SurveyAreas.objects.using('bis').filter(area_name='Milwaukee')[0].id) - else: - return JsonResponse({ - 'success': False, - 'message': 'Sorry! Area not covered at the moment.' - }, status=400) - else: - return JsonResponse({ - 'success': False, - 'message': 'Please enter proper address.' + if len(address) <= 3: + return JsonResponse({ + 'success': False, + 'message': 'Please enter street address.' }, status=400) - else: + + zip = address[-2].split(" ")[-1] + if not (zip.isnumeric() and address[-1] == " United States"): return JsonResponse({ - 'success': False, - 'message': 'Please enter street address.' + 'success': False, + 'message': 'Please enter proper address.' }, status=400) - - data['surveyId'] = surveyId - Id_array = list(Surveys.objects.using('bis').filter(survey_area_id=surveyId)) + + search = SearchEngine(simple_zipcode=True) + zipcode = search.by_zipcode(zip) + surveyAreas = SurveyAreas.objects.using('bis') + + area_name = '' + if zipcode.county in nyc_area and zipcode.state == 'NY': + area_name='NYC' + elif zipcode.major_city == 'Oakland' and zipcode.state == 'CA': + area_name='Oakland' + elif zipcode.major_city == 'Milwaukee' and zipcode.state == 'WI': + area_name='Milwaukee' + + if area_name == '': + return JsonResponse({ + 'success': False, + 'message': 'Sorry! Area not covered at the moment.' + }, status=400) + + data['surveyId'] = int(surveyAreas.filter(area_name=area_name)[0].id) + Id_array = list(Surveys.objects.using('bis').filter(survey_area_id=data['surveyId'])) for Id in Id_array: - queID = Id.que_id - ansId = Id.ans_id + queIDs = Id.que_id + ansIds = Id.ans_id - for j in queID: - questions = Questions.objects.using('bis').filter(id=j) - for question in questions: - data['questions'][question.id] = question.question + questions = Questions.objects.using('bis').filter(id__in=queIDs) + for question in questions: + data['questions'][question.id] = question.question - for k in ansId: - answers = Answers.objects.using('bis').filter(id=k) - for answer in answers: - data['answers'][answer.id] = answer.answer + answers = Answers.objects.using('bis').filter(id__in=ansIds) + for answer in answers: + data['answers'][answer.id] = answer.answer # Get buildingId from the address try: -- GitLab