Changeset 9150


Ignore:
Timestamp:
May 5, 2011, 9:54:10 AM (14 years ago)
Author:
rick
Message:
  • Added whole bunch of comments to make code better understandable.
  • Removed the invocation of the test code, as this is not the way is should be (either command or testcase).
  • Made the (for reference only) PIL libary optional.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/website/tile.py

    r9149 r9150  
    11#!/usr/bin/env python
    22#
    3 # Hack to show image generation realtime, sample tile server implementation
     3# Hack to show image generation realtime, sample tile server implementation.
    44#
    55# Rick van der Zwet <info@rickvanderzwet.nl>
    6 from PIL import Image
    76from django.core.management import setup_environ
    87from django.http import HttpResponse
    98from gheat.models import *
    10 import ImageDraw
    119import logging
    12 import numpy as np
    1310import pygame
    1411import sys
    1512import tempfile
     13
     14# Rending with PIL and computation with numpy has proven to be to slow to be
     15# usable, but is still in here for refence purposes.
     16try:
     17  from PIL import Image
     18  import ImageDraw
     19  import numpy as np
     20except ImportError:
     21  pass
    1622
    1723logging.basicConfig(level=logging.WARNING)
     
    129135
    130136def make_tile(x,y,z):
    131   """ Crude attempt to generate tiles, by placing a gradient circle on a
     137  """
     138  Crude attempt to generate tiles, by placing a gradient circle on a
    132139  coordinate point.  Generate a larger tile  and make sure to plot related
    133140  points first and then crop it to the required size (250x250).
    134141 
    135142  Many stuff NOT implemented yet, like:
    136   - Caching Images
     143  - Caching Images.
     144  - Conditional Filtering of Meting to allow display of sub-results.
     145  - Defining a extra level of transparency if you like to layer multiple tiles
     146    on top of each-other.
     147  - Color variation, allow the user to dynamically choose a the colour the
     148    points to be.
     149  - Advanced data plotting, like trying to guess the remainder points.
    137150  """
     151 
    138152  SIZE = 250
    139153 
     
    163177  lat_max = 0
    164178  lon_max = 0
     179 
     180  # TODO: This is currently hard-coded to display _all_ metingen
    165181  metingen = Meting.objects.select_related().filter(
    166182     latitude__lte=nw_deg.lat,latitude__gte=se_deg.lat,
     
    168184 
    169185  def dif(x,y):
     186    """ Return difference between two points """
    170187    return max(x,y) - min(x,y)
    171188 
     
    178195    ycoord = dif(nw_deg.lat,meting.latitude) / (resolution_deg.lat)
    179196    log.info(meting.accespoint.ssid, meting.latitude, meting.longitude, xcoord, ycoord)
    180     # The radius relates to the zoom-level we are in, and should represent
     197
     198    # XXX: The radius relates to the zoom-level we are in, and should represent
    181199    # a fixed distance, given the scale. Assume signal/distance to be lineair
    182200    # such that signal 100% = 100m and 1% = 1m.
     
    184202    # XXX: The relation is not lineair but from a more logeritmic scape, as we
    185203    # are dealing with radio signals
     204    #
     205    # TODO: Please note that this 'logic' technically does any apply to WiFi signals,
     206    # if you are plotting from the 'source'. With measured data you get
     207    # different patterns.
     208    #
    186209    im.add_circle((xcoord,ycoord),float(meting.signaal) / meters_per_pixel,(255,0,0))
    187210 
     
    204227  im.write(response,'png')
    205228  return response
    206 
    207 if __name__ == '__main__':
    208   log.setLevel(logging.DEBUG)
    209   x = int(sys.argv[1])
    210   y = int(sys.argv[2])
    211   z = 14
    212 
    213   im = make_tile(x,y,z)
    214   filename = 'sample-gradient.png'
    215   im.write(open(filename,'w'))
    216   log.info("Output saved as '%s'" % filename)
Note: See TracChangeset for help on using the changeset viewer.