feat: option to show likes, dislikes or both
This commit is contained in:
parent
06fd18ef4c
commit
d37c6f7158
15
analysis.py
15
analysis.py
@ -49,7 +49,7 @@ def sociogram_json():
|
|||||||
return JSONResponse({"nodes": nodes, "links": links})
|
return JSONResponse({"nodes": nodes, "links": links})
|
||||||
|
|
||||||
|
|
||||||
def sociogram_data(dislike: bool | None = False):
|
def sociogram_data(show: int | None = 2):
|
||||||
G = nx.DiGraph()
|
G = nx.DiGraph()
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
for p in session.exec(select(P)).fetchall():
|
for p in session.exec(select(P)).fetchall():
|
||||||
@ -62,13 +62,14 @@ def sociogram_data(dislike: bool | None = False):
|
|||||||
)
|
)
|
||||||
statement2 = (
|
statement2 = (
|
||||||
select(C)
|
select(C)
|
||||||
.where(C.user.in_(["Kruse", "Franz", "ck"]))
|
# .where(C.user.in_(["Kruse", "Franz", "ck"]))
|
||||||
.join(subquery, (C.user == subquery.c.user) & (C.time == subquery.c.latest))
|
.join(subquery, (C.user == subquery.c.user) & (C.time == subquery.c.latest))
|
||||||
)
|
)
|
||||||
for c in session.exec(statement2):
|
for c in session.exec(statement2):
|
||||||
for i, p in enumerate(c.love):
|
if show >= 1:
|
||||||
G.add_edge(c.user, p, group="love", rank=i, popularity=1 - 0.08 * i)
|
for i, p in enumerate(c.love):
|
||||||
if dislike:
|
G.add_edge(c.user, p, group="love", rank=i, popularity=1 - 0.08 * i)
|
||||||
|
if show <= 1:
|
||||||
for i, p in enumerate(c.hate):
|
for i, p in enumerate(c.hate):
|
||||||
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
|
||||||
@ -82,7 +83,7 @@ class Params(BaseModel):
|
|||||||
distance: float | None = 0.2
|
distance: float | None = 0.2
|
||||||
weighting: bool | None = True
|
weighting: bool | None = True
|
||||||
popularity: bool | None = True
|
popularity: bool | None = True
|
||||||
dislike: bool | None = False
|
show: int | None = 2
|
||||||
|
|
||||||
|
|
||||||
ARROWSTYLE = {"love": "-|>", "hate": "-|>"}
|
ARROWSTYLE = {"love": "-|>", "hate": "-|>"}
|
||||||
@ -96,7 +97,7 @@ async def render_sociogram(params: Params):
|
|||||||
ax.set_facecolor("none") # Set the axis face color to none (transparent)
|
ax.set_facecolor("none") # Set the axis face color to none (transparent)
|
||||||
ax.axis("off") # Turn off axis ticks and frames
|
ax.axis("off") # Turn off axis ticks and frames
|
||||||
|
|
||||||
G = sociogram_data(params.dislike)
|
G = sociogram_data(show=params.show)
|
||||||
pos = nx.spring_layout(G, scale=2, k=params.distance, iterations=50, seed=None)
|
pos = nx.spring_layout(G, scale=2, k=params.distance, iterations=50, seed=None)
|
||||||
nodes = nx.draw_networkx_nodes(
|
nodes = nx.draw_networkx_nodes(
|
||||||
G,
|
G,
|
||||||
|
@ -33,7 +33,7 @@ interface Params {
|
|||||||
distance: number;
|
distance: number;
|
||||||
weighting: boolean;
|
weighting: boolean;
|
||||||
popularity: boolean;
|
popularity: boolean;
|
||||||
dislike: boolean;
|
show: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DeferredProps {
|
interface DeferredProps {
|
||||||
@ -53,10 +53,10 @@ export default function Analysis() {
|
|||||||
distance: 2,
|
distance: 2,
|
||||||
weighting: true,
|
weighting: true,
|
||||||
popularity: true,
|
popularity: true,
|
||||||
dislike: false,
|
show: 2,
|
||||||
});
|
});
|
||||||
const [showControlPanel, setShowControlPanel] = useState(false);
|
const [showControlPanel, setShowControlPanel] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
// Function to generate and fetch the graph image
|
// Function to generate and fetch the graph image
|
||||||
async function loadImage() {
|
async function loadImage() {
|
||||||
@ -84,6 +84,14 @@ export default function Analysis() {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}, [params]);
|
}, [params]);
|
||||||
|
|
||||||
|
function showLabel() {
|
||||||
|
switch (params.show) {
|
||||||
|
case 0: return "dislike";
|
||||||
|
case 1: return "both";
|
||||||
|
case 2: return "like";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="stack column dropdown">
|
<div className="stack column dropdown">
|
||||||
<button onClick={() => setShowControlPanel(!showControlPanel)}>
|
<button onClick={() => setShowControlPanel(!showControlPanel)}>
|
||||||
@ -92,14 +100,27 @@ export default function Analysis() {
|
|||||||
<div id="control-panel" className={showControlPanel ? "opened" : ""}>
|
<div id="control-panel" className={showControlPanel ? "opened" : ""}>
|
||||||
|
|
||||||
<div className="control">
|
<div className="control">
|
||||||
<div className="checkBox">
|
<datalist id="markers">
|
||||||
|
<option value="0"></option>
|
||||||
|
<option value="1"></option>
|
||||||
|
<option value="2"></option>
|
||||||
|
</datalist>
|
||||||
|
<div id="three-slider">
|
||||||
|
<label>😬</label>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="range"
|
||||||
checked={params.dislike}
|
list="markers"
|
||||||
onChange={(evt) => setParams({ ...params, dislike: evt.target.checked })}
|
min="0"
|
||||||
|
max="2"
|
||||||
|
step="1"
|
||||||
|
width="16px"
|
||||||
|
onChange={(evt) => setParams({ ...params, show: Number(evt.target.value) })}
|
||||||
/>
|
/>
|
||||||
<label>show dislike</label>
|
<label>😍</label>
|
||||||
</div>
|
</div>
|
||||||
|
{showLabel()}
|
||||||
|
</div>
|
||||||
|
<div className="control">
|
||||||
<div className="checkBox">
|
<div className="checkBox">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -151,6 +151,11 @@ button {
|
|||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#three-slider input {
|
||||||
|
margin: 4px;
|
||||||
|
width: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 1000px) {
|
@media only screen and (max-width: 1000px) {
|
||||||
#control-panel {
|
#control-panel {
|
||||||
grid-template-columns: repeat(2, 1fr);
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user