fix: weigh dislike negatively for weighted degree
This commit is contained in:
parent
a6d0f528d0
commit
6902ffdca6
@ -58,6 +58,7 @@ def graph_json(
|
||||
request: Annotated[
|
||||
TeamScopedRequest, Security(verify_team_scope, scopes=["analysis"])
|
||||
],
|
||||
networkx_graph: bool = False,
|
||||
):
|
||||
nodes = []
|
||||
edges = []
|
||||
@ -124,11 +125,22 @@ def graph_json(
|
||||
)
|
||||
G = nx.DiGraph()
|
||||
G.add_nodes_from([n["id"] for n in nodes])
|
||||
G.add_weighted_edges_from([(e["source"], e["target"], e["size"]) for e in edges])
|
||||
G.add_weighted_edges_from(
|
||||
[
|
||||
(
|
||||
e["source"],
|
||||
e["target"],
|
||||
e["size"] if e["data"]["relation"] == 2 else -e["size"],
|
||||
)
|
||||
for e in edges
|
||||
]
|
||||
)
|
||||
in_degrees = G.in_degree(weight="weight")
|
||||
nodes = [
|
||||
dict(node, **{"data": {"inDegree": in_degrees[node["id"]]}}) for node in nodes
|
||||
]
|
||||
if networkx_graph:
|
||||
return G
|
||||
return JSONResponse({"nodes": nodes, "edges": edges})
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user