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

Last change on this file since 11407 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
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Rick van der Zwet <info@rickvanderzwet.nl>
5#
6import csv
7import logging
8
9from collections import defaultdict
10
11logger = logging.getLogger(__name__)
12
13def process_csv(fh, counters):
14 """ Import all points, return tuple with summary"""
15
16 # Temponary holders
17 meting_pool = defaultdict(list)
18 ap_pool = {}
19
20 csvfile = csv.reader(fh, delimiter=',')
21 # Process file, preparing new access points and measurements
22 for row in csvfile:
23 try:
24 epoch, msg_type, lat, lon, accuracy, ssid, bssid, level, frequency, capabilities = row
25 bssid = bssid.upper()
26 except ValueError:
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))
30 continue
31 if msg_type == "data" and lat and lon:
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)
36
37 # We store the best value found
38 key = (bssid, lat, lon)
39 signaal=(100 + int(level))
40 meting_pool[key].append(signaal)
41
42 return (counters, ap_pool, None, meting_pool)
Note: See TracBrowser for help on using the repository browser.