feat: change API output
This commit is contained in:
parent
8e91724462
commit
1fa91a7228
10
analysis.py
10
analysis.py
@ -24,10 +24,10 @@ P = Player
|
|||||||
def sociogram_json():
|
def sociogram_json():
|
||||||
nodes = []
|
nodes = []
|
||||||
necessary_nodes = set()
|
necessary_nodes = set()
|
||||||
links = []
|
edges = []
|
||||||
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():
|
||||||
nodes.append({"id": p.name, "appearance": 1})
|
nodes.append({"id": p.name, "label": p.name})
|
||||||
subquery = (
|
subquery = (
|
||||||
select(C.user, func.max(C.time).label("latest"))
|
select(C.user, func.max(C.time).label("latest"))
|
||||||
.where(C.time > datetime(2025, 2, 1, 10))
|
.where(C.time > datetime(2025, 2, 1, 10))
|
||||||
@ -44,9 +44,11 @@ def sociogram_json():
|
|||||||
# G.add_edge(c.user, p)
|
# G.add_edge(c.user, p)
|
||||||
# p_id = session.exec(select(P.id).where(P.name == p)).one()
|
# p_id = session.exec(select(P.id).where(P.name == p)).one()
|
||||||
necessary_nodes.add(p)
|
necessary_nodes.add(p)
|
||||||
links.append({"source": c.user, "target": p})
|
edges.append({"from": c.user, "to": p, "relation": "likes"})
|
||||||
|
for p in c.hate:
|
||||||
|
edges.append({"from": c.user, "to": p, "relation": "dislikes"})
|
||||||
# nodes = [n for n in nodes if n["name"] in necessary_nodes]
|
# nodes = [n for n in nodes if n["name"] in necessary_nodes]
|
||||||
return JSONResponse({"nodes": nodes, "links": links})
|
return JSONResponse({"nodes": nodes, "edges": edges})
|
||||||
|
|
||||||
|
|
||||||
def sociogram_data(show: int | None = 2):
|
def sociogram_data(show: int | None = 2):
|
||||||
|
@ -10,11 +10,12 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"d3": "^7.9.0",
|
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-sortablejs": "^6.1.4",
|
"react-sortablejs": "^6.1.4",
|
||||||
"sortablejs": "^1.15.6"
|
"sortablejs": "^1.15.6",
|
||||||
|
"vis-data": "^7.1.9",
|
||||||
|
"vis-network": "^9.1.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.17.0",
|
"@eslint/js": "^9.17.0",
|
||||||
@ -22,7 +23,7 @@
|
|||||||
"@types/react": "^18.3.18",
|
"@types/react": "^18.3.18",
|
||||||
"@types/react-dom": "^18.3.5",
|
"@types/react-dom": "^18.3.5",
|
||||||
"@types/sortablejs": "^1.15.8",
|
"@types/sortablejs": "^1.15.8",
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
"@vitejs/plugin-react": "^1.3.2",
|
||||||
"eslint": "^9.17.0",
|
"eslint": "^9.17.0",
|
||||||
"eslint-plugin-react-hooks": "^5.0.0",
|
"eslint-plugin-react-hooks": "^5.0.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.16",
|
"eslint-plugin-react-refresh": "^0.4.16",
|
||||||
@ -30,7 +31,7 @@
|
|||||||
"react-router": "^7.1.5",
|
"react-router": "^7.1.5",
|
||||||
"typescript": "~5.6.2",
|
"typescript": "~5.6.2",
|
||||||
"typescript-eslint": "^8.18.2",
|
"typescript-eslint": "^8.18.2",
|
||||||
"vite": "^6.0.5"
|
"vite": "^6.1.0"
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
|
12
src/App.tsx
12
src/App.tsx
@ -5,19 +5,19 @@ import Header from "./Header";
|
|||||||
import Rankings from "./Rankings";
|
import Rankings from "./Rankings";
|
||||||
import { BrowserRouter, Routes, Route } from "react-router";
|
import { BrowserRouter, Routes, Route } from "react-router";
|
||||||
import { SessionProvider } from "./Session";
|
import { SessionProvider } from "./Session";
|
||||||
|
import GraphComponent from "./Network";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
//const [data, setData] = useState({ nodes: [], links: [] } as SociogramData);
|
|
||||||
//async function loadData() {
|
|
||||||
// await fetch(`${baseUrl}api/analysis/json`, { method: "GET" }).then(resp => resp.json() as unknown as SociogramData).then(json => { setData(json) })
|
|
||||||
//}
|
|
||||||
//useEffect(() => { loadData() }, [])
|
|
||||||
//
|
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Header />
|
<Header />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route index element={<Rankings />} />
|
<Route index element={<Rankings />} />
|
||||||
|
<Route path="/network" element={
|
||||||
|
<SessionProvider>
|
||||||
|
<GraphComponent />
|
||||||
|
</SessionProvider>
|
||||||
|
} />
|
||||||
<Route path="/analysis" element={
|
<Route path="/analysis" element={
|
||||||
<SessionProvider>
|
<SessionProvider>
|
||||||
<Analysis />
|
<Analysis />
|
||||||
|
11
src/api.ts
11
src/api.ts
@ -20,13 +20,16 @@ export default async function api(path: string, data: any): Promise<any> {
|
|||||||
|
|
||||||
export async function apiAuth(path: string, data: any, method: string = "GET"): Promise<any> {
|
export async function apiAuth(path: string, data: any, method: string = "GET"): Promise<any> {
|
||||||
|
|
||||||
const req = new Request(`${baseUrl}api/${path}`, {
|
const req = new Request(`${baseUrl}api/${path}`,
|
||||||
method: method, headers: {
|
{
|
||||||
|
method: method,
|
||||||
|
headers: {
|
||||||
"Authorization": `Bearer ${token()} `,
|
"Authorization": `Bearer ${token()} `,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data),
|
...(data && { body: JSON.stringify(data) })
|
||||||
});
|
}
|
||||||
|
);
|
||||||
let resp: Response;
|
let resp: Response;
|
||||||
try {
|
try {
|
||||||
resp = await fetch(req);
|
resp = await fetch(req);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user