Skip to content

Commit c41e7ba

Browse files
committed
maj TODO + classement (a travailer)
1 parent a50fe72 commit c41e7ba

File tree

8 files changed

+54
-41
lines changed

8 files changed

+54
-41
lines changed
1.07 KB
Binary file not shown.
-20 Bytes
Binary file not shown.
113 Bytes
Binary file not shown.
34 Bytes
Binary file not shown.

app/_test_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fastf1 as f1
22
from datetime import datetime, timezone
3-
import pandas as pd
43

54
year = datetime.now(timezone.utc).year
65
calendar = f1.get_event_schedule(year)

app/classement.py

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
import json
22
import os
3+
from fastf1 import get_session
34
from thefuzz import fuzz
45
import discord
56
from config import logger, EMBED_COLOR_RED, EMBED_THUMBNAIL, EMBED_FOOTER_TEXT, EMBED_IMAGE
67
import pronos as pr
78

9+
def get_session_name():
10+
# Lecture des infos de session depuis le fichier JSON
11+
with open('data/Session.json', 'r', encoding='utf-8') as f:
12+
data = json.load(f)
13+
14+
saison = data['Saison']
15+
location = data['Location']
16+
statue = data['Session'] # ex: "Qualifying", "Race", etc.
17+
18+
try:
19+
session = get_session(saison, location, statue)
20+
session.load() # Nécessaire pour avoir SessionName
21+
return session.session_name # ex: "QUALIFYING", "RACE", "SPRINT"
22+
except Exception as e:
23+
print(f"Erreur lors du chargement de la session : {e}")
24+
return "Session inconnue"
25+
26+
827

928
def load_json_file(path):
1029
"""Charge un fichier JSON, retourne un dict vide si fichier absent ou invalide."""
@@ -37,27 +56,35 @@ def match_position(entry: str, target: str, threshold: int) -> bool:
3756
fuzz.ratio(target_nom.lower(), nom.lower()) >= threshold)
3857

3958

40-
def save_results(race_type):
41-
"""
42-
race_type doit être une des chaînes : 'Qualif', 'CourseSprint', 'Course'
43-
"""
59+
def save_results():
60+
race_type = get_session_name()
61+
62+
if race_type == "Inconnu":
63+
logger.error("Session inconnue. Impossible de continuer.")
64+
return
4465

4566
logger.info(f"save_results appelée avec race_type = {race_type}")
4667

4768
country = pr.country_fonction()
4869

49-
results = load_json_file('data/Results.json')
50-
pronos = load_json_file(f'data/pronos_{country}.json')
70+
# Chemin dynamique du fichier Results
71+
if race_type == "Qualif":
72+
results_path = f'data/result/Results_Qualif_{country}.json'
73+
elif race_type == "CourseSprint":
74+
results_path = f'data/result/Results_Sprint_{country}.json'
75+
else:
76+
results_path = f'data/result/Results_Course_{country}.json'
77+
78+
results = load_json_file(results_path)
79+
pronos = load_json_file(f'data/pronos/pronos_{country}.json')
5180
barem = load_json_file('data/Barem.json')
5281

5382
if not results or not pronos or not barem:
54-
logger.info(
55-
"Fichiers nécessaires absents ou invalides, arrêt de la fonction.")
83+
logger.info("Fichiers nécessaires absents ou invalides, arrêt de la fonction.")
5684
return
5785

5886
if race_type not in barem:
59-
logger.error(
60-
f"Type de course '{race_type}' non supporté dans le barème.")
87+
logger.error(f"Type de course '{race_type}' non supporté dans le barème.")
6188
return
6289

6390
bar = barem[race_type]
@@ -74,66 +101,53 @@ def save_results(race_type):
74101

75102
logger.info(f"Calcul des points pour l'utilisateur {key} ({pseudo})")
76103

77-
premier_in_top3 = premier in [user_pronos.get(
78-
'1', ''), user_pronos.get('2', ''), user_pronos.get('3', '')]
79-
second_in_top3 = second in [user_pronos.get(
80-
'1', ''), user_pronos.get('2', ''), user_pronos.get('3', '')]
81-
troisieme_in_top3 = troisieme in [user_pronos.get(
82-
'1', ''), user_pronos.get('2', ''), user_pronos.get('3', '')]
104+
premier_in_top3 = premier in [user_pronos.get('1', ''), user_pronos.get('2', ''), user_pronos.get('3', '')]
105+
second_in_top3 = second in [user_pronos.get('1', ''), user_pronos.get('2', ''), user_pronos.get('3', '')]
106+
troisieme_in_top3 = troisieme in [user_pronos.get('1', ''), user_pronos.get('2', ''), user_pronos.get('3', '')]
83107

84108
premier_correct = match_position(user_pronos.get('1', ''), premier, 90)
85109
second_correct = match_position(user_pronos.get('2', ''), second, 90)
86-
troisieme_correct = match_position(
87-
user_pronos.get('3', ''), troisieme, 90)
110+
troisieme_correct = match_position(user_pronos.get('3', ''), troisieme, 90)
88111

89112
all_correct = premier_correct and second_correct and troisieme_correct
90113

91114
if all_correct:
92115
points += bar.get('allCorrect', 0)
93-
logger.info(
94-
f"Tout juste pour {pseudo}, +{bar.get('allCorrect', 0)} pts")
116+
logger.info(f"Tout juste pour {pseudo}, +{bar.get('allCorrect', 0)} pts")
95117
else:
96118
if premier_correct:
97119
points += bar.get('correctPosition', 0)
98-
logger.info(
99-
f"Premier à la bonne place pour {pseudo}, +{bar.get('correctPosition', 0)} pts")
120+
logger.info(f"Premier à la bonne place pour {pseudo}, +{bar.get('correctPosition', 0)} pts")
100121
elif premier_in_top3:
101122
points += bar.get('inTop3', 0)
102-
logger.info(
103-
f"Premier dans le top 3 pour {pseudo}, +{bar.get('inTop3', 0)} pts")
123+
logger.info(f"Premier dans le top 3 pour {pseudo}, +{bar.get('inTop3', 0)} pts")
104124

105125
if second_correct:
106126
points += bar.get('correctPosition', 0)
107-
logger.info(
108-
f"Deuxième à la bonne place pour {pseudo}, +{bar.get('correctPosition', 0)} pts")
127+
logger.info(f"Deuxième à la bonne place pour {pseudo}, +{bar.get('correctPosition', 0)} pts")
109128
elif second_in_top3:
110129
points += bar.get('inTop3', 0)
111-
logger.info(
112-
f"Deuxième dans le top 3 pour {pseudo}, +{bar.get('inTop3', 0)} pts")
130+
logger.info(f"Deuxième dans le top 3 pour {pseudo}, +{bar.get('inTop3', 0)} pts")
113131

114132
if troisieme_correct:
115133
points += bar.get('correctPosition', 0)
116-
logger.info(
117-
f"Troisième à la bonne place pour {pseudo}, +{bar.get('correctPosition', 0)} pts")
134+
logger.info(f"Troisième à la bonne place pour {pseudo}, +{bar.get('correctPosition', 0)} pts")
118135
elif troisieme_in_top3:
119136
points += bar.get('inTop3', 0)
120-
logger.info(
121-
f"Troisième dans le top 3 pour {pseudo}, +{bar.get('inTop3', 0)} pts")
137+
logger.info(f"Troisième dans le top 3 pour {pseudo}, +{bar.get('inTop3', 0)} pts")
122138

123-
if key not in leaderboard:
124-
leaderboard[key] = {"Pseudo": pseudo, "Points": points}
125-
else:
126-
leaderboard[key]["Points"] += points
139+
if key not in leaderboard:
140+
leaderboard[key] = {"Pseudo": pseudo, "Points": points}
141+
else:
142+
leaderboard[key]["Points"] += points
127143

128144
try:
129145
with open(leaderboard_path, 'w', encoding='utf-8') as f:
130146
json.dump(leaderboard, f, ensure_ascii=False, indent=4)
131-
logger.info(
132-
f"Leaderboard mis à jour avec {len(leaderboard)} utilisateurs.")
147+
logger.info(f"Leaderboard mis à jour avec {len(leaderboard)} utilisateurs.")
133148
except Exception as e:
134149
logger.error(f"Erreur lors de la sauvegarde du leaderboard: {e}")
135150

136-
137151
def Leaderboard():
138152
try:
139153
with open("data/Leaderbord.json", 'r', encoding='utf-8') as f:

app/error_embed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from config import logger, EMBED_COLOR_RED, EMBED_IMAGE, EMBED_THUMBNAIL, EMBED_FOOTER_TEXT, PRONOS_ID
1+
from config import logger, EMBED_COLOR_RED, EMBED_IMAGE, EMBED_THUMBNAIL, EMBED_FOOTER_TEXT
22
import discord
33

44

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)