feat: working WebGL graph with selection/highlighting
This commit is contained in:
17
analysis.py
17
analysis.py
@@ -67,25 +67,32 @@ def graph_json():
|
||||
subquery, (C.user == subquery.c.user) & (C.time == subquery.c.latest)
|
||||
)
|
||||
for c in session.exec(statement2):
|
||||
for p in c.love:
|
||||
for i, p in enumerate(c.love):
|
||||
edges.append(
|
||||
{
|
||||
"id": f"{c.user}->{p}",
|
||||
"source": c.user,
|
||||
"target": p,
|
||||
"relation": "likes",
|
||||
"size": max(1.0 - 0.1 * i, 0.3),
|
||||
"data": {"relation": 2},
|
||||
}
|
||||
)
|
||||
continue
|
||||
for p in c.hate:
|
||||
edges.append(
|
||||
{
|
||||
id: f"{c.user}-x>{p}",
|
||||
"id": f"{c.user}-x>{p}",
|
||||
"source": c.user,
|
||||
"target": p,
|
||||
"relation": "dislikes",
|
||||
"size": 0.3,
|
||||
"data": {"relation": 0},
|
||||
"fill": "#ff7c7c",
|
||||
}
|
||||
)
|
||||
|
||||
G = nx.DiGraph()
|
||||
G.add_weighted_edges_from([(e["source"], e["target"], e["size"]) for e in edges])
|
||||
in_degrees = G.in_degree(weight="weight")
|
||||
nodes = [dict(node, **{"inDegree": in_degrees[node["id"]]}) for node in nodes]
|
||||
return JSONResponse({"nodes": nodes, "edges": edges})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user