def cursorToArray(cursor, decrypted=False, probe="", is_researcher=False, map_to_users=False):
    array = [doc for doc in cursor]
    if "BluetoothProbe" in probe:
        if decrypted:
            anonymizer = Anonymizer()
            return anonymizer.deanonymizeDocument(array, probe)
        elif is_researcher and map_to_users:
            deviceInventory = device_inventory.DeviceInventory()
            for doc in array:
                for device in doc["data"]["DEVICES"]:
                    try:
                        user_temp = deviceInventory.mapBtToUser(
                            device["android_bluetooth_device_extra_DEVICE"]["mAddress"],
                            doc["data"]["TIMESTAMP"],
                            use_mac_if_empty=False,
                        )
                        if user_temp is not None:
                            device["user"] = user_temp
                        else:
                            device["user"] = ""
                    except KeyError:
                        device["user"] = ""
            return array
        else:
            return array
    else:
        return array
def cursorToArray(cursor, decrypted=False, probe=''):
    array = [doc for doc in cursor]
    if decrypted and 'BluetoothProbe' in probe:
        anonymizer = Anonymizer()
        return anonymizer.deanonymizeDocument(array, probe)
    else:
        return array
def cursorToArray(cursor, decrypted = False, probe = ''):
	array = [doc for doc in cursor]
	if decrypted and 'BluetoothProbe' in probe:
		anonymizer = Anonymizer()
		return anonymizer.deanonymizeDocument(array, probe)
	else:
		return array
Ejemplo n.º 4
0
def cursorToArray(cursor, decrypted = False, probe = '', is_researcher=False, map_to_users=False):
	array = []
	for row in cursor:
		if 'timestamp' in row:
			row['timestamp'] = int(time.mktime(row['timestamp'].timetuple()))
		if 'timestamp_added' in row:
			row['timestamp_added'] = int(time.mktime(row['timestamp_added'].timetuple()))
		array.append(row)

	if 'ExperienceSamplingProbe' in probe:
		for doc in array:
			doc['answer'] = json.loads(base64.b64decode(doc['answer']))

	if 'EpidemicProbe' in probe:
		for doc in array:
			doc['data'] = json.loads(base64.b64decode(doc['data']))

	if 'BluetoothProbe' not in probe: return array
	if decrypted:
		anonymizer = Anonymizer()
		return anonymizer.deanonymizeDocument(array, probe)
	if is_researcher and map_to_users:
		deviceInventory = device_inventory.DeviceInventory()
		for doc in array:
			try:
				user_temp = deviceInventory.mapBtToUser(doc['bt_mac'], doc['timestamp'], use_mac_if_empty=False)
				if user_temp is not None:
					doc['scanned_user'] = user_temp
				else:
					doc['scanned_user'] = ''
			except KeyError: doc['scanned_user'] = ''
	return array
def get_friends_connections(request, user, scopes, users_to_return, user_roles, own_data):
	collection = 'main'
	if 'researcher' in user_roles: collection = 'researcher'
	elif 'developer' in user_roles: collection = 'developer'

	if len(users_to_return) > 1 or 'all' in users_to_return: return {'error':'This functionality is not yet implemented'}
	conn, cursor = get_cursor()
	friends, connections = get_ego_network(cursor, collection, users_to_return[0])	
        anon = Anonymizer()
	return anon.deanonymizeDocument({'friends':list(friends), 'connections':list(connections)}, 'dk_dtu_compute_facebook_friends')
def cursorToArray(cursor, decrypted = False, probe = '', is_researcher=False, map_to_users=False):
	array = [doc for doc in cursor]
	if 'BluetoothProbe' in probe:
		if decrypted:
			anonymizer = Anonymizer()
			return anonymizer.deanonymizeDocument(array, probe)
		elif is_researcher and map_to_users:
			deviceInventory = device_inventory.DeviceInventory()
			for doc in array:
				for device in doc['data']['DEVICES']:
					try:
						user_temp = deviceInventory.mapBtToUser(device['android_bluetooth_device_extra_DEVICE']['mAddress'], doc['data']['TIMESTAMP'], use_mac_if_empty=False)
						if user_temp is not None:
							device['user'] = user_temp
						else:
							device['user'] = ''
					except KeyError: device['user'] = ''
			return array
		else: return array
	else: return array