Changeset 9549 for src/django_gheat/wlheatmap/tile.py
- Timestamp:
- Aug 23, 2011, 8:38:09 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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")
Note:
See TracChangeset
for help on using the changeset viewer.