MLOps/tests/demo_error_case.py

51 lines
1.5 KiB
Python

import requests
import time
def inject_bad_predictions():
"""Simuler une dégradation de performance"""
print("=" * 50)
print("CAS EN ERREUR - Dégradation Performance")
print("=" * 50)
# Injecter 100 mauvaises prédictions
print("\n⚠️ Injection de prédictions erronées...")
for i in range(100):
match = {
"team_1": f"Team_{i}",
"team_2": f"Team_{i+1}",
"rank_1": 10,
"rank_2": 11,
"map_name": "Dust2"
}
# Faire prédiction
response = requests.post("http://localhost:8000/predict", json=match)
# Simuler que toutes sont fausses
requests.post("http://localhost:8000/feedback", json={
"prediction_id": response.json()['id'],
"actual": 0 # Opposé de la prédiction
})
time.sleep(0.1)
print("✅ 100 mauvaises prédictions injectées")
# Vérifier métriques
print("\n📊 Vérification des métriques...")
metrics = requests.get("http://localhost:8000/health").json()
print(f"Accuracy actuelle: {metrics['metrics']['accuracy']:.1%}")
if metrics['metrics']['accuracy'] < 0.60:
print("\n🚨 ALERTE CRITIQUE DÉCLENCHÉE!")
print("✅ Dashboard montre l'anomalie")
print("✅ Alerte Slack envoyée")
print("✅ Email oncall envoyé")
print(f"\n🎨 Voir dashboard: http://localhost:3000/d/csgo-dashboard")
if __name__ == "__main__":
inject_bad_predictions()