- Timestamp:
- Jul 12, 2011, 11:10:22 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/wlheatmap/tile.py
r9188 r9392 4 4 # 5 5 # Rick van der Zwet <info@rickvanderzwet.nl> 6 from django.core.cache import cache7 6 from django.core.management import setup_environ 8 7 from django.db.models import Max 9 8 from django.http import HttpResponse 9 from django.views.decorators.cache import cache_page 10 10 from gheat.models import * 11 import logging12 11 import pygame 13 12 import sys … … 23 22 except ImportError: 24 23 pass 25 26 logging.basicConfig(level=logging.DEBUG)27 log = logging.getLogger('tile')28 24 29 25 class PyGamePicture(): … … 247 243 #im.add_point((xcoord,ycoord),float(signal_normalized) / meters_per_pixel,colour, MAX_SIGNAL - meting.signaal) 248 244 249 log.info("BoundingBox NW: %s" % nw_deg)250 log.info("BoundingBox SE: %s" % se_deg)251 log.info("")252 log.info("MetingBox NW: %.5f,%.5f" % (lat_max, lon_min))253 log.info("MetingBox SE: %.5f,%.5f" % (lat_min, lon_max))254 log.info("")255 log.info("Metingen Count: %s" % metingen.count())256 257 245 im.center_crop((SIZE,SIZE)) 258 246 return im … … 260 248 261 249 # Create your views here. 250 @cache_page(60 * 60 * 24) 262 251 def serve_tile(request,zoom,x,y): 263 """ 264 Showcase on caching and tile generation: 265 266 To make it 'easy' we use two types of caching here, memory cache expiring 267 at 30 seconds and database cache, always persistent storage on database. 268 """ 269 270 hash_key = TileCache.make_key("%s %s %s %s" % (zoom, x ,y, request.GET.urlencode())) 271 data = cache.get(hash_key) 272 273 if not data: 274 try: 275 d = TileCache.objects.get(key=hash_key) 276 data = d.data 277 cache.set(hash_key,data, 30) 278 except TileCache.DoesNotExist: 279 #log.setLevel(logging.DEBUG) 280 filter = {} 281 colour = (255,0,0) 282 for key, value in request.GET.iteritems(): 283 if key == 'colour': 284 colour = tuple(map(int,value.split(','))) 285 else: 286 filter[key] = value 287 now = time.time() 288 im = make_tile(int(x),int(y),int(zoom),filter=filter,colour=colour) 289 log.info("Processing time: %s" % (time.time() - now)) 290 data = im.get_image('png') 291 cache.set(hash_key,data, 30) 292 r = TileCache.objects.create(key=hash_key,data=data) 252 raise KeyError("foo") 253 filter = {} 254 colour = (255,0,0) 255 for key, value in request.GET.iteritems(): 256 if key == 'colour': 257 colour = tuple(map(int,value.split(','))) 258 else: 259 filter[key] = value 260 now = time.time() 261 im = make_tile(int(x),int(y),int(zoom),filter=filter,colour=colour) 262 data = im.get_image('png') 293 263 294 264 response = HttpResponse(mimetype="image/png")
Note:
See TracChangeset
for help on using the changeset viewer.