Changeset 9549
- Timestamp:
- Aug 23, 2011, 8:38:09 PM (13 years ago)
- Location:
- src/django_gheat
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/settings.py
r9545 r9549 7 7 DJANGO_BALANCERS = OSM_PROXY_BALANCERS = ['a','b','c','d','e','f'] 8 8 OSM_PROXY_CDN_DOMAINS = [d + '.osmproxy.wirelessleiden.nl' for d in DJANGO_BALANCERS] 9 OSM_PREFIX = '/osm-tile-proxy' 9 10 DJANGO_CDN_DOMAINS = [d + '.maps.wirelessleiden.nl' for d in DJANGO_BALANCERS] 10 11 … … 38 39 'LOCATION': '127.0.0.1:11211', 39 40 'TIMEOUT': 3600 * 24 * 7, 41 'OPTIONS': { 42 'MAX_ENTRIES': 100000 43 } 44 }, 45 'osm_proxy': { 46 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 47 'LOCATION': '/usr/local/var/django/cache/osm_proxy', 48 'TIMEOUT': 3600 * 24 * 7, 49 'OPTIONS': { 50 'MAX_ENTRIES': 100000 51 } 52 }, 53 'tile_cache': { 54 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 55 'LOCATION': '/usr/local/var/django/cache/tile_cache', 56 'TIMEOUT': 3600 * 24, 40 57 'OPTIONS': { 41 58 'MAX_ENTRIES': 100000 -
src/django_gheat/wlheatmap/osm_proxy.py
r9398 r9549 16 16 17 17 # Create your views here. 18 @cache_page(60 * 60 * 24 * 7, key_prefix="osm_proxy")18 @cache_page(60 * 60 * 24 * 7, cache="osm_proxy") 19 19 def osm_proxy(request,zoom,x,y): 20 20 mirror = random.choice(['a','b','c']) -
src/django_gheat/wlheatmap/static/heatmap.js
r9546 r9549 59 59 map.addLayer(layerHeatmap3); 60 60 61 //layerHeatmap = new OpenLayers.Layer.OSM.Overlay1("Original Heatmap generator", {isBaseLayer: false, visibility: false});62 //map.addLayer(layerHeatmap);61 layerHeatmap = new OpenLayers.Layer.OSM.Overlay1("Original Heatmap generator", {isBaseLayer: false, visibility: false}); 62 map.addLayer(layerHeatmap); 63 63 64 64 var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); … … 73 73 */ 74 74 75 //$("#default").append("<span id=\"" + layerHeatmap.name + "\"><div id='layer_switcher_colour' style='background-color:rgb(" + layerHeatmap.colour + ")' /><input type=checkbox id=togglelayer /><font>" + layerHeatmap.name + " </font><br /></span>");75 $("#default").append("<span id=\"" + layerHeatmap.name + "\"><div id='layer_switcher_colour' style='background-color:rgb(" + layerHeatmap.colour + ")' /><input type=checkbox id=togglelayer /><font>" + layerHeatmap.name + " </font><br /></span>"); 76 76 77 77 $("#default").append("<span id=\"" + layerHeatmap2.name + "\"><div id='layer_switcher_colour' style='background-color:rgb(" + layerHeatmap2.colour + ")' /><input type=checkbox id=togglelayer /><font>" + layerHeatmap2.name + " </font><br /></span>"); -
src/django_gheat/wlheatmap/templates/js/LayerBase.js
r9544 r9549 54 54 */ 55 55 initialize: function(name, options) { 56 var url = get_balanced_urls('http://', {{ settings.OSM_PROXY_CDN_DOMAINS|safe }}, '{{ settings. DJANGO_PREFIX }}/osm-proxy/${z}/${x},${y}.png');56 var url = get_balanced_urls('http://', {{ settings.OSM_PROXY_CDN_DOMAINS|safe }}, '{{ settings.OSM_PREFIX }}/${z}/${x}/${y}.png'); 57 57 options = OpenLayers.Util.extend({ numZoomLevels: 19 }, options); 58 58 var newArguments = [name, url, options]; -
src/django_gheat/wlheatmap/tile.py
r9398 r9549 9 9 from django.views.decorators.cache import cache_page 10 10 from gheat.models import * 11 import os 11 12 import pygame 12 13 import sys … … 36 37 self.surf = new_surf 37 38 38 def write(self, fh,format='png'): 39 # XXX: How to get a PNG stream directly to the output 40 f = tempfile.NamedTemporaryFile(suffix=format) 41 pygame.image.save(self.surf,f.name) 42 f.seek(0) 43 fh.write(f.read()) 39 def save_and_get_image(self,filename): 40 """ Save the file to the location and return the file """ 41 basedir = os.path.dirname(filename) 42 if not os.path.isdir(basedir): 43 os.makedirs(basedir) 44 pygame.image.save(self.surf,filename) 45 return open(filename,'r').read() 44 46 45 47 def get_image(self,format='png'): … … 48 50 f.seek(0) 49 51 return f.read() 52 50 53 51 54 … … 199 202 'longitude__gte' : nw_deg.lon 200 203 }) 201 # TODO: This is currently hard-coded to display _all_ metingen202 metingen = Meting.objects. select_related().filter(**filter)204 # Limit such that high level zooms does not get the whole database 205 metingen = Meting.objects.filter(**filter)[:1000].values_list('latitude', 'longitude', 'signaal') 203 206 204 207 # XXX: Signal is not normalized in the database making it unknown when a … … 219 222 return max(x,y) - min(x,y) 220 223 221 for metingin metingen:222 lat_min = min(lat_min, meting.latitude)223 lat_max = max(lat_max, meting.latitude)224 lon_min = min(lon_min, meting.longitude)225 lon_max = max(lon_max, meting.longitude)226 xcoord = int(dif(nw_deg.lon, meting.longitude) / (resolution_deg.lon))227 ycoord = int(dif(nw_deg.lat, meting.latitude) / (resolution_deg.lat))224 for (latitude, longitude, signaal) in metingen: 225 lat_min = min(lat_min, latitude) 226 lat_max = max(lat_max, latitude) 227 lon_min = min(lon_min, longitude) 228 lon_max = max(lon_max, longitude) 229 xcoord = int(dif(nw_deg.lon,longitude) / (resolution_deg.lon)) 230 ycoord = int(dif(nw_deg.lat,latitude) / (resolution_deg.lat)) 228 231 229 232 # TODO: Please note that this 'logic' technically does apply to WiFi signals, … … 239 242 # with examples like this: 240 243 # http://stackoverflow.com/questions/3104781/inverse-distance-weighted-idw-interpolation-with-python 241 signal_normalized = MAX_RANGE - (MAX_SIGNAL - meting.signaal)242 im.add_circle((xcoord,ycoord),float(signal_normalized) / meters_per_pixel,colour, MAX_SIGNAL - meting.signaal)244 signal_normalized = MAX_RANGE - (MAX_SIGNAL - signaal) 245 im.add_circle((xcoord,ycoord),float(signal_normalized) / meters_per_pixel,colour, MAX_SIGNAL - signaal) 243 246 #im.add_point((xcoord,ycoord),float(signal_normalized) / meters_per_pixel,colour, MAX_SIGNAL - meting.signaal) 244 247 … … 246 249 return im 247 250 248 249 # Create your views here. 250 @cache_page(60 * 60 * 24, key_prefix="wlheatmap_tile") 251 def serve_tile(request,zoom,x,y): 251 def pre_process_tile(request,zoom,x,y): 252 252 filter = {} 253 253 colour = (255,0,0) … … 259 259 now = time.time() 260 260 im = make_tile(int(x),int(y),int(zoom),filter=filter,colour=colour) 261 return im 262 263 # Create your views here. 264 @cache_page(60 * 60 * 24, cache="tile_cache") 265 def serve_tile(request,zoom,x,y): 266 im = pre_process_tile(request,zoom,x,y) 261 267 data = im.get_image('png') 262 263 response = HttpResponse(mimetype="image/png") 264 response.write(data) 265 return response 266 268 return HttpResponse(data,mimetype="image/png") 269 270 def fixed_wl_only(request,zoom,x,y): 271 """ Pre-render and save attempt """ 272 im = pre_process_tile(request,zoom,x,y) 273 data = im.save_and_get_image('/usr/local/var/django/tile/fixed/wl-only/%s/%s,%s.png' % (zoom, x, y)) 274 return HttpResponse(data,mimetype="image/png") -
src/django_gheat/wlheatmap/urls.py
r9544 r9549 14 14 url(r'^$', direct_to_template, {'template' : 'home.html'}), 15 15 url(r'^js/LayerBase.js$', 'js_layer_base'), 16 url(r'^tile/fixed/wl-only/(?P<zoom>\d+)/(?P<x>\d+),(?P<y>\d+).png$', 'tile.fixed_wl_only'), 16 17 url(r'^tile/(?P<zoom>\d+)/(?P<x>\d+),(?P<y>\d+).png$', 'tile.serve_tile'), 17 18 url(r'^nodelist/(?P<zoom>\d+),(?P<lat>[0-9.]+),(?P<lon>[0-9.]+)$', 'nodelist.serve_nodelist'),
Note:
See TracChangeset
for help on using the changeset viewer.