|
|
|
@ -10,9 +10,7 @@ class MultiDeviceDbSupport: |
|
|
|
self.dbStore:AsyncDatabase = dbStore |
|
|
|
self.core = core |
|
|
|
|
|
|
|
#return {"$or": [{"device_uuid": value}]} |
|
|
|
def deviceHash2Match(self, devices_hashes = []): |
|
|
|
#print(devices_hashes) |
|
|
|
def device2Hash(self, devices_hashes = []): |
|
|
|
if devices_hashes == None: |
|
|
|
devices_hashes = [self.core.defaultDeviceUUIDHash] |
|
|
|
elif (type(devices_hashes) == list): |
|
|
|
@ -22,6 +20,11 @@ class MultiDeviceDbSupport: |
|
|
|
|
|
|
|
if devices_hashes.__len__() == 0: |
|
|
|
devices_hashes = [self.core.defaultDeviceUUIDHash] |
|
|
|
return devices_hashes |
|
|
|
|
|
|
|
#return {"$or": [{"device_uuid": value}]} |
|
|
|
def deviceHash2Match(self, devices_hashes = []): |
|
|
|
devices_hashes = self.device2Hash(devices_hashes) |
|
|
|
|
|
|
|
#print(devices_hashes) |
|
|
|
orPart = [] |
|
|
|
@ -32,6 +35,24 @@ class MultiDeviceDbSupport: |
|
|
|
orPart.append({"device_uuid": None}) |
|
|
|
orPart.append({"device_uuid": uuid}) |
|
|
|
return orPart#-->{"$or": orPart} |
|
|
|
|
|
|
|
def devicesHash2UuidList(self, devices_hashes = []): |
|
|
|
devices_hashes = self.device2Hash(devices_hashes) |
|
|
|
uuids = [] |
|
|
|
for hash in devices_hashes: |
|
|
|
uuid = self.core.devicesUuidHashToUuid.get(hash, "") |
|
|
|
if uuid: |
|
|
|
uuids.append(uuid) |
|
|
|
return uuids |
|
|
|
|
|
|
|
def devicesHash2NumList(self, devices_hashes = []): |
|
|
|
uuids = self.devicesHash2UuidList(devices_hashes) |
|
|
|
nums = [] |
|
|
|
for device in self.core.devices: |
|
|
|
if device.nid: |
|
|
|
nums.append(device.nid) |
|
|
|
|
|
|
|
return nums |
|
|
|
|
|
|
|
class MessageDbService(MultiDeviceDbSupport): |
|
|
|
MESSAGE_PORTNUM = 1 |
|
|
|
@ -145,7 +166,8 @@ class PacketDbService(MultiDeviceDbSupport): |
|
|
|
after: float = -1, |
|
|
|
before: float = -1, |
|
|
|
nums: List[int] = [], |
|
|
|
devices = []): |
|
|
|
devices = [], |
|
|
|
ignore_host = False): |
|
|
|
pipeline = [] |
|
|
|
match = {"$or": self.deviceHash2Match(devices)} |
|
|
|
if after != -1 or before != -1: |
|
|
|
@ -160,6 +182,9 @@ class PacketDbService(MultiDeviceDbSupport): |
|
|
|
nums = [nums] |
|
|
|
match["from"] = {"$in":nums} |
|
|
|
|
|
|
|
if ignore_host and "from" not in match: |
|
|
|
match["from"] = {"$nin": self.devicesHash2NumList(devices)} |
|
|
|
|
|
|
|
pipeline.append({"$match":match}) |
|
|
|
collection = self.dbStore['packet'] |
|
|
|
c = await collection.aggregate(pipeline) |
|
|
|
@ -173,7 +198,8 @@ class PacketDbService(MultiDeviceDbSupport): |
|
|
|
portnums: List[int] = [], |
|
|
|
packetsPerNode = False, |
|
|
|
packetsSumNode = False, |
|
|
|
devices = []): |
|
|
|
devices = [], |
|
|
|
ignore_host = False): |
|
|
|
pipeline = [] |
|
|
|
|
|
|
|
match = {"$or": self.deviceHash2Match(devices)} |
|
|
|
@ -189,6 +215,9 @@ class PacketDbService(MultiDeviceDbSupport): |
|
|
|
nums = [nums] |
|
|
|
match["from"] = {"$in":nums} |
|
|
|
|
|
|
|
if ignore_host and "from" not in match: |
|
|
|
match["from"] = {"$nin": self.devicesHash2NumList(devices)} |
|
|
|
|
|
|
|
if portnums: |
|
|
|
if type(portnums) != list: |
|
|
|
portnums = [portnums] |
|
|
|
|