Ignore:
Timestamp:
Aug 30, 2011, 6:13:57 PM (13 years ago)
Author:
rick
Message:

Merge and migrate all files into common files to get rid of all duplicate codes.

File:
1 edited

Legend:

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

    r9618 r9623  
    88from struct import unpack
    99
    10 def parse_netstumbler(fh):
     10from collections import defaultdict
     11import logging
     12
     13logger = logging.getLogger(__name__)
     14logger.setLevel(logging.INFO)
     15
     16def parse_ns1(fh):
    1117  def get_int32(size=1):
    1218    v = unpack('<' + 'i'*size,fh.read(4*size))
     
    103109  return data
    104110
     111def process_ns1(fh, counters):
     112  data = parse_ns1(fh)
     113
     114
     115  # Temponary holders
     116  meting_pool = defaultdict(list)
     117  ap_pool = {}
     118
     119  for ap in data['aps']:
     120    # XXX: How is encryption coded?
     121    encryption = False
     122    ap_pool[ap['BSSID']]= (ap['SSID'], encryption)
     123    for point in ap["measurements"]:
     124     counters['meting_total'] += 1
     125     if point['LocationSource'] == 0:
     126       logger.debug("No GPS Coordinates found for BSSID %s @ %s",
     127         ap['BSSID'], point['Time'])
     128       counters['meting_ignored'] += 1
     129       continue
     130     # We store all values found, avg or max will be done later on
     131     key = (ap['BSSID'], point["Latitude"], point["Longitude"])
     132
     133     # Known measurement error
     134     if point['Signal'] == -32767: continue
     135
     136     # XXX: Signal need properly be a relation of signal_dbm and noice_dbm
     137     signaal= 100 + point['Signal']
     138     if signaal > 100 or signaal < 0:
     139       logger.warning("Signal %s is not valid entry for BSSID %s @ %s",
     140         point['Signal'], ap['BSSID'], point['Time'])
     141       continue
     142     meting_pool[key].append(signaal)
     143
     144  return (counters, ap_pool, None, meting_pool)
    105145if __name__ == '__main__':
    106146  import sys
    107147  import pprint
    108148  pp = pprint.PrettyPrinter(indent=2)
    109   pp.pprint(parse_netstumbler(open(sys.argv[1],'r')))
     149  pp.pprint(parse_ns1(open(sys.argv[1],'r')))
Note: See TracChangeset for help on using the changeset viewer.