Evaluation.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from Model.Parametre import *
  2. from Model.profil import profile
  3. import datetime as dt
  4. import uuid
  5. from pathlib import Path
  6. import shutil
  7. import os
  8. import json
  9. @profile
  10. def ajouter_res(nom, jour_depart, nb_jours, res, resGlobal, Portefeuille):
  11. # Création du fichier s'il n'existe pas
  12. if not os.path.exists(nom):
  13. with open(nom, "w") as f:
  14. pass # juste créer le fichier vide
  15. # Préparer les données à ajouter
  16. donnees = {
  17. "jour_depart": jour_depart,
  18. "nb_jours": nb_jours,
  19. "res": res,
  20. "resGlobal": resGlobal,
  21. "nbVente": Portefeuille.nbVente,
  22. "nbAchat": Portefeuille.nbAchat,
  23. "PerteMax": Portefeuille.PerteMax,
  24. "nbJourGagnant": Portefeuille.JourGagnant,
  25. "nbJourPerdant": Portefeuille.JourPerdant
  26. }
  27. # Ajouter les données au fichier au format JSON
  28. with open(nom, "a") as f:
  29. f.write(json.dumps(donnees) + "\n")
  30. @profile
  31. def fc_NumeroTest(path):
  32. # Timestamp compact : AAAAMMJJ_HHMMSS
  33. timestamp = dt.datetime.now().strftime("%Y%m%d_%H%M%S")
  34. # Petit identifiant unique si plusieurs lancements simultanés
  35. uid = uuid.uuid4().hex[:6]
  36. # Nom final
  37. nom_dossier = f"Modele_{timestamp}_{uid}"
  38. return nom_dossier
  39. def signe(resultat, target):
  40. signe_resultat = resultat > 0
  41. signe_target = target > 0
  42. Egal_signe = signe_resultat == signe_target
  43. return np.sum(Egal_signe)
  44. def Ecart(resultat, target):
  45. diff = resultat - target
  46. return np.mean(diff),np.max(diff),np.min(diff),np.std(diff)
  47. def AfficheStat(resultat, target):
  48. nb_Egal = signe(resultat, target)
  49. print(f"Signe : {nb_Egal}/{np.size(resultat)} soit : {nb_Egal / np.size(resultat)}")
  50. MoyenEcart,maxEcart,minEcart,stdEcart = Ecart(resultat, target)
  51. print(f"Ecart :: Moyenne : {MoyenEcart}, max :{maxEcart}, min : {minEcart}, std : {stdEcart}")