From 5c06c72e353c58c97e9bd8145a1e561b0e321738 Mon Sep 17 00:00:00 2001 From: markAking Date: Mon, 12 Sep 2016 13:35:26 -0400 Subject: [PATCH 1/2] adding city of rochester back on to the maps. add new route patterens for handling different cities --- ebdjango/urls.py | 5 +- maps/urls.py | 7 -- maps/views.py | 73 +++++++++++++----- templates/nyc.html | 4 +- templates/rochester.html | 156 ++++++++++++++++++++++++--------------- 5 files changed, 155 insertions(+), 90 deletions(-) delete mode 100644 maps/urls.py diff --git a/ebdjango/urls.py b/ebdjango/urls.py index ffe5376..4781e23 100644 --- a/ebdjango/urls.py +++ b/ebdjango/urls.py @@ -19,7 +19,8 @@ from maps import views urlpatterns = [ url(r'^$', views.index, name='index'), - url(r'^tile/15/(?P[0-9]+)/(?P[0-9]+)/$', views.tile, name='tile'), - url(r'^nyc/', include('maps.urls')), + url(r'^(?P[\w-]+)/$', views.index, name='index'), + url(r'^(?P[\w-]+)/building_detail/', views.building_detail, name='building_detail'), + url(r'^tile/15/(?P[0-9]+)/(?P[0-9]+)/$', views.tile, name='tile') # url(r'^admin/', admin.site.urls), ] diff --git a/maps/urls.py b/maps/urls.py deleted file mode 100644 index 68c82f2..0000000 --- a/maps/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.conf.urls import url -from . import views - -urlpatterns = [ - url(r'^$', views.index, name='index'), - url(r'^building_detail/', views.building_detail, name='building_detail') -] \ No newline at end of file diff --git a/maps/views.py b/maps/views.py index b2f2ce6..408cae2 100644 --- a/maps/views.py +++ b/maps/views.py @@ -10,21 +10,33 @@ import pymongo from pymongo import MongoClient from django.http import JsonResponse -def arcgis(building_id): +def arcgis_nyc(building_id): url = 'http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0/query?where=1=1&objectIds=%s&outFields=*&outSR=4326&f=geojson' % building_id response = urlopen(url) reader = codecs.getreader("utf-8") return json.load(reader(response)) +def arcgis_roc(building_id): + url = 'http://maps.cityofrochester.gov/arcgis/rest/services/App_PropertyInformation/ROC_Parcel_Query_SDE/MapServer/0/query??where=1=1&objectIds=%s&outFields=*&f=pjson' % building_id + response = urlopen(url) + reader = codecs.getreader("utf-8") + return json.load(reader(response)) + def openMongo(): client = MongoClient(settings.MONGO_DB_URI) return client['blocmaps'] -def index(request): - template = loader.get_template('nyc.html') - context = { - 'City': 'NYC', - } +def index(request, city = 'nyc'): + if city == 'nyc': + template = loader.get_template('nyc.html') + context = { + 'City': 'NYC', + } + if city == 'roc': + template = loader.get_template('rochester.html') + context = { + 'City': 'Rochester', + } return HttpResponse(template.render(context, request)) def tile(request, tile_x, tile_y): @@ -36,20 +48,41 @@ def tile(request, tile_x, tile_y): else: return HttpResponse('') -def building_detail(request): +def building_detail(request, city = 'nyc'): bld_id = request.POST['id'] db = openMongo() - cursor = db.nyc.find({"_id": int(bld_id)}) - data = arcgis(bld_id) - for document in cursor: - if 'prediction' in document['properties']: - data['features'][0]['properties'][u'prediction'] = document['properties']['prediction'] - - if 'ped_energy' in document['properties']: - data['features'][0]['properties'][u'ped_energy'] = document['properties']['ped_energy'] - - if 'ecm' in document['properties']: - data['features'][0]['properties'][u'ecm'] = document['properties']['ecm'] - - return JsonResponse(data['features'][0]['properties']) + if city == 'nyc': + cursor = db.nyc.find({"_id": int(bld_id)}) + data = arcgis_nyc(bld_id) + + for document in cursor: + if 'prediction' in document['properties']: + data['features'][0]['properties'][u'prediction'] = document['properties']['prediction'] + + if 'ped_energy' in document['properties']: + data['features'][0]['properties'][u'ped_energy'] = document['properties']['ped_energy'] + + if 'ecm' in document['properties']: + data['features'][0]['properties'][u'ecm'] = document['properties']['ecm'] + + return JsonResponse(data['features'][0]['properties']) + + if city == 'roc': + cursor = db.roc.find({"_id": int(bld_id)}) + data = arcgis_roc(bld_id) + + for document in cursor: + data['features'][0]['attributes'][u'sqft'] = document['properties']['sqft'] + data['features'][0]['attributes'][u'age'] = document['properties']['age'] + data['features'][0]['attributes'][u'NumFloors'] = document['properties']['NumFloors'] + if 'prediction' in document['properties']: + data['features'][0]['attributes'][u'prediction'] = document['properties']['prediction'] + + if 'ped_energy' in document['properties']: + data['features'][0]['attributes'][u'ped_energy'] = document['properties']['ped_energy'] + + if 'ecm' in document['properties']: + data['features'][0]['attributes'][u'ecm'] = document['properties']['ecm'] + + return JsonResponse(data['features'][0]['attributes']) diff --git a/templates/nyc.html b/templates/nyc.html index 48bba43..806ea1e 100644 --- a/templates/nyc.html +++ b/templates/nyc.html @@ -33,8 +33,8 @@ diff --git a/templates/rochester.html b/templates/rochester.html index 8939f1d..4b17a5e 100644 --- a/templates/rochester.html +++ b/templates/rochester.html @@ -10,18 +10,18 @@ - -
+
@@ -36,7 +36,38 @@
Very Effiencient
- +
+
+

+ +
+
+

+

+
+
+

Projected Energy Consumption

+

20,000kwh

+

Type 33% less efficient than similar buildings in this area.

+
+
+

Energy Conservation Measures

+

ECM's are the recommended energy saving measures this building can take in order to dramatically conserve energy.

+
+
    +

    We can help retrofit this building, just drop us a line!

    + Contact Blocpower +
    +
    +

    We haven't generated any ECM's for this building yet, but we can. if you're the owner or manager of this building email us at info@blocpower.org +

    +
    +
    +

    Building Details

    +
    +
    +

    Do you manage or own this building?

    +
    @@ -44,66 +75,73 @@ - + // START OSMB - in blocmaps.js // + startOSMB(position, bounds, pointerdown); + -- GitLab From 39b926826f2bf463afbad2afa6ef7b73ae957f5c Mon Sep 17 00:00:00 2001 From: markAking Date: Tue, 13 Sep 2016 12:02:25 -0400 Subject: [PATCH 2/2] fixing code for PR comments --- maps/views.py | 52 +++++++++++++++++++--------------------- templates/rochester.html | 2 +- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/maps/views.py b/maps/views.py index 408cae2..d4360f5 100644 --- a/maps/views.py +++ b/maps/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.template import loader from django.conf import settings from django.core.files.storage import default_storage @@ -10,14 +10,11 @@ import pymongo from pymongo import MongoClient from django.http import JsonResponse -def arcgis_nyc(building_id): - url = 'http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0/query?where=1=1&objectIds=%s&outFields=*&outSR=4326&f=geojson' % building_id - response = urlopen(url) - reader = codecs.getreader("utf-8") - return json.load(reader(response)) - -def arcgis_roc(building_id): - url = 'http://maps.cityofrochester.gov/arcgis/rest/services/App_PropertyInformation/ROC_Parcel_Query_SDE/MapServer/0/query??where=1=1&objectIds=%s&outFields=*&f=pjson' % building_id +def arcgis(building_id, city): + if city == 'roc': + url = 'http://maps.cityofrochester.gov/arcgis/rest/services/App_PropertyInformation/ROC_Parcel_Query_SDE/MapServer/0/query??where=1=1&objectIds=%s&outFields=*&f=pjson' % building_id + else: + url = 'http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0/query?where=1=1&objectIds=%s&outFields=*&outSR=4326&f=geojson' % building_id response = urlopen(url) reader = codecs.getreader("utf-8") return json.load(reader(response)) @@ -32,11 +29,14 @@ def index(request, city = 'nyc'): context = { 'City': 'NYC', } - if city == 'roc': + elif city == 'roc': template = loader.get_template('rochester.html') context = { 'City': 'Rochester', } + else: + return HttpResponseRedirect('/nyc/') + return HttpResponse(template.render(context, request)) def tile(request, tile_x, tile_y): @@ -51,26 +51,10 @@ def tile(request, tile_x, tile_y): def building_detail(request, city = 'nyc'): bld_id = request.POST['id'] db = openMongo() - if city == 'nyc': - cursor = db.nyc.find({"_id": int(bld_id)}) - data = arcgis_nyc(bld_id) - - for document in cursor: - if 'prediction' in document['properties']: - data['features'][0]['properties'][u'prediction'] = document['properties']['prediction'] - - if 'ped_energy' in document['properties']: - data['features'][0]['properties'][u'ped_energy'] = document['properties']['ped_energy'] - - if 'ecm' in document['properties']: - data['features'][0]['properties'][u'ecm'] = document['properties']['ecm'] - - return JsonResponse(data['features'][0]['properties']) + data = arcgis(bld_id, city) if city == 'roc': cursor = db.roc.find({"_id": int(bld_id)}) - data = arcgis_roc(bld_id) - for document in cursor: data['features'][0]['attributes'][u'sqft'] = document['properties']['sqft'] data['features'][0]['attributes'][u'age'] = document['properties']['age'] @@ -86,3 +70,17 @@ def building_detail(request, city = 'nyc'): return JsonResponse(data['features'][0]['attributes']) + else: + cursor = db.nyc.find({"_id": int(bld_id)}) + for document in cursor: + if 'prediction' in document['properties']: + data['features'][0]['properties'][u'prediction'] = document['properties']['prediction'] + + if 'ped_energy' in document['properties']: + data['features'][0]['properties'][u'ped_energy'] = document['properties']['ped_energy'] + + if 'ecm' in document['properties']: + data['features'][0]['properties'][u'ecm'] = document['properties']['ecm'] + + return JsonResponse(data['features'][0]['properties']) + diff --git a/templates/rochester.html b/templates/rochester.html index 4b17a5e..a2eb11f 100644 --- a/templates/rochester.html +++ b/templates/rochester.html @@ -20,7 +20,7 @@ -- GitLab