source: src/django_gheat/gheat/dataimport/droidstumbler.py@ 11406

Last change on this file since 11406 was 9640, checked in by rick, 13 years ago

Cast the import logic to a special place, cause we are going to need it soon
when we want to auto-import files from the WEB (admin interface or form).

  • Property svn:executable set to *
File size: 1.2 KB
RevLine 
[9120]1#!/usr/bin/env python
[9140]2# -*- coding: utf-8 -*-
[9120]3#
[9170]4# Rick van der Zwet <info@rickvanderzwet.nl>
[9120]5#
[9163]6import csv
[9178]7import logging
[9120]8
[9623]9from collections import defaultdict
10
[9557]11logger = logging.getLogger(__name__)
[9179]12
[9623]13def process_csv(fh, counters):
[9180]14 """ Import all points, return tuple with summary"""
[9120]15
[9557]16 # Temponary holders
[9623]17 meting_pool = defaultdict(list)
[9557]18 ap_pool = {}
[9623]19
20 csvfile = csv.reader(fh, delimiter=',')
[9557]21 # Process file, preparing new access points and measurements
[9120]22 for row in csvfile:
[9165]23 try:
24 epoch, msg_type, lat, lon, accuracy, ssid, bssid, level, frequency, capabilities = row
[9565]25 bssid = bssid.upper()
[9165]26 except ValueError:
[9557]27 # Known error, please ignore
28 if row[1] == 'gps' and len(row) == 12: continue
29 logger.error("Unable to parse line:%i '%s'" % (csvfile.line_num, row))
[9165]30 continue
[9140]31 if msg_type == "data" and lat and lon:
[9557]32 counters['meting_total'] += 1
33 if not ap_pool.has_key(bssid):
34 encryption = 'WPA' in capabilities or 'WEP' in capabilities
35 ap_pool[bssid] = (ssid, encryption)
[9120]36
[9179]37 # We store the best value found
[9557]38 key = (bssid, lat, lon)
[9179]39 signaal=(100 + int(level))
[9623]40 meting_pool[key].append(signaal)
[9165]41
[9623]42 return (counters, ap_pool, None, meting_pool)
Note: See TracBrowser for help on using the repository browser.