[9026] | 1 | import datetime
|
---|
[9006] | 2 |
|
---|
[9184] | 3 | from django.core import validators
|
---|
| 4 | from django.db import models
|
---|
| 5 |
|
---|
[9664] | 6 | MIN_SIGNAL = 0
|
---|
| 7 | MAX_SIGNAL = 100
|
---|
[9638] | 8 |
|
---|
[9819] | 9 | ACCESSPOINT_TYPE_CHOICES= (
|
---|
| 10 | ('accesspoint', 'Acess Point'),
|
---|
[9818] | 11 | ('interlink', 'InterLink'),
|
---|
| 12 | )
|
---|
[9664] | 13 |
|
---|
| 14 | # http://stackoverflow.com/questions/849142/how-to-limit-the-maximum-value-of-a-numeric-field-in-a-django-model/849426#849426
|
---|
| 15 | class IntegerRangeField(models.IntegerField):
|
---|
| 16 | def __init__(self, verbose_name=None, name=None, min_value=None, max_value=None, **kwargs):
|
---|
| 17 | self.min_value, self.max_value = min_value, max_value
|
---|
| 18 | models.IntegerField.__init__(self, verbose_name, name, **kwargs)
|
---|
| 19 | def formfield(self, **kwargs):
|
---|
| 20 | defaults = {'min_value': self.min_value, 'max_value':self.max_value}
|
---|
| 21 | defaults.update(kwargs)
|
---|
| 22 | return super(IntegerRangeField, self).formfield(**defaults)
|
---|
| 23 |
|
---|
| 24 |
|
---|
[9562] | 25 | class WirelessClient(models.Model):
|
---|
| 26 | mac = models.CharField(max_length=17, unique=True)
|
---|
| 27 | def __unicode__(self):
|
---|
| 28 | return self.mac
|
---|
[9184] | 29 |
|
---|
[9579] | 30 |
|
---|
[9592] | 31 | class Organization(models.Model):
|
---|
| 32 | fullname = models.CharField(max_length=100,unique=True)
|
---|
| 33 | name = models.CharField(max_length=100,unique=True)
|
---|
| 34 | def __unicode__(self):
|
---|
| 35 | return self.fullname
|
---|
[9579] | 36 |
|
---|
[9592] | 37 | @staticmethod
|
---|
| 38 | def get_name_by_ssid(ssid):
|
---|
| 39 | """ Try to determine the organization via the SSID """
|
---|
[9593] | 40 | ssid = ssid.lower()
|
---|
[9592] | 41 | name = None
|
---|
| 42 | if ssid.startswith('ap') and ssid.endswith('wleiden.net'):
|
---|
| 43 | name = 'WirelessLeiden'
|
---|
[9593] | 44 | elif ssid.startswith('il-') and ssid.endswith('wleiden.net'):
|
---|
[9592] | 45 | name = 'WirelessLeiden'
|
---|
[9593] | 46 | elif ssid.startswith('ap') and 'wirelessleiden' in ssid:
|
---|
| 47 | name = 'WirelessLeiden'
|
---|
| 48 | elif ssid.startswith('ap-') and 'westeinder' in ssid:
|
---|
| 49 | name = 'WirelessPlassen'
|
---|
| 50 | elif ssid.endswith('walphen.net'):
|
---|
| 51 | name = 'WirelessAlphen'
|
---|
| 52 | elif 'wirelessarnhem' in ssid:
|
---|
| 53 | name = 'WirelessArnhem'
|
---|
[9592] | 54 | return name
|
---|
| 55 |
|
---|
[9593] | 56 | @staticmethod
|
---|
| 57 | def get_by_ssid(ssid):
|
---|
| 58 | name = Organization.get_name_by_ssid(ssid)
|
---|
| 59 | if not name:
|
---|
| 60 | return None
|
---|
| 61 | else:
|
---|
| 62 | return Organization.objects.get(name=name)
|
---|
| 63 |
|
---|
| 64 |
|
---|
[9590] | 65 | class Node(models.Model):
|
---|
[9593] | 66 | name = models.CharField(max_length=50, unique=True)
|
---|
[9590] | 67 | latitude = models.FloatField(null=True,blank=True)
|
---|
| 68 | longitude = models.FloatField(null=True,blank=True)
|
---|
[9592] | 69 | organization = models.ForeignKey(Organization,null=True, blank=True)
|
---|
[9590] | 70 |
|
---|
[9592] | 71 | def __unicode__(self):
|
---|
| 72 | return "%s - %s" % (self.name, self.organization)
|
---|
| 73 |
|
---|
[9819] | 74 | class Accesspoint(models.Model):
|
---|
[9053] | 75 | mac = models.CharField(max_length=17)
|
---|
| 76 | ssid = models.CharField(max_length=64)
|
---|
[9819] | 77 | type = models.CharField(max_length=20, null=True, blank=True, choices=ACCESSPOINT_TYPE_CHOICES)
|
---|
[9592] | 78 | organization = models.ForeignKey(Organization,null=True, blank=True)
|
---|
[9053] | 79 | encryptie = models.BooleanField()
|
---|
[9562] | 80 | class Meta:
|
---|
| 81 | unique_together = ('mac', 'ssid')
|
---|
[9053] | 82 | def __unicode__(self):
|
---|
| 83 | return "%s - %s" % (self.mac, self.ssid)
|
---|
[9006] | 84 |
|
---|
[9818] | 85 | @staticmethod
|
---|
| 86 | def get_type_by_ssid(ssid):
|
---|
| 87 | if ssid.startswith('ap'):
|
---|
[9819] | 88 | type = 'accesspoint'
|
---|
[9818] | 89 | elif ssid.startswith('il'):
|
---|
| 90 | type = 'interlink'
|
---|
| 91 | else:
|
---|
| 92 | type = None
|
---|
| 93 | return type
|
---|
[9579] | 94 |
|
---|
| 95 | def save(self, *args, **kwargs):
|
---|
[9819] | 96 | super(Accesspoint, self).save(*args, **kwargs)
|
---|
[9579] | 97 |
|
---|
[9026] | 98 | class Gebruiker(models.Model):
|
---|
[9053] | 99 | naam = models.CharField(max_length=64)
|
---|
| 100 | email = models.CharField(max_length=64)
|
---|
| 101 | def __unicode__(self):
|
---|
| 102 | return "%s - %s" % (self.naam, self.email)
|
---|
[9026] | 103 |
|
---|
[9041] | 104 | class Apparatuur(models.Model):
|
---|
[9659] | 105 | antenne = models.CharField(max_length=64, default="onbekend")
|
---|
| 106 | kaart = models.CharField(max_length=64, default="onbekend")
|
---|
[9053] | 107 | def __unicode__(self):
|
---|
| 108 | return "%s - %s" % (self.antenne, self.kaart)
|
---|
[9633] | 109 | class Meta:
|
---|
| 110 | verbose_name_plural = 'Apparatuur'
|
---|
[9659] | 111 | unique_together = ('antenne', 'kaart')
|
---|
[9026] | 112 |
|
---|
[9041] | 113 | class MeetRondje(models.Model):
|
---|
[9633] | 114 | datum = models.DateTimeField(blank=True,null=True,default=datetime.datetime.now)
|
---|
[9097] | 115 | naam = models.CharField(max_length=64)
|
---|
[9053] | 116 | gebruiker = models.ForeignKey(Gebruiker)
|
---|
| 117 | apparatuur = models.ForeignKey(Apparatuur)
|
---|
| 118 | def __unicode__(self):
|
---|
[9054] | 119 | return "%s - %s" % (self.gebruiker.naam, self.naam)
|
---|
[9633] | 120 | class Meta:
|
---|
| 121 | verbose_name_plural = 'MeetRondjes'
|
---|
[9041] | 122 |
|
---|
[9747] | 123 | FILE_TYPES = (
|
---|
| 124 | ( 'netxml', 'Netstumbler NetXML'),
|
---|
| 125 | ( 'gpsxml', 'Netstumbler GPSXML'),
|
---|
| 126 | ( 'droidcsv', 'DroidStumbler CSV'),
|
---|
| 127 | )
|
---|
| 128 |
|
---|
[9395] | 129 | class MeetBestand(models.Model):
|
---|
| 130 | meetrondje = models.ForeignKey(MeetRondje)
|
---|
[9660] | 131 | bestand = models.FileField(upload_to='scan-data/%Y/%m/%d')
|
---|
[9747] | 132 | filetype = models.CharField(max_length=64,choices=FILE_TYPES,default='netxml')
|
---|
| 133 | is_imported = models.BooleanField(default=False,help_text="This field get set the moment the data is processed into the database")
|
---|
[9633] | 134 | class Meta:
|
---|
| 135 | verbose_name_plural = 'MeetBestanden'
|
---|
[9660] | 136 | unique_together = ('meetrondje', 'bestand')
|
---|
[9637] | 137 | def __unicode__(self):
|
---|
| 138 | return "%s - %s" % (self.meetrondje, self.bestand)
|
---|
[9395] | 139 |
|
---|
| 140 |
|
---|
[9026] | 141 | class Meting(models.Model):
|
---|
[9053] | 142 | meetrondje = models.ForeignKey(MeetRondje)
|
---|
[9819] | 143 | accesspoint = models.ForeignKey(Accesspoint)
|
---|
[9633] | 144 | latitude = models.FloatField()
|
---|
| 145 | longitude = models.FloatField()
|
---|
[9664] | 146 | signaal = IntegerRangeField(max_length=3,min_value=MIN_SIGNAL,max_value=MAX_SIGNAL)
|
---|
[9054] | 147 | def __unicode__(self):
|
---|
[9819] | 148 | return "%s @ %.5f,%.5f : %s" % (self.accesspoint.ssid, float(self.latitude), float(self.longitude), self.signaal)
|
---|
[9179] | 149 | class Meta:
|
---|
| 150 | # This implies that you cannot have multiple messurements on the same
|
---|
| 151 | # location for a single 'run', thus the data needs cleaned before to make
|
---|
| 152 | # this properly hold.
|
---|
[9819] | 153 | unique_together = ('meetrondje', 'accesspoint', 'latitude', 'longitude'),
|
---|
[9633] | 154 | verbose_name_plural = 'Metingen'
|
---|
| 155 |
|
---|