Ignore:
Timestamp:
May 4, 2011, 11:04:37 AM (14 years ago)
Author:
dennisw
Message:

Figuring out the tile generation & data flow.

File:
1 edited

Legend:

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

    r9123 r9142  
    3333import csv
    3434
    35 def import_file(location, meetrondje, gebruiker, email):
     35# Function that imports a csv and processes it.
     36def import_file(location, meetrondje, gebruiker, email, antenne, kaart):
    3637
     38  # Creating some objects that have to be created only once. Uses 'get_or_create' to rule out duplicates.
     39  # Creating user object. Depends on basecommand options.
    3740  g, created = Gebruiker.objects.get_or_create(naam=gebruiker , email=email)
    38   a, created = Apparatuur.objects.get_or_create(antenne='test' , kaart='test')
     41  # Creating equipment object. Depends on basecomand options.
     42  a, created = Apparatuur.objects.get_or_create(antenne=antenne , kaart=kaart)
     43  # Creating dataset object. Depends on baseommand options.
    3944  mr = MeetRondje.objects.create(datum=datetime.datetime.now() , naam=meetrondje , gebruiker=g , apparatuur=a)
    4045
     46  # Open the csv.
    4147  csvfile = csv.reader(open(location, 'rb'), delimiter='\t')
     48  # Read every row individually and extract the required data.
    4249  for row in csvfile:
     50    # '.replace' & '.strip' are for replacing and stripping some unwished characters. Edit where necessary.
    4351    lat = row[0].replace('N ', '')
    4452    lon = row[1].replace('E ', '')
     
    5159    print lat, lon, ssid, bssid, enc, sig
    5260
     61    # Creating accespoint objects. Avoiding duplicates.
    5362    ap, created = Accespoint.objects.get_or_create(mac=bssid, ssid=ssid, encryptie=enc)
     63    # Creating the measurement objects.
    5464    m = Meting.objects.create(meetrondje=mr, accespoint=ap, latitude=lat, longitude=lon, signaal=sig)
    5565
    56 
     66# Basecommand with options. This gives the user some control over the execution of this script.
    5767class Command(BaseCommand):
    5868  option_list = BaseCommand.option_list + (
     
    6171    make_option('-g', '--gebruiker', dest='gebruiker', default='username'),
    6272    make_option('-e', '--email', dest='email', default='foo@bar.org'),
     73    make_option('-a', '--antenne', dest='antenne', default='geen'),
     74    make_option('-k', '--kaart', dest='kaart', default='interne kaart'),
    6375    )
    64 
     76 
     77  # The function 'import_file' will be executed with the default option values, or the values specified by the user.
    6578  def handle(self, *args, **options):
    66     import_file(options['location'],options['meetrondje'],options['gebruiker'],options['email'])
     79    import_file(options['location'],options['meetrondje'],options['gebruiker'],options['email'],options['antenne'],options['kaart'])
Note: See TracChangeset for help on using the changeset viewer.