Changeset 9180 for src/django_gheat


Ignore:
Timestamp:
May 12, 2011, 7:51:59 AM (14 years ago)
Author:
rick
Message:

Makes it visually more attractive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/management/commands/import_droidstumbler.py

    r9179 r9180  
    3131
    3232def import_droidstumbler(location, meetrondje, gebruiker, email, datum,show_progres=False):
    33 
     33  """ Import all points, return tuple with summary"""
    3434  g, created = Gebruiker.objects.get_or_create(naam=gebruiker , email=email)
    3535  a, created = Apparatuur.objects.get_or_create(antenne='buildin' , kaart='mobilePhone')
    3636  mr, created = MeetRondje.objects.get_or_create(datum=datum , naam=meetrondje , gebruiker=g , apparatuur=a)
    3737
     38  meting_count = 0
     39  new_ap_count = 0
    3840  ap_cache = {}
    3941  meting_pool = {}
     
    5456      if not ap_cache.has_key(bssid):
    5557        ap_cache[bssid], created = Accespoint.objects.get_or_create(mac=bssid, ssid=ssid, encryptie=capabilities)
     58        if created: new_ap_count += 1
    5659
    5760      # We store the best value found
     
    6568
    6669  # Import the data into the database
    67   count = 0
     70  meting_count = 0
    6871  for (ap,lat,lon),signal in meting_pool.iteritems():
    6972    try:
     
    7578    # Give some feedback to the user
    7679    if show_progres:
    77       count = user_feedback(count, 100, 1000)
     80      meting_count = user_feedback(meting_count, 100, 1000)
    7881
    7982  if show_progres:
    80     sys.stdout.write("%s\n" % count)
     83    sys.stdout.write("%s\n" % meting_count)
     84
     85  return (len(ap_cache), new_ap_count, meting_count, len(meting_pool) - meting_count)
    8186
    8287
     
    113118       datum = datetime.datetime.strptime(datum,'%Y-%m-%d-%H%M%S')
    114119    except ValueError:
    115       logging.error("Invalid date '%s'" % options['datum'])
    116       sys.exit(1)
     120      raise CommandError("Invalid date '%s'\n" % options['datum'])
    117121
    118     self.stdout.write('Meetrondje: %s @ %s\n' % (meetrondje, datum))
    119     self.stdout.write("Going to import '%s' for gebruiker '%s <%s>'\n" % (os.path.basename(csv_file), options['gebruiker'], options['email']))
    120     import_droidstumbler(csv_file,meetrondje,options['gebruiker'],options['email'], datum, True)
    121     self.stdout.write("All done, goodbye")
     122    self.stdout.write('#INFO: Meetrondje: %s @ %s\n' % (meetrondje, datum))
     123    self.stdout.write("#INFO: Going to import '%s' for gebruiker '%s <%s>'\n" % (os.path.basename(csv_file), options['gebruiker'], options['email']))
     124    (ap_count, new_ap_count, meting_count, meting_error_count) = import_droidstumbler(csv_file,meetrondje,options['gebruiker'],options['email'], datum, True)
     125    self.stdout.write("#INFO: Import summary accespoints: added:%s processed:%s\n" % (new_ap_count, ap_count))
     126    self.stdout.write("#INFO: Import summary metingen: added:%s error:%s\n" % (meting_count, meting_error_count))
Note: See TracChangeset for help on using the changeset viewer.