feat: change API router structure

This commit is contained in:
julius 2025-02-11 14:14:23 +01:00
parent 55b7b6f206
commit e89a2eea20
Signed by: julius
GPG Key ID: C80A63E6A5FD7092
5 changed files with 55 additions and 21 deletions

View File

@ -1,5 +1,4 @@
from datetime import datetime
import numpy as np
import io
import base64
from fastapi import APIRouter
@ -81,19 +80,17 @@ class Params(BaseModel):
font_size: int | None = Field(default=10, alias="fontSize")
arrow_size: int | None = Field(default=20, alias="arrowSize")
edge_width: float | None = Field(default=1, alias="edgeWidth")
distance: float | None = 0.2
def sociogram_image(params: Params):
print(params)
plt.figure(figsize=(16, 10), facecolor="none")
ax = plt.gca()
ax.set_facecolor("none") # Set the axis face color to none (transparent)
ax.axis("off") # Turn off axis ticks and frames
G = sociogram_data()
pos = nx.spring_layout(
G, scale=2, k=1 / np.sqrt(G.number_of_edges()), iterations=50, seed=42
)
pos = nx.spring_layout(G, scale=2, k=params.distance, iterations=50, seed=None)
nx.draw_networkx_nodes(
G,
pos,

18
main.py
View File

@ -10,6 +10,7 @@ from analysis import analysis_router
app = FastAPI(title="cutt")
api_router = APIRouter(prefix="/api")
origins = [
"*",
"http://localhost",
@ -80,7 +81,16 @@ def submit_chemistry(chemistry: Chemistry):
session.commit()
app.include_router(player_router)
app.include_router(team_router)
app.include_router(analysis_router)
app.mount("/", StaticFiles(directory="dist", html=True), name="site")
class SPAStaticFiles(StaticFiles):
async def get_response(self, path: str, scope):
response = await super().get_response(path, scope)
if response.status_code == 404:
response = await super().get_response(".", scope)
return response
api_router.include_router(player_router)
api_router.include_router(team_router)
api_router.include_router(analysis_router)
app.include_router(api_router)
app.mount("/", SPAStaticFiles(directory="dist", html=True), name="site")

View File

@ -60,15 +60,6 @@ h3 {
}
#control-panel {
display: flex;
flex-direction: column;
input {
margin: auto
}
}
.container {
display: flex;
flex-wrap: nowrap;
@ -138,7 +129,43 @@ button {
z-index: 1;
}
#control-panel {
display: grid;
overflow: hidden;
margin: auto;
gap: 16px;
grid-template-columns: repeat(3, 1fr);
}
.opened {
max-height: 100vw;
transition: max-height 1s ease-in;
}
.closed {
max-height: 0px;
transition: max-height 0.5s ease-out;
}
.control {
display: flex;
flex-direction: column;
align-items: center;
border: 1px solid #404040;
padding: 8px;
}
@media only screen and (max-width: 1000px) {
#control-panel {
grid-template-columns: repeat(2, 1fr);
}
}
@media only screen and (max-width: 768px) {
#control-panel {
grid-template-columns: 1fr;
}
.submit_text {
display: none;
}

View File

@ -8,7 +8,7 @@ import { BrowserRouter, Routes, Route } from "react-router-dom";
function App() {
//const [data, setData] = useState({ nodes: [], links: [] } as SociogramData);
//async function loadData() {
// await fetch(`${baseUrl}analysis/json`, { method: "GET" }).then(resp => resp.json() as unknown as SociogramData).then(json => { setData(json) })
// await fetch(`${baseUrl}api/analysis/json`, { method: "GET" }).then(resp => resp.json() as unknown as SociogramData).then(json => { setData(json) })
//}
//useEffect(() => { loadData() }, [])
//
@ -17,7 +17,7 @@ function App() {
<Header />
<Routes>
<Route index element={<Rankings />} />
<Route path="analysis" element={<Analysis />} />
<Route path="/analysis" element={<Analysis />} />
</Routes>
<Footer />
</BrowserRouter>

View File

@ -272,7 +272,7 @@ export default function Rankings() {
const [openTab, setOpenTab] = useState("Chemistry");
async function loadPlayers() {
const response = await fetch(`${baseUrl}player/list`, {
const response = await fetch(`${baseUrl}api/player/list`, {
method: "GET",
});
const data = await response.json();