Changeset 9664 for src


Ignore:
Timestamp:
Sep 5, 2011, 5:05:20 PM (13 years ago)
Author:
rick
Message:

Fix import of invalid datapoints, causing large dots in output as signal values of 100+ where imported.

Location:
src/django_gheat/gheat
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/dataimport/__init__.py

    r9640 r9664  
    113113  sql_values = []
    114114  for (bssid,lat,lon),signals in meting_pool.iteritems():
     115    final_signal = max(signals)
    115116    if clients.has_key(bssid):
    116117      counters['meting_ignored'] += len(signals)
     
    118119      counters['meting_failed'] += len(signals)
    119120      bssid_failed[bssid] += len(signals)
     121    elif final_signal < MIN_SIGNAL or final_signal > MAX_SIGNAL:
     122      counters['meting_failed'] += len(signals)
    120123    else:
    121124      item = str((int(meetrondje.id),mac2id[bssid],float(lat),\
  • src/django_gheat/gheat/models.py

    r9663 r9664  
    33from django.core import validators
    44from django.db import models
     5
     6MIN_SIGNAL = 0
     7MAX_SIGNAL = 100
     8
     9
     10# http://stackoverflow.com/questions/849142/how-to-limit-the-maximum-value-of-a-numeric-field-in-a-django-model/849426#849426
     11class IntegerRangeField(models.IntegerField):
     12  def __init__(self, verbose_name=None, name=None, min_value=None, max_value=None, **kwargs):
     13    self.min_value, self.max_value = min_value, max_value
     14    models.IntegerField.__init__(self, verbose_name, name, **kwargs)
     15  def formfield(self, **kwargs):
     16    defaults = {'min_value': self.min_value, 'max_value':self.max_value}
     17    defaults.update(kwargs)
     18    return super(IntegerRangeField, self).formfield(**defaults)
    519
    620
     
    110124  latitude = models.FloatField()
    111125  longitude = models.FloatField()
    112   signaal = models.IntegerField(max_length=3)
     126  signaal = IntegerRangeField(max_length=3,min_value=MIN_SIGNAL,max_value=MAX_SIGNAL)
    113127  def __unicode__(self):
    114128    return "%s @ %.5f,%.5f : %s" % (self.accespoint.ssid, float(self.latitude), float(self.longitude), self.signaal)
Note: See TracChangeset for help on using the changeset viewer.