feat: adjust Sociogram to new DB
This commit is contained in:
parent
95e66e5d73
commit
c42231907d
10
analysis.py
10
analysis.py
@ -108,8 +108,10 @@ def graph_json():
|
|||||||
def sociogram_data(show: int | None = 2):
|
def sociogram_data(show: int | None = 2):
|
||||||
G = nx.DiGraph()
|
G = nx.DiGraph()
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
|
players = {}
|
||||||
for p in session.exec(select(P)).fetchall():
|
for p in session.exec(select(P)).fetchall():
|
||||||
G.add_node(p.name)
|
G.add_node(p.display_name)
|
||||||
|
players[p.id] = p.display_name
|
||||||
subquery = (
|
subquery = (
|
||||||
select(C.user, func.max(C.time).label("latest")).group_by(C.user).subquery()
|
select(C.user, func.max(C.time).label("latest")).group_by(C.user).subquery()
|
||||||
)
|
)
|
||||||
@ -120,10 +122,12 @@ def sociogram_data(show: int | None = 2):
|
|||||||
)
|
)
|
||||||
for c in session.exec(statement2):
|
for c in session.exec(statement2):
|
||||||
if show >= 1:
|
if show >= 1:
|
||||||
for i, p in enumerate(c.love):
|
for i, p_id in enumerate(c.love):
|
||||||
|
p = players[p_id]
|
||||||
G.add_edge(c.user, p, group="love", rank=i, popularity=1 - 0.08 * i)
|
G.add_edge(c.user, p, group="love", rank=i, popularity=1 - 0.08 * i)
|
||||||
if show <= 1:
|
if show <= 1:
|
||||||
for i, p in enumerate(c.hate):
|
for i, p_id in enumerate(c.hate):
|
||||||
|
p = players[p_id]
|
||||||
G.add_edge(c.user, p, group="hate", rank=8, popularity=-0.16)
|
G.add_edge(c.user, p, group="hate", rank=8, popularity=-0.16)
|
||||||
return G
|
return G
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user