Skip to content

Commit

Permalink
Fix moyenne
Browse files Browse the repository at this point in the history
  • Loading branch information
Giga77 committed Feb 4, 2025
1 parent cce9f9d commit b2311ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions custom_components/ecole_directe/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ async def _async_update_data(self) -> dict[Platform, dict[str, Any]]:
self.data[f"{eleve.get_fullname_lower()}_{
discipline["name"]}"] = discipline

self.data[f"{eleve.get_fullname_lower(
)}_moyenne_generale"] = grades_evaluations["moyenne_generale"]
if grades_evaluations["moyenne_generale"]:
self.data[f"{eleve.get_fullname_lower(
)}_moyenne_generale"] = grades_evaluations["moyenne_generale"]

self.data[f"{eleve.get_fullname_lower()}_grades"] = (
grades_evaluations["grades"]
Expand Down
22 changes: 13 additions & 9 deletions custom_components/ecole_directe/ecole_directe_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ def get_grades_evaluations(token, eleve, annee_scolaire, config_path, grades_dis
if "periodes" in data:
data["periodes"].sort(key=operator.itemgetter("dateDebut"))
for periode_json in data["periodes"]:
if "trimestre" not in periode_json["periode"].lower():
if periode_json["cloture"] == True:
continue
if "trimestre" not in periode_json["periode"].lower() and "semestre" not in periode_json["periode"].lower():
continue
if datetime.now() < datetime.strptime(
periode_json["dateDebut"], "%Y-%m-%d"
Expand All @@ -520,14 +522,13 @@ def get_grades_evaluations(token, eleve, annee_scolaire, config_path, grades_dis
continue
response["disciplines"] = get_disciplines_periode(periode_json)
if "ensembleMatieres" in periode_json:
if "moyenneGenerale" in periode_json["ensembleMatieres"]:
response["moyenne_generale"] = {
"moyenneGenerale": periode_json["ensembleMatieres"].get("moyenneGenerale", "").replace(",", "."),
"moyenneClasse": periode_json["ensembleMatieres"].get("moyenneClasse", "").replace(",", "."),
"moyenneMin": periode_json["ensembleMatieres"].get("moyenneMin", "").replace(",", "."),
"moyenneMax": periode_json["ensembleMatieres"].get("moyenneMax", "").replace(",", "."),
"dateCalcul": periode_json["ensembleMatieres"].get("dateCalcul", ""),
}
response["moyenne_generale"] = {
"moyenneGenerale": (periode_json["ensembleMatieres"].get("moyenneGenerale") or "").replace(",", "."),
"moyenneClasse": (periode_json["ensembleMatieres"].get("moyenneClasse") or "").replace(",", "."),
"moyenneMin": (periode_json["ensembleMatieres"].get("moyenneMin") or "").replace(",", "."),
"moyenneMax": (periode_json["ensembleMatieres"].get("moyenneMax") or "").replace(",", "."),
"dateCalcul": (periode_json["ensembleMatieres"].get("dateCalcul") or ""),
}
break

if "notes" in data:
Expand Down Expand Up @@ -585,7 +586,10 @@ def get_disciplines_periode(data):
if "ensembleMatieres" in data:
if "disciplines" in data["ensembleMatieres"]:
for discipline_json in data["ensembleMatieres"]["disciplines"]:
if "codeSousMatiere" in discipline_json and len(discipline_json["codeSousMatiere"]) > 0:
continue
discipline = {
"code": discipline_json.get("codeMatiere", "").lower(),
"name": discipline_json.get("discipline", "").lower(),
"moyenne": discipline_json.get("moyenne", "").replace(",", "."),
"moyenneClasse": discipline_json.get("moyenneClasse", "").replace(",", "."),
Expand Down
1 change: 1 addition & 0 deletions custom_components/ecole_directe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def extra_state_attributes(self):

return {
"updated_at": self.coordinator.last_update_success_time,
"code": discipline["code"],
"nom": discipline["name"],
"moyenneClasse": discipline["moyenneClasse"],
"moyenneMin": discipline["moyenneMin"],
Expand Down

0 comments on commit b2311ae

Please sign in to comment.