Places

The goal with this place representation is to provide a flexible enough representation to manage:


from django.db import models

# Create your models here.

## CONSTANTS
## these are fairly useless constants, don't fret over them
##

NAME_MAXLEN=30
ADDR_STREET_MAXLEN=1000
ADDR_POSTCODE_MAXLEN=20
ADDR_CITY_MAXLEN=500
ADDR_STATE_MAXLEN=500
ADDR_ISLAND_MAXLEN=500
ADDR_COUNTRY_MAXLEN=500
SPOTTER_MAXLEN = 500
OBSERVER_MAXLEN = 500

POSITION_UNITS = (('m','Meters'),('km','Kilometers'),('feet','Feet'),('Miles','miles'),('latlon','latlon'))
ORIENTATION_UNITS = (('rad','Radians'),('deg','Degrees'))
FINGERPRINT_TYPES = (('wifi','WiFi'),('bt','Bluetooth'),('acoustic','Acoustic'),('barcode','Barcode'))
CHOICE_MAXLEN = lambda c : max([ len(x[0]) for x in c ])

DECIMAL_PLACES = 30
MAX_DIGITS = 65

## 
## MODELS
## the real meat and potatoes

class Position(models.Model):
   x = models.DecimalField(max_digits=MAX_DIGITS,decimal_places=DECIMAL_PLACES)
   y = models.DecimalField(max_digits=MAX_DIGITS,decimal_places=DECIMAL_PLACES)
   z = models.DecimalField(max_digits=MAX_DIGITS,decimal_places=DECIMAL_PLACES)
   units = models.CharField(max_length=CHOICE_MAXLEN(POSITION_UNITS),choices=POSITION_UNITS)
   heading = models.DecimalField(max_digits=MAX_DIGITS,decimal_places=DECIMAL_PLACES)
   tilt = models.DecimalField(max_digits=MAX_DIGITS,decimal_places=DECIMAL_PLACES)
   roll = models.DecimalField(max_digits=MAX_DIGITS,decimal_places=DECIMAL_PLACES)
   headingunits = models.CharField(max_length=CHOICE_MAXLEN(ORIENTATION_UNITS),choices=ORIENTATION_UNITS)
   referenceFrame = models.ForeignKey('Place')

class Point(models.Model):
   ## is a Position plus order#
   index = models.IntegerField()
   coord = models.ForeignKey(Position)

class Region(models.Model):
   points = models.ManyToManyField(Point)

class Address(models.Model):
   ## TODO: This is merely a placeholder for something that is actually ISO-compliant 
   Street = models.CharField(max_length=ADDR_STREET_MAXLEN)
   City = models.CharField(max_length=ADDR_CITY_MAXLEN)
   StatePrefectureRepublic = models.CharField(max_length=ADDR_STATE_MAXLEN)
   Island = models.CharField(max_length=ADDR_ISLAND_MAXLEN)
   PostalCode = models.CharField(max_length=ADDR_POSTCODE_MAXLEN)
   Country = models.CharField(max_length=ADDR_COUNTRY_MAXLEN)

class PlaceName(models.Model):
   name =  models.CharField(max_length=NAME_MAXLEN) ## shortname

class FingerprintObservation(models.Model):
   obsdate = models.DateField()
   observer = models.CharField(max_length=OBSERVER_MAXLEN)
   data = models.XMLField()

class Fingerprint(models.Model):
   type = models.CharField(max_length=CHOICE_MAXLEN(FINGERPRINT_TYPES),choices=FINGERPRINT_TYPES)
   spotter = models.CharField(max_length=SPOTTER_MAXLEN)
   observations = models.ManyToManyField(FingerprintObservation)

class Place(models.Model):
   uri = models.SlugField()  ## uniquely identifies this place
   names = models.ManyToManyField(PlaceName)    
   address = models.ForeignKey(Address)
   region = models.ManyToManyField(Region)
   positions = models.ManyToManyField(Point)
   fingerprints = models.ManyToManyField(Fingerprint)
   contains =  models.ManyToManyField('self',related_name="containedBy",symmetrical=False)   

Places (last edited 2008-07-17 18:33:49 by MaxVanKleek)