1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | #
|
---|
4 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
5 | #
|
---|
6 | import csv
|
---|
7 | import logging
|
---|
8 |
|
---|
9 | from collections import defaultdict
|
---|
10 |
|
---|
11 | logger = logging.getLogger(__name__)
|
---|
12 |
|
---|
13 | def 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)
|
---|