[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] | 6 | import csv
|
---|
[9178] | 7 | import logging
|
---|
[9120] | 8 |
|
---|
[9623] | 9 | from collections import defaultdict
|
---|
| 10 |
|
---|
[9557] | 11 | logger = logging.getLogger(__name__)
|
---|
[9179] | 12 |
|
---|
[9623] | 13 | def 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)
|
---|