Merge remote-tracking branch 'origin/main'

This commit is contained in:
tuanvu
2026-01-08 11:27:25 +01:00
16 changed files with 165 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
{
"realm": "Frisbyee_realm",
"resource": "Frisbyee_client",
"clientId": "Frisbyee_client",
"auth-server-url": "http://localhost:8080",
"public-client": true
}

View File

@@ -6,6 +6,7 @@ const api = axios.create({
headers: {
"Content-Type": "application/json",
},
withCredentials: true,
});
api.interceptors.request.use((config) => {

View File

@@ -105,6 +105,7 @@ export function getUserTest():User{
s1.isRecurrent = true;
s1.ligne = [ligne1];
s1.duree= 90;
s1.athletes = [athlete1,athlete2];
var date2 = new Date();
date2.setDate(date2.getDate() + 2);
s2.creneau = date2;
@@ -113,19 +114,15 @@ export function getUserTest():User{
s2.name = "entraintement 2"
s2.ligne = [ligne2];
s2.duree= 120;
s2.athletes = [athlete1,athlete2, athlete3];
s3.creneau = date2;
s3.id = 3;
s3.isRecurrent = false;
s3.name = "entraintement 3"
s3.ligne = [ligne3, ligne1];
s3.duree= 120;
s1.athletes = [athlete1, athlete2];
s2.athletes = [athlete2, athlete3];
s3.athletes = [athlete1, athlete3];
s3.athletes = [athlete2, athlete3];
const act1 = new Activite();
act1.id = 1;

View File

@@ -1,7 +1,7 @@
import { useState, useEffect } from "react";
import { Session, User, Coach, Activite, Groupe } from "../classes";
import { useLocalData } from "../context/useLocalData";
import { sessionService } from "../api";
import { activiteService, sessionService } from "../api";
export const CreateSession = () => {
const {user} = useLocalData()
@@ -24,7 +24,7 @@ export const CreateSession = () => {
newActivite.duree= activiteDuree;
newActivite.data= new Map<string,string>();
try{
await sessionService.create(newActivite);
await activiteService.create(newActivite);
console.log("Session créée");
setActivities([...activities, newActivite]);

View File

@@ -59,7 +59,7 @@ export const Login =() =>{
function handleLogin(): void {
keycloak.login()
keycloak.login();
//TODO setUser
}
@@ -80,6 +80,9 @@ export const Login =() =>{
<div>
User nom : { user.nom}
</div>
<div>
User role : { user.role}
</div>
</div>
}

View File

@@ -1,23 +1,82 @@
import React from "react";
import { Athlete, Activite, Coach, Session, Ligne } from "../classes";
import {calculStatsAthlete, niveauAlerte} from "../utils/athleteUtils";
import {calculTempsDeJeuParLigne} from "../utils/ligneUtils";
type AthleteListProps = { athletes: Athlete[] };
type AthleteListProps = { athletes: Athlete[], sessions: Session[]};
type ActiviteListProps = { activites: Activite[] };
type CoachListProps = { coachs: Coach[] };
type SessionListProps = { sessions: Session[]};
type LigneListProps = { lignes: Ligne[], tempsDeJeuParLigne: Map<number, number> };
function AthleteList({ athletes }: AthleteListProps) {
function AthleteList({ athletes, sessions }: AthleteListProps) {
const [dateDebut, setDateDebut] = React.useState(new Date());
const [dateFin, setDateFin] = React.useState(new Date());
const [seuilCritique, setSeuilCritique] = React.useState(0);
const [seuilMax, setSeuilMax] = React.useState(0);
const dateToDatetimeLocal = (date: Date) => {
const pad = (n: number) => n.toString().padStart(2, "0");
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
};
return (
<ul className="AthleteList">
{athletes.map((athlete) => (
<li key={athlete.id}>
<div><strong>Nom:</strong> {athlete.nom}</div>
<div><strong>Groupe:</strong> {athlete.groupe}</div>
</li>
))}
</ul>
<>
<div className="creneau-stats">
<label>
Début :
<input
type="datetime-local"
value={dateToDatetimeLocal(dateDebut)}
onChange={e => setDateDebut(new Date(e.target.value))}
/>
</label>
<label>
Fin :
<input
type="datetime-local"
value={dateToDatetimeLocal(dateFin)}
onChange={e => setDateFin(new Date(e.target.value))}
/>
</label>
<label>
Seuil critique :
<input
type="number"
value={seuilCritique}
min={1}
onChange={e => setSeuilCritique(Number(e.target.value))}
/>
</label>
<label>Seuil max :
<input
type="number"
value={seuilMax}
min={1}
onChange={e => setSeuilMax(Number(e.target.value))}
/>
</label>
</div>
<ul className="AthleteList">
{athletes.map(a => {
const stats = calculStatsAthlete(sessions, a, dateDebut, dateFin);
const alerte = niveauAlerte(stats, seuilCritique, seuilMax);
return (
<li key={a.id}>
<div><strong>Nom:</strong> {a.nom}</div>
<div><strong>Groupe:</strong> {a.groupe}</div>
<div><strong>Nombre de sessions:</strong> {stats.nbSessions}</div>
<div><strong>Sessions/semaine:</strong> {stats.nbSessionsPerWeek.toFixed(2)}</div>
<div><strong>Alerte:</strong> {alerte}</div>
</li>
);
})}
</ul>
</>
);
}

View File

@@ -91,7 +91,7 @@ import { unescapeLeadingUnderscores } from "typescript";
{value==="athletes" && (
<div className="edt_athletes_panel">
<h3>Liste des athlètes</h3>
<AthleteList athletes={allAthletes} />
<AthleteList athletes={allAthletes} sessions={allSessions} />
</div>
)}

View File

@@ -0,0 +1,46 @@
import { Athlete, Session } from '../classes';
export interface StatsAthlete {
nbSessions: number;
nbSessionsPerWeek: number;
isAlerte: boolean;
distributions: Map<string, number>; //le nom de l'activité et son nombre
}
export function niveauAlerte(stats: StatsAthlete, seuilCritique = 0, seuilMax = 0) {
if (stats.nbSessionsPerWeek > seuilMax) return "Alerte ! Niveau maximal atteint.";
if (stats.nbSessionsPerWeek > seuilCritique) return "Attention! Niveau critique atteint.";
return "Normal";
}
export function calculStatsAthlete(sessions: Session[], athlete: Athlete, debut: Date, fin: Date): StatsAthlete {
let nb_sessions = 0;
let nb_semaine = 1; //forcément une semaine
const distributions: Map<string, number> = new Map();
const timeDiff = Math.abs(fin.getTime() - debut.getTime());
nb_semaine = Math.ceil(timeDiff / (1000 * 3600 * 24 * 7));
sessions.forEach(session => {
// verification session dans l'intervalle
if (session.creneau < debut || session.creneau > fin) return;
// verification athlete dans session
if (!session.athletes.some(a => a.id === athlete.id)) return;
//incrementation (verifie si recurent ou non)
const increment = session.isRecurrent ? nb_semaine : 1;
nb_sessions += increment;
}
);
const nbSessionsPerWeek = nb_sessions / nb_semaine;
const isAlerte = nbSessionsPerWeek > 8;
return {
nbSessions: nb_sessions,
nbSessionsPerWeek: nbSessionsPerWeek,
isAlerte: isAlerte,
distributions: distributions
};
}