Compare commits
8 Commits
105b3778e1
...
main
Author | SHA1 | Date | |
---|---|---|---|
1626751083
|
|||
710b0770cc
|
|||
56c1ba11fc
|
|||
ad2b2993df
|
|||
638e8bf20c
|
|||
a4ea0dfc41
|
|||
62ba89c599
|
|||
05bdc5c44c
|
@@ -160,15 +160,16 @@ def graph_json(
|
|||||||
if p_id not in player_map:
|
if p_id not in player_map:
|
||||||
continue
|
continue
|
||||||
p = player_map[p_id]
|
p = player_map[p_id]
|
||||||
|
weight = 0.9**i
|
||||||
edges.append(
|
edges.append(
|
||||||
{
|
{
|
||||||
"id": f"{user}->{p}",
|
"id": f"{user}->{p}",
|
||||||
"source": user,
|
"source": user,
|
||||||
"target": p,
|
"target": p,
|
||||||
"size": max(1.0 - 0.1 * i, 0.3),
|
"size": weight,
|
||||||
"data": {
|
"data": {
|
||||||
"relation": 2,
|
"relation": 2,
|
||||||
"origSize": max(1.0 - 0.1 * i, 0.3),
|
"origSize": weight,
|
||||||
"origFill": "#bed4ff",
|
"origFill": "#bed4ff",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -182,7 +183,7 @@ def graph_json(
|
|||||||
"id": f"{user}-x>{p}",
|
"id": f"{user}-x>{p}",
|
||||||
"source": user,
|
"source": user,
|
||||||
"target": p,
|
"target": p,
|
||||||
"size": 0.3,
|
"size": 0.5,
|
||||||
"data": {"relation": 0, "origSize": 0.3, "origFill": "#ff7c7c"},
|
"data": {"relation": 0, "origSize": 0.3, "origFill": "#ff7c7c"},
|
||||||
"fill": "#ff7c7c",
|
"fill": "#ff7c7c",
|
||||||
}
|
}
|
||||||
@@ -320,10 +321,17 @@ def last_submissions(
|
|||||||
):
|
):
|
||||||
times = {}
|
times = {}
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
|
player_ids = session.exec(
|
||||||
|
select(P.id)
|
||||||
|
.join(PlayerTeamLink)
|
||||||
|
.join(Team)
|
||||||
|
.where(Team.id == request.team_id, P.disabled == False)
|
||||||
|
).all()
|
||||||
for survey in [C, PT, R]:
|
for survey in [C, PT, R]:
|
||||||
subquery = (
|
subquery = (
|
||||||
select(survey.user, func.max(survey.time).label("latest"))
|
select(survey.user, func.max(survey.time).label("latest"))
|
||||||
.where(survey.team == request.team_id)
|
.where(survey.team == request.team_id)
|
||||||
|
.where(survey.user.in_(player_ids))
|
||||||
.group_by(survey.user)
|
.group_by(survey.user)
|
||||||
.subquery()
|
.subquery()
|
||||||
)
|
)
|
||||||
@@ -342,24 +350,26 @@ def last_submissions(
|
|||||||
|
|
||||||
|
|
||||||
def mvp(
|
def mvp(
|
||||||
request: Annotated[TeamScopedRequest, Security(verify_team_scope)],
|
request: Annotated[TeamScopedRequest, Security(verify_team_scope)], mixed=False
|
||||||
):
|
):
|
||||||
ranks = dict()
|
|
||||||
if request.team_id == 42:
|
if request.team_id == 42:
|
||||||
|
ranks = {}
|
||||||
random.seed(42)
|
random.seed(42)
|
||||||
players = [request.user] + demo_players
|
players = [request.user] + demo_players
|
||||||
for p in players:
|
for p in players:
|
||||||
random.shuffle(players)
|
random.shuffle(players)
|
||||||
for i, p in enumerate(players):
|
for i, p in enumerate(players):
|
||||||
ranks[p.display_name] = ranks.get(p.display_name, []) + [i + 1]
|
ranks[p.id] = ranks.get(p.id, []) + [i + 1]
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
{
|
{
|
||||||
"name": p,
|
"p_id": p_id,
|
||||||
"rank": f"{np.mean(v):.02f}",
|
"rank": f"{np.mean(v):.02f}",
|
||||||
"std": f"{np.std(v):.02f}",
|
"std": f"{np.std(v):.02f}",
|
||||||
"n": len(v),
|
"n": len(v),
|
||||||
}
|
}
|
||||||
for p, v in ranks.items()
|
for i, (p_id, v) in enumerate(ranks.items())
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
@@ -371,7 +381,7 @@ def mvp(
|
|||||||
).all()
|
).all()
|
||||||
if not players:
|
if not players:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
player_map = {p.id: p.display_name for p in players}
|
player_map = {p.id: p for p in players}
|
||||||
subquery = (
|
subquery = (
|
||||||
select(R.user, func.max(R.time).label("latest"))
|
select(R.user, func.max(R.time).label("latest"))
|
||||||
.where(R.team == request.team_id)
|
.where(R.team == request.team_id)
|
||||||
@@ -381,25 +391,45 @@ def mvp(
|
|||||||
statement2 = select(R).join(
|
statement2 = select(R).join(
|
||||||
subquery, (R.user == subquery.c.user) & (R.time == subquery.c.latest)
|
subquery, (R.user == subquery.c.user) & (R.time == subquery.c.latest)
|
||||||
)
|
)
|
||||||
|
if mixed:
|
||||||
|
all_ranks = []
|
||||||
|
for gender in ["fmp", "mmp"]:
|
||||||
|
ranks = {}
|
||||||
|
for r in session.exec(statement2):
|
||||||
|
mvps = [
|
||||||
|
p_id
|
||||||
|
for p_id in r.mvps
|
||||||
|
if p_id in player_map and player_map[p_id].gender == gender
|
||||||
|
]
|
||||||
|
for i, p_id in enumerate(mvps):
|
||||||
|
p = player_map[p_id]
|
||||||
|
ranks[p_id] = ranks.get(p_id, []) + [i + 1]
|
||||||
|
all_ranks.append(ranks)
|
||||||
|
else:
|
||||||
|
ranks = {}
|
||||||
for r in session.exec(statement2):
|
for r in session.exec(statement2):
|
||||||
for i, p_id in enumerate(r.mvps):
|
for i, p_id in enumerate(r.mvps):
|
||||||
if p_id not in player_map:
|
if p_id not in player_map:
|
||||||
continue
|
continue
|
||||||
p = player_map[p_id]
|
p = player_map[p_id]
|
||||||
ranks[p] = ranks.get(p, []) + [i + 1]
|
ranks[p_id] = ranks.get(p_id, []) + [i + 1]
|
||||||
|
all_ranks = [ranks]
|
||||||
|
|
||||||
if not ranks:
|
if not all_ranks:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail="no entries found"
|
status_code=status.HTTP_404_NOT_FOUND, detail="no entries found"
|
||||||
)
|
)
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
{
|
{
|
||||||
"name": p,
|
"p_id": p_id,
|
||||||
"rank": f"{np.mean(v):.02f}",
|
"rank": f"{np.mean(v):.02f}",
|
||||||
"std": f"{np.std(v):.02f}",
|
"std": f"{np.std(v):.02f}",
|
||||||
"n": len(v),
|
"n": len(v),
|
||||||
}
|
}
|
||||||
for p, v in ranks.items()
|
for p_id, v in ranks.items()
|
||||||
|
]
|
||||||
|
for ranks in all_ranks
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@ class Team(SQLModel, table=True):
|
|||||||
name: str
|
name: str
|
||||||
location: str | None
|
location: str | None
|
||||||
country: str | None
|
country: str | None
|
||||||
|
mixed: bool = False
|
||||||
players: list["Player"] | None = Relationship(
|
players: list["Player"] | None = Relationship(
|
||||||
back_populates="teams", link_model=PlayerTeamLink
|
back_populates="teams", link_model=PlayerTeamLink
|
||||||
)
|
)
|
||||||
|
@@ -16,7 +16,7 @@ names = [
|
|||||||
demo_players = [
|
demo_players = [
|
||||||
Player.model_validate(
|
Player.model_validate(
|
||||||
{
|
{
|
||||||
"id": i,
|
"id": i + 4200,
|
||||||
"display_name": name,
|
"display_name": name,
|
||||||
"username": name.lower().replace(" ", "").replace(".", ""),
|
"username": name.lower().replace(" ", "").replace(".", ""),
|
||||||
"gender": gender,
|
"gender": gender,
|
||||||
|
228
src/Analysis.tsx
228
src/Analysis.tsx
@@ -1,228 +0,0 @@
|
|||||||
import { useEffect, useState } from "react";
|
|
||||||
import { apiAuth } from "./api";
|
|
||||||
|
|
||||||
//const debounce = <T extends (...args: any[]) => void>(
|
|
||||||
// func: T,
|
|
||||||
// delay: number
|
|
||||||
//): ((...args: Parameters<T>) => void) => {
|
|
||||||
// let timeoutId: number | null = null;
|
|
||||||
// return (...args: Parameters<T>) => {
|
|
||||||
// if (timeoutId !== null) {
|
|
||||||
// clearTimeout(timeoutId);
|
|
||||||
// }
|
|
||||||
// console.log(timeoutId);
|
|
||||||
// timeoutId = setTimeout(() => {
|
|
||||||
// func(...args);
|
|
||||||
// }, delay);
|
|
||||||
// };
|
|
||||||
//};
|
|
||||||
//
|
|
||||||
|
|
||||||
interface Params {
|
|
||||||
nodeSize: number;
|
|
||||||
edgeWidth: number;
|
|
||||||
arrowSize: number;
|
|
||||||
fontSize: number;
|
|
||||||
distance: number;
|
|
||||||
weighting: boolean;
|
|
||||||
popularity: boolean;
|
|
||||||
show: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
let timeoutID: NodeJS.Timeout | null = null;
|
|
||||||
export default function Analysis() {
|
|
||||||
const [image, setImage] = useState("");
|
|
||||||
const [params, setParams] = useState<Params>({
|
|
||||||
nodeSize: 2000,
|
|
||||||
edgeWidth: 1,
|
|
||||||
arrowSize: 16,
|
|
||||||
fontSize: 10,
|
|
||||||
distance: 2,
|
|
||||||
weighting: true,
|
|
||||||
popularity: true,
|
|
||||||
show: 2,
|
|
||||||
});
|
|
||||||
const [showControlPanel, setShowControlPanel] = useState(false);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
|
|
||||||
// Function to generate and fetch the graph image
|
|
||||||
async function loadImage() {
|
|
||||||
setLoading(true);
|
|
||||||
await apiAuth("analysis/image", params, "POST")
|
|
||||||
.then((data) => {
|
|
||||||
setImage(data.image);
|
|
||||||
setLoading(false);
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.log("best to just reload... ", e);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (timeoutID) {
|
|
||||||
clearTimeout(timeoutID);
|
|
||||||
}
|
|
||||||
timeoutID = setTimeout(() => {
|
|
||||||
loadImage();
|
|
||||||
}, 1000);
|
|
||||||
}, [params]);
|
|
||||||
|
|
||||||
function showLabel() {
|
|
||||||
switch (params.show) {
|
|
||||||
case 0:
|
|
||||||
return "dislike";
|
|
||||||
case 1:
|
|
||||||
return "both";
|
|
||||||
case 2:
|
|
||||||
return "like";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="stack column dropdown">
|
|
||||||
<button onClick={() => setShowControlPanel(!showControlPanel)}>
|
|
||||||
Parameters{" "}
|
|
||||||
<svg
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
height="1.2em"
|
|
||||||
style={{
|
|
||||||
fill: "#ffffff",
|
|
||||||
display: "inline",
|
|
||||||
top: "0.2em",
|
|
||||||
position: "relative",
|
|
||||||
transform: showControlPanel ? "rotate(180deg)" : "unset",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{" "}
|
|
||||||
<path d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"> </path>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<div id="control-panel" className={showControlPanel ? "opened" : ""}>
|
|
||||||
<div className="control">
|
|
||||||
<datalist id="markers">
|
|
||||||
<option value="0"></option>
|
|
||||||
<option value="1"></option>
|
|
||||||
<option value="2"></option>
|
|
||||||
</datalist>
|
|
||||||
<div id="three-slider">
|
|
||||||
<label>😬</label>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
list="markers"
|
|
||||||
min="0"
|
|
||||||
max="2"
|
|
||||||
step="1"
|
|
||||||
width="16px"
|
|
||||||
onChange={(evt) =>
|
|
||||||
setParams({ ...params, show: Number(evt.target.value) })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<label>😍</label>
|
|
||||||
</div>
|
|
||||||
{showLabel()}
|
|
||||||
</div>
|
|
||||||
<div className="control">
|
|
||||||
<div className="checkBox">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={params.weighting}
|
|
||||||
onChange={(evt) =>
|
|
||||||
setParams({ ...params, weighting: evt.target.checked })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<label>weighting</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="checkBox">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={params.popularity}
|
|
||||||
onChange={(evt) =>
|
|
||||||
setParams({ ...params, popularity: evt.target.checked })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<label>popularity</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="control">
|
|
||||||
<label>distance between nodes</label>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min="0.01"
|
|
||||||
max="3.001"
|
|
||||||
step="0.05"
|
|
||||||
value={params.distance}
|
|
||||||
onChange={(evt) =>
|
|
||||||
setParams({ ...params, distance: Number(evt.target.value) })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span>{params.distance}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="control">
|
|
||||||
<label>node size</label>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min="500"
|
|
||||||
max="3000"
|
|
||||||
value={params.nodeSize}
|
|
||||||
onChange={(evt) =>
|
|
||||||
setParams({ ...params, nodeSize: Number(evt.target.value) })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span>{params.nodeSize}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="control">
|
|
||||||
<label>font size</label>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min="4"
|
|
||||||
max="24"
|
|
||||||
value={params.fontSize}
|
|
||||||
onChange={(evt) =>
|
|
||||||
setParams({ ...params, fontSize: Number(evt.target.value) })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span>{params.fontSize}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="control">
|
|
||||||
<label>edge width</label>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min="1"
|
|
||||||
max="5"
|
|
||||||
step="0.1"
|
|
||||||
value={params.edgeWidth}
|
|
||||||
onChange={(evt) =>
|
|
||||||
setParams({ ...params, edgeWidth: Number(evt.target.value) })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span>{params.edgeWidth}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="control">
|
|
||||||
<label>arrow size</label>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min="10"
|
|
||||||
max="50"
|
|
||||||
value={params.arrowSize}
|
|
||||||
onChange={(evt) =>
|
|
||||||
setParams({ ...params, arrowSize: Number(evt.target.value) })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span>{params.arrowSize}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button onClick={() => loadImage()}>reload ↻</button>
|
|
||||||
{loading ? (
|
|
||||||
<span className="loader"></span>
|
|
||||||
) : (
|
|
||||||
<img src={"data:image/png;base64," + image} width="86%" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
14
src/App.css
14
src/App.css
@@ -515,12 +515,6 @@ button {
|
|||||||
&.disable-player {
|
&.disable-player {
|
||||||
background-color: #e338;
|
background-color: #e338;
|
||||||
}
|
}
|
||||||
&.mmp {
|
|
||||||
background-color: lightskyblue;
|
|
||||||
}
|
|
||||||
&.fmp {
|
|
||||||
background-color: salmon;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.new-player-inputs {
|
.new-player-inputs {
|
||||||
@@ -551,6 +545,14 @@ button {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mmp {
|
||||||
|
background-color: lightskyblue;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fmp {
|
||||||
|
background-color: salmon;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes blink {
|
@keyframes blink {
|
||||||
0% {
|
0% {
|
||||||
background-color: #8888;
|
background-color: #8888;
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import Analysis from "./Analysis";
|
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
import Footer from "./Footer";
|
import Footer from "./Footer";
|
||||||
import Header from "./Header";
|
import Header from "./Header";
|
||||||
@@ -35,7 +34,6 @@ function App() {
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route index element={<Rankings />} />
|
<Route index element={<Rankings />} />
|
||||||
<Route path="network" element={<GraphComponent />} />
|
<Route path="network" element={<GraphComponent />} />
|
||||||
<Route path="analysis" element={<Analysis />} />
|
|
||||||
<Route path="mvp" element={<MVPChart />} />
|
<Route path="mvp" element={<MVPChart />} />
|
||||||
<Route path="changepassword" element={<SetPassword />} />
|
<Route path="changepassword" element={<SetPassword />} />
|
||||||
<Route path="team" element={<TeamPanel />} />
|
<Route path="team" element={<TeamPanel />} />
|
||||||
|
@@ -1,95 +0,0 @@
|
|||||||
import { FC } from 'react';
|
|
||||||
import { PlayerRanking } from './types';
|
|
||||||
|
|
||||||
interface BarChartProps {
|
|
||||||
players: PlayerRanking[];
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
std: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BarChart: FC<BarChartProps> = ({ players, width, height, std }) => {
|
|
||||||
const padding = 24;
|
|
||||||
const maxValue = Math.max(...players.map((player) => player.rank)) + 1;
|
|
||||||
const barWidth = (width - 2 * padding) / players.length;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<svg width={width} height={height}>
|
|
||||||
|
|
||||||
{players.map((player, index) => (
|
|
||||||
<rect
|
|
||||||
key={index}
|
|
||||||
x={index * barWidth + padding}
|
|
||||||
y={height - (1 - player.rank / maxValue) * height}
|
|
||||||
width={barWidth - 8} // subtract 2 for some spacing between bars
|
|
||||||
height={(1 - player.rank / maxValue) * height}
|
|
||||||
fill="#69f"
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{players.map((player, index) => (
|
|
||||||
<text
|
|
||||||
key={index}
|
|
||||||
x={index * barWidth + barWidth / 2 - 4 + padding}
|
|
||||||
y={height - (1 - player.rank / maxValue) * height - 5}
|
|
||||||
textAnchor="middle"
|
|
||||||
//transform='rotate(-27)'
|
|
||||||
//style={{ transformOrigin: "center", transformBox: "fill-box" }}
|
|
||||||
fontSize="16px"
|
|
||||||
fill="#404040"
|
|
||||||
>
|
|
||||||
{player.name}
|
|
||||||
</text>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{players.map((player, index) => (
|
|
||||||
<text
|
|
||||||
key={index}
|
|
||||||
x={index * barWidth + barWidth / 2 + padding - 4}
|
|
||||||
y={height - 8}
|
|
||||||
textAnchor="middle"
|
|
||||||
fontSize="12px"
|
|
||||||
fill="#404040"
|
|
||||||
>
|
|
||||||
{player.rank}
|
|
||||||
</text>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{std && players.map((player, index) => (
|
|
||||||
<line
|
|
||||||
key={`error-${index}`}
|
|
||||||
x1={index * barWidth + barWidth / 2 + padding}
|
|
||||||
y1={height - (1 - player.rank / maxValue) * height - (player.std / maxValue) * height}
|
|
||||||
x2={index * barWidth + barWidth / 2 + padding}
|
|
||||||
y2={height - (1 - player.rank / maxValue) * height + (player.std / maxValue) * height}
|
|
||||||
stroke="#ff0000"
|
|
||||||
strokeWidth="1"
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
{std && players.map((player, index) => (
|
|
||||||
<line
|
|
||||||
key={`cap-${index}-top`}
|
|
||||||
x1={index * barWidth + barWidth / 2 - 2 + padding}
|
|
||||||
y1={height - (1 - player.rank / maxValue) * height - (player.std / maxValue) * height}
|
|
||||||
x2={index * barWidth + barWidth / 2 + 2 + padding}
|
|
||||||
y2={height - (1 - player.rank / maxValue) * height - (player.std / maxValue) * height}
|
|
||||||
stroke="#ff0000"
|
|
||||||
strokeWidth="1"
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
{std && players.map((player, index) => (
|
|
||||||
<line
|
|
||||||
key={`cap-${index}-bottom`}
|
|
||||||
x1={index * barWidth + barWidth / 2 - 2 + padding}
|
|
||||||
y1={height - (1 - player.rank / maxValue) * height + (player.std / maxValue) * height}
|
|
||||||
x2={index * barWidth + barWidth / 2 + 2 + padding}
|
|
||||||
y2={height - (1 - player.rank / maxValue) * height + (player.std / maxValue) * height}
|
|
||||||
stroke="#ff0000"
|
|
||||||
strokeWidth="1"
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default BarChart;
|
|
@@ -6,12 +6,13 @@ import { useSession } from "./Session";
|
|||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
|
|
||||||
const MVPChart = () => {
|
const MVPChart = () => {
|
||||||
let initialData = {} as PlayerRanking[];
|
let initialData = {} as PlayerRanking[][];
|
||||||
const [data, setData] = useState(initialData);
|
const [data, setData] = useState(initialData);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [showStd, setShowStd] = useState(false);
|
const [showStd, setShowStd] = useState(false);
|
||||||
const { user, teams } = useSession();
|
const { user, teams } = useSession();
|
||||||
|
const [mixed, setMixed] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
user?.scopes.includes(`team:${teams?.activeTeam}`) ||
|
user?.scopes.includes(`team:${teams?.activeTeam}`) ||
|
||||||
@@ -19,21 +20,30 @@ const MVPChart = () => {
|
|||||||
navigate("/", { replace: true });
|
navigate("/", { replace: true });
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (teams) {
|
||||||
|
const activeTeam = teams.teams.find(
|
||||||
|
(team) => team.id == teams.activeTeam
|
||||||
|
);
|
||||||
|
activeTeam && setMixed(activeTeam.mixed);
|
||||||
|
}
|
||||||
|
}, [teams]);
|
||||||
|
|
||||||
async function loadData() {
|
async function loadData() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
if (teams) {
|
if (teams) {
|
||||||
await apiAuth(`analysis/mvp/${teams?.activeTeam}`, null)
|
await apiAuth(`analysis/mvp/${teams?.activeTeam}?mixed=${mixed}`, null)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.detail) {
|
if (data.detail) {
|
||||||
setError(data.detail);
|
setError(data.detail);
|
||||||
return initialData;
|
return initialData;
|
||||||
} else {
|
} else {
|
||||||
setError("");
|
setError("");
|
||||||
return data as Promise<PlayerRanking[]>;
|
return data as Promise<PlayerRanking[][]>;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setData(data.sort((a, b) => a.rank - b.rank));
|
setData(data.map((_data) => _data.sort((a, b) => a.rank - b.rank)));
|
||||||
})
|
})
|
||||||
.catch(() => setError("no access"));
|
.catch(() => setError("no access"));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -46,7 +56,8 @@ const MVPChart = () => {
|
|||||||
|
|
||||||
if (loading) return <span className="loader" />;
|
if (loading) return <span className="loader" />;
|
||||||
else if (error) return <span>{error}</span>;
|
else if (error) return <span>{error}</span>;
|
||||||
else return <RaceChart std={showStd} players={data} />;
|
else
|
||||||
|
return data.map((_data) => <RaceChart std={showStd} playerRanks={_data} />);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MVPChart;
|
export default MVPChart;
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
import { FC, useEffect, useState } from "react";
|
import { FC, useEffect, useState } from "react";
|
||||||
import { PlayerRanking } from "./types";
|
import { PlayerRanking } from "./types";
|
||||||
|
import { useSession } from "./Session";
|
||||||
|
|
||||||
interface RaceChartProps {
|
interface RaceChartProps {
|
||||||
players: PlayerRanking[];
|
playerRanks: PlayerRanking[];
|
||||||
std: boolean;
|
std: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,15 +14,14 @@ const determineNiceWidth = (width: number) => {
|
|||||||
else return width * 0.96;
|
else return width * 0.96;
|
||||||
};
|
};
|
||||||
|
|
||||||
const RaceChart: FC<RaceChartProps> = ({ players, std }) => {
|
const RaceChart: FC<RaceChartProps> = ({ playerRanks, std }) => {
|
||||||
const [width, setWidth] = useState(determineNiceWidth(window.innerWidth));
|
const [width, setWidth] = useState(determineNiceWidth(window.innerWidth));
|
||||||
//const [height, setHeight] = useState(window.innerHeight);
|
const height = (playerRanks.length + 1) * 40;
|
||||||
const height = (players.length + 1) * 40;
|
const { players } = useSession();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleResize = () => {
|
const handleResize = () => {
|
||||||
setWidth(determineNiceWidth(window.innerWidth));
|
setWidth(determineNiceWidth(window.innerWidth));
|
||||||
//setHeight(window.innerHeight);
|
|
||||||
};
|
};
|
||||||
window.addEventListener("resize", handleResize);
|
window.addEventListener("resize", handleResize);
|
||||||
return () => {
|
return () => {
|
||||||
@@ -30,18 +30,18 @@ const RaceChart: FC<RaceChartProps> = ({ players, std }) => {
|
|||||||
}, []);
|
}, []);
|
||||||
const padding = 24;
|
const padding = 24;
|
||||||
const gap = 8;
|
const gap = 8;
|
||||||
const maxValue = Math.max(...players.map((player) => player.rank)) + 1;
|
const maxValue = Math.max(...playerRanks.map((player) => player.rank)) + 1;
|
||||||
const barHeight = (height - 2 * padding) / players.length;
|
const barHeight = (height - 2 * padding) / playerRanks.length;
|
||||||
const fontSize = Math.min(barHeight - 1.5 * gap, width / 22);
|
const fontSize = Math.min(barHeight - 1.5 * gap, width / 22);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<svg width={width} height={height} id="RaceChartSVG">
|
<svg width={width} height={height} id="RaceChartSVG">
|
||||||
{players.map((player, index) => (
|
{playerRanks.map((playerRank, index) => (
|
||||||
<rect
|
<rect
|
||||||
key={String(index)}
|
key={String(index)}
|
||||||
x={4}
|
x={4}
|
||||||
y={index * barHeight + padding}
|
y={index * barHeight + padding}
|
||||||
width={(1 - player.rank / maxValue) * width}
|
width={(1 - playerRank.rank / maxValue) * width}
|
||||||
height={barHeight - gap} // subtract 2 for some spacing between bars
|
height={barHeight - gap} // subtract 2 for some spacing between bars
|
||||||
fill="#36c"
|
fill="#36c"
|
||||||
stroke="aliceblue"
|
stroke="aliceblue"
|
||||||
@@ -50,13 +50,15 @@ const RaceChart: FC<RaceChartProps> = ({ players, std }) => {
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{players.map((player, index) => (
|
{playerRanks.map((playerRank, index) => {
|
||||||
|
const player = players!.find((p) => p.id === playerRank.p_id);
|
||||||
|
return (
|
||||||
<g key={"group" + index}>
|
<g key={"group" + index}>
|
||||||
<text
|
<text
|
||||||
key={index + "_name"}
|
key={index + "_name"}
|
||||||
x={8}
|
x={8}
|
||||||
y={index * barHeight + barHeight / 2 + padding + gap / 2}
|
y={index * barHeight + barHeight / 2 + padding + gap / 2}
|
||||||
width={(1 - player.rank / maxValue) * width}
|
width={(1 - playerRank.rank / maxValue) * width}
|
||||||
height={barHeight - 8} // subtract 2 for some spacing between bars
|
height={barHeight - 8} // subtract 2 for some spacing between bars
|
||||||
fontSize={fontSize}
|
fontSize={fontSize}
|
||||||
fill="aliceblue"
|
fill="aliceblue"
|
||||||
@@ -67,18 +69,19 @@ const RaceChart: FC<RaceChartProps> = ({ players, std }) => {
|
|||||||
fontFamily="monospace"
|
fontFamily="monospace"
|
||||||
style={{ whiteSpace: "pre" }}
|
style={{ whiteSpace: "pre" }}
|
||||||
>
|
>
|
||||||
{`${String(index + 1).padStart(2)}. ${player.name}`}
|
{`${String(index + 1).padStart(2)}. ${player?.display_name}`}
|
||||||
</text>
|
</text>
|
||||||
<text
|
<text
|
||||||
key={index + "_value"}
|
key={index + "_value"}
|
||||||
x={
|
x={
|
||||||
8 +
|
8 +
|
||||||
(4 + Math.max(...players.map((p, _) => p.name.length))) *
|
(4 +
|
||||||
|
Math.max(...players!.map((p, _) => p.display_name.length))) *
|
||||||
fontSize *
|
fontSize *
|
||||||
0.66
|
0.66
|
||||||
}
|
}
|
||||||
y={index * barHeight + barHeight / 2 + padding + gap / 2}
|
y={index * barHeight + barHeight / 2 + padding + gap / 2}
|
||||||
width={(1 - player.rank / maxValue) * width}
|
width={(1 - playerRank.rank / maxValue) * width}
|
||||||
height={barHeight - 8} // subtract 2 for some spacing between bars
|
height={barHeight - 8} // subtract 2 for some spacing between bars
|
||||||
fontSize={0.8 * fontSize}
|
fontSize={0.8 * fontSize}
|
||||||
fill="aliceblue"
|
fill="aliceblue"
|
||||||
@@ -89,10 +92,11 @@ const RaceChart: FC<RaceChartProps> = ({ players, std }) => {
|
|||||||
paintOrder={"stroke fill"}
|
paintOrder={"stroke fill"}
|
||||||
style={{ whiteSpace: "pre" }}
|
style={{ whiteSpace: "pre" }}
|
||||||
>
|
>
|
||||||
{`${String(player.rank).padStart(5)} ± ${player.std} N = ${player.n}`}
|
{`${String(playerRank.rank).padStart(5)} ± ${playerRank.std} N = ${playerRank.n}`}
|
||||||
</text>
|
</text>
|
||||||
</g>
|
</g>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -7,9 +7,11 @@ import TabController from "./TabController";
|
|||||||
|
|
||||||
type PlayerListProps = Partial<ReactSortableProps<any>> & {
|
type PlayerListProps = Partial<ReactSortableProps<any>> & {
|
||||||
orderedList?: boolean;
|
orderedList?: boolean;
|
||||||
|
gender?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function PlayerList(props: PlayerListProps) {
|
function PlayerList(props: PlayerListProps) {
|
||||||
|
const fmps = props.list?.filter((item) => item.gender === "fmp").length;
|
||||||
return (
|
return (
|
||||||
<ReactSortable
|
<ReactSortable
|
||||||
{...props}
|
{...props}
|
||||||
@@ -17,10 +19,20 @@ function PlayerList(props: PlayerListProps) {
|
|||||||
swapThreshold={0.2}
|
swapThreshold={0.2}
|
||||||
style={{ minHeight: props.list && props.list?.length < 1 ? 64 : 32 }}
|
style={{ minHeight: props.list && props.list?.length < 1 ? 64 : 32 }}
|
||||||
>
|
>
|
||||||
{props.list?.map((item, index) => (
|
{props.list &&
|
||||||
<div key={item.id} className="item">
|
props.list.map((item, index) => (
|
||||||
|
<div
|
||||||
|
key={item.id}
|
||||||
|
className={"item " + (props.gender ? item.gender : "")}
|
||||||
|
>
|
||||||
{props.orderedList
|
{props.orderedList
|
||||||
? index + 1 + ". " + item.display_name
|
? props.gender
|
||||||
|
? index +
|
||||||
|
1 -
|
||||||
|
(item.gender !== "fmp" ? fmps! : 0) +
|
||||||
|
". " +
|
||||||
|
item.display_name
|
||||||
|
: index + 1 + ". " + item.display_name
|
||||||
: item.display_name}
|
: item.display_name}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@@ -325,10 +337,18 @@ function MVPDnD({ user, teams, players }: PlayerInfoProps) {
|
|||||||
const [availablePlayers, setAvailablePlayers] = useState<User[]>(players);
|
const [availablePlayers, setAvailablePlayers] = useState<User[]>(players);
|
||||||
const [rankedPlayers, setRankedPlayers] = useState<User[]>([]);
|
const [rankedPlayers, setRankedPlayers] = useState<User[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [mixed, setMixed] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const activeTeam = teams.teams.find((team) => team.id == teams.activeTeam);
|
||||||
|
activeTeam && setMixed(activeTeam.mixed);
|
||||||
|
handleGet();
|
||||||
|
}, [players]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleGet();
|
handleGet();
|
||||||
}, [players]);
|
// setMixedList(rankedPlayers);
|
||||||
|
}, [mixed]);
|
||||||
|
|
||||||
const [dialog, setDialog] = useState("dialog");
|
const [dialog, setDialog] = useState("dialog");
|
||||||
const dialogRef = useRef<HTMLDialogElement>(null);
|
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||||
@@ -342,6 +362,15 @@ function MVPDnD({ user, teams, players }: PlayerInfoProps) {
|
|||||||
response ? setDialog(response) : setDialog("try sending again");
|
response ? setDialog(response) : setDialog("try sending again");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setMixedList = (newList: User[]) =>
|
||||||
|
mixed
|
||||||
|
? setRankedPlayers(
|
||||||
|
newList.sort((a, b) =>
|
||||||
|
a.gender && b.gender ? a.gender.localeCompare(b.gender) : -1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: setRankedPlayers(newList);
|
||||||
|
|
||||||
async function handleGet() {
|
async function handleGet() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const data = await apiAuth(`mvps/${teams.activeTeam}`, null, "GET");
|
const data = await apiAuth(`mvps/${teams.activeTeam}`, null, "GET");
|
||||||
@@ -351,7 +380,7 @@ function MVPDnD({ user, teams, players }: PlayerInfoProps) {
|
|||||||
setRankedPlayers([]);
|
setRankedPlayers([]);
|
||||||
} else {
|
} else {
|
||||||
const mvps = data as MVPRanking;
|
const mvps = data as MVPRanking;
|
||||||
setRankedPlayers(filterSort(players, mvps.mvps));
|
setMixedList(filterSort(players, mvps.mvps));
|
||||||
setAvailablePlayers(
|
setAvailablePlayers(
|
||||||
players.filter((user) => !mvps.mvps.includes(user.id))
|
players.filter((user) => !mvps.mvps.includes(user.id))
|
||||||
);
|
);
|
||||||
@@ -382,11 +411,9 @@ function MVPDnD({ user, teams, players }: PlayerInfoProps) {
|
|||||||
setList={setAvailablePlayers}
|
setList={setAvailablePlayers}
|
||||||
group={{
|
group={{
|
||||||
name: "mvp-shared",
|
name: "mvp-shared",
|
||||||
pull: function (to) {
|
|
||||||
return to.el.classList.contains("putclone") ? "clone" : true;
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
className="dragbox"
|
className="dragbox"
|
||||||
|
gender={mixed}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="box two">
|
<div className="box two">
|
||||||
@@ -399,15 +426,13 @@ function MVPDnD({ user, teams, players }: PlayerInfoProps) {
|
|||||||
)}
|
)}
|
||||||
<PlayerList
|
<PlayerList
|
||||||
list={rankedPlayers}
|
list={rankedPlayers}
|
||||||
setList={setRankedPlayers}
|
setList={setMixedList}
|
||||||
group={{
|
group={{
|
||||||
name: "mvp-shared",
|
name: "mvp-shared",
|
||||||
pull: function (to) {
|
|
||||||
return to.el.classList.contains("putclone") ? "clone" : true;
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
className="dragbox"
|
className="dragbox"
|
||||||
orderedList
|
orderedList
|
||||||
|
gender={mixed}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { jwtDecode, JwtPayload } from "jwt-decode";
|
import { jwtDecode, JwtPayload } from "jwt-decode";
|
||||||
import { ReactNode, useEffect, useState } from "react";
|
import { ReactNode, useEffect, useState } from "react";
|
||||||
import { apiAuth, baseUrl, User } from "./api";
|
import { apiAuth, baseUrl, Gender, User } from "./api";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { Eye, EyeSlash } from "./Icons";
|
import { Eye, EyeSlash } from "./Icons";
|
||||||
import { useSession } from "./Session";
|
import { useSession } from "./Session";
|
||||||
@@ -237,6 +237,21 @@ export const SetPassword = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>gender</label>
|
||||||
|
<select
|
||||||
|
name="gender"
|
||||||
|
required
|
||||||
|
value={player.gender}
|
||||||
|
onChange={(e) => {
|
||||||
|
setPlayer({ ...player, gender: e.target.value as Gender });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value={undefined}></option>
|
||||||
|
<option value="fmp">FMP</option>
|
||||||
|
<option value="mmp">MMP</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label>number (optional)</label>
|
<label>number (optional)</label>
|
||||||
<input
|
<input
|
||||||
|
@@ -155,7 +155,6 @@ const TeamPanel = () => {
|
|||||||
<label>gender</label>
|
<label>gender</label>
|
||||||
<select
|
<select
|
||||||
name="gender"
|
name="gender"
|
||||||
required
|
|
||||||
value={player.gender}
|
value={player.gender}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setPlayer({ ...player, gender: e.target.value as Gender });
|
setPlayer({ ...player, gender: e.target.value as Gender });
|
||||||
|
@@ -13,7 +13,7 @@ export default interface NetworkData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface PlayerRanking {
|
export interface PlayerRanking {
|
||||||
name: string;
|
p_id: number;
|
||||||
rank: number;
|
rank: number;
|
||||||
std: number;
|
std: number;
|
||||||
n: number;
|
n: number;
|
||||||
@@ -46,6 +46,7 @@ export interface Team {
|
|||||||
name: string;
|
name: string;
|
||||||
location: string;
|
location: string;
|
||||||
country: string;
|
country: string;
|
||||||
|
mixed: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ErrorState = {
|
export type ErrorState = {
|
||||||
|
Reference in New Issue
Block a user