示例#1
0
def mac_coords_dict(qs, day_list, mac_address_key='source_address'):
    qs = exclude_manufacturers(qs, ['cisco'])
    days = {}

    for day in day_list:
        day_dict_list = defaultdict(list)
        day_dict = {}
        day_qs = qs.filter(time__day=day)
        mac_addresses = day_qs.values_list(mac_address_key,
                                           flat=True).distinct()

        mac_identity = {
            obj.mac_address: obj.identity
            for obj in DeviceInfo.objects.all()
            if not 'host' in obj.identity.lower()
        }
        is_probe = qs[0].__class__.__name__ == 'Probe'
        print 'start', datetime.datetime.now()
        for obj in day_qs:
            coords = time_to_coords(obj.time)
            if is_probe:
                day_dict_list[obj.source_address].append(coords)
            else:
                day_dict_list[obj.mac_address].append(coords)
        print 'stop', datetime.datetime.now()
        for mac in day_dict_list:
            day_dict[mac] = sorted(set(day_dict_list[mac]))

        days[day] = day_dict
    for day in days:
        print day, len(days[day])

    return days, mac_identity
示例#2
0
def mac_coords_dict(qs, day_list):
    qs = exclude_manufacturers(qs, ['cisco'])
    days = {}

    for day in day_list:
        day_dict_list = defaultdict(list)
        day_dict = {}
        day_qs = qs.filter(time__day=day)
        mac_addresses = day_qs.values_list('mac_address', flat=True).distinct()
        mac_identity = {}
        for mac in mac_addresses:
            try:
                identity = DeviceInfo.objects.filter(mac_address=EUI(mac))[0].identity.split('@')[0]
                if not 'host' in identity:
                    mac_identity[EUI(mac)] = identity
            except IndexError:
                pass
        for obj in day_qs:
            coords = time_to_coords(obj.time)
            try:
                day_dict_list[mac_identity[obj.mac_address]].append(coords)
            except KeyError:
                pass
        for mac in day_dict_list:
            day_dict[mac] = sorted(set(day_dict_list[mac]))

        days[day] = day_dict
    return days
示例#3
0
def mac_coords_dict(qs, day_list, mac_address_key='source_address'):
    qs = exclude_manufacturers(qs, ['cisco'])
    days = {}

    for day in day_list:
        day_dict_list = defaultdict(list)
        day_dict = {}
        day_qs = qs.filter(time__day=day)
        mac_addresses = day_qs.values_list(mac_address_key, flat=True).distinct()
        
        mac_identity = {obj.mac_address:obj.identity for obj in DeviceInfo.objects.all() if not 'host' in obj.identity.lower()}        
        is_probe = qs[0].__class__.__name__ == 'Probe'
        print 'start', datetime.datetime.now()        
        for obj in day_qs:
            coords = time_to_coords(obj.time)
            if is_probe:
                day_dict_list[obj.source_address].append(coords)
            else:
                day_dict_list[obj.mac_address].append(coords)
        print 'stop', datetime.datetime.now()        
        for mac in day_dict_list:
            day_dict[mac] = sorted(set(day_dict_list[mac]))

        days[day] = day_dict
    for day in days:
        print day, len(days[day])

    return days, mac_identity