mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-09-10 20:15:24 +03:00
feat(statistics): distinguish open vs closed project nodes
Closed project nodes don't have status info in topology JSON. Add open_project_nodes and closed_project_nodes counts to help clarify why by_status may be empty.
This commit is contained in:
parent
b4caffe13b
commit
33fdfd65ba
@ -186,26 +186,38 @@ async def statistics() -> dict:
|
|||||||
"closed": sum(1 for p in projects if p.status == "closed"),
|
"closed": sum(1 for p in projects if p.status == "closed"),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Node statistics
|
# Node statistics - distinguish open vs closed project nodes
|
||||||
all_nodes = []
|
open_project_nodes = []
|
||||||
for project in projects:
|
closed_project_nodes = []
|
||||||
all_nodes.extend(project.nodes.values())
|
|
||||||
|
|
||||||
node_by_type = {}
|
node_by_type = {}
|
||||||
node_by_status = {}
|
node_by_status = {}
|
||||||
for node in all_nodes:
|
|
||||||
# Handle both Node objects (open project) and dicts (closed project)
|
for project in projects:
|
||||||
if isinstance(node, dict):
|
nodes = project.nodes.values()
|
||||||
node_type = node.get("node_type", "unknown")
|
if project.status == "closed":
|
||||||
node_status = node.get("status", "unknown")
|
closed_project_nodes.extend(nodes)
|
||||||
else:
|
else:
|
||||||
node_type = getattr(node, "node_type", "unknown")
|
open_project_nodes.extend(nodes)
|
||||||
node_status = getattr(node, "status", "unknown")
|
|
||||||
|
# Open project nodes have real status
|
||||||
|
for node in open_project_nodes:
|
||||||
|
node_type = getattr(node, "node_type", "unknown")
|
||||||
|
node_status = getattr(node, "status", "unknown")
|
||||||
node_by_type[node_type] = node_by_type.get(node_type, 0) + 1
|
node_by_type[node_type] = node_by_type.get(node_type, 0) + 1
|
||||||
node_by_status[node_status] = node_by_status.get(node_status, 0) + 1
|
node_by_status[node_status] = node_by_status.get(node_status, 0) + 1
|
||||||
|
|
||||||
|
# Closed project nodes don't have status, count them separately
|
||||||
|
for node in closed_project_nodes:
|
||||||
|
if isinstance(node, dict):
|
||||||
|
node_type = node.get("node_type", "unknown")
|
||||||
|
else:
|
||||||
|
node_type = getattr(node, "node_type", "unknown")
|
||||||
|
node_by_type[node_type] = node_by_type.get(node_type, 0) + 1
|
||||||
|
|
||||||
node_stats = {
|
node_stats = {
|
||||||
"total": len(all_nodes),
|
"total": len(open_project_nodes) + len(closed_project_nodes),
|
||||||
|
"open_project_nodes": len(open_project_nodes),
|
||||||
|
"closed_project_nodes": len(closed_project_nodes),
|
||||||
"by_type": node_by_type,
|
"by_type": node_by_type,
|
||||||
"by_status": node_by_status,
|
"by_status": node_by_status,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user