|
|
@ -1,6 +1,7 @@ |
|
|
from typing import List |
|
|
from typing import List |
|
|
from pymongo.asynchronous.database import AsyncDatabase |
|
|
from pymongo.asynchronous.database import AsyncDatabase |
|
|
from typing import List |
|
|
from typing import List |
|
|
|
|
|
from entities.PacketGroup import PacketGroup |
|
|
|
|
|
|
|
|
class NodeDbService: |
|
|
class NodeDbService: |
|
|
def __init__(self, dbStore): |
|
|
def __init__(self, dbStore): |
|
|
@ -95,7 +96,9 @@ class PacketDbService: |
|
|
after: float = -1, |
|
|
after: float = -1, |
|
|
before: float = -1, |
|
|
before: float = -1, |
|
|
nums: List[int] = [], |
|
|
nums: List[int] = [], |
|
|
portnums: List[int] = []): |
|
|
portnums: List[int] = [], |
|
|
|
|
|
packetsPerNode = False, |
|
|
|
|
|
packetsSumNode = False): |
|
|
pipeline = [] |
|
|
pipeline = [] |
|
|
|
|
|
|
|
|
match = {} |
|
|
match = {} |
|
|
@ -120,12 +123,30 @@ class PacketDbService: |
|
|
pipeline.append({"$match":match}) |
|
|
pipeline.append({"$match":match}) |
|
|
|
|
|
|
|
|
#групировка по количеству на выхлопе _id номер портнума и count число его юзов |
|
|
#групировка по количеству на выхлопе _id номер портнума и count число его юзов |
|
|
pipeline.append({"$group": {"_id": "$portnum", "count": {"$sum": 1}}}) |
|
|
groupPipe = { |
|
|
|
|
|
"$group": |
|
|
|
|
|
{"_id": "$portnum", "count": {"$sum": 1}} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if packetsPerNode: |
|
|
|
|
|
groupPipe["$group"]["_id"] = { |
|
|
|
|
|
"portnum": "$portnum", |
|
|
|
|
|
"from": "$from" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if packetsSumNode: |
|
|
|
|
|
groupPipe["$group"]["_id"] = "$from" |
|
|
|
|
|
|
|
|
|
|
|
print(packetsPerNode, packetsSumNode) |
|
|
|
|
|
pipeline.append(groupPipe) |
|
|
|
|
|
print(pipeline) |
|
|
|
|
|
|
|
|
###print(pipeline) |
|
|
###print(pipeline) |
|
|
collection = self.dbStore['packet'] |
|
|
collection = self.dbStore['packet'] |
|
|
c = await collection.aggregate(pipeline) |
|
|
c = await collection.aggregate(pipeline) |
|
|
return await c.to_list() |
|
|
l = await c.to_list() |
|
|
|
|
|
print(l[0]) |
|
|
|
|
|
return [PacketGroup(p, packetsPerNode, packetsSumNode) for p in l] |
|
|
|
|
|
|
|
|
class DbService(NodeDbService, PacketDbService): |
|
|
class DbService(NodeDbService, PacketDbService): |
|
|
def __init__(self, dbStore): |
|
|
def __init__(self, dbStore): |
|
|
|