Liga-System/match_calculations/calc_match.py

109 lines
3.1 KiB
Python

from data import data_api
from match_calculations import calculation
import json
import os
from wood import logger
point_inflation = 0.7 # => entspricht %
K_FACTOR = 40 # Die "Border" (Maximalpunkte) die ein Sieg gibt.
# Mach die DB abfrage für die Relevanten Daten. Von hier aus werden die "Aufgaben" und Daten dann an die kleineren Berechnungs Funktionen verteilt.
def calculate_match (match_id):
match_data = data_api.get_match_by_id(match_id)
if not match_data:
print("Fehler: Match nicht gefunden!")
return
data_api.confirm_match(match_id)
# Laden und aufdröseln der Match Daten
p1_id = match_data['player1_id']
p2_id = match_data['player2_id']
p1_score = match_data['score_player1']
p2_score = match_data['score_player2']
sys_name = match_data['gamesystem_name']
sys_id = match_data['gamesystem_id']
# ==========================================
# 1. IDENTIFIKATION (Bleibt gleich)
# ==========================================
if -draw_diff <= (p1_score - p2_score) <= draw_diff:
winner_id, looser_id = p1_id, p2_id
elif p1_score > p2_score:
winner_id, looser_id = p1_id, p2_id
else:
winner_id, looser_id = p2_id, p1_id
# ==========================================
# 2. DIE BERECHNUNG & ROUTING-TABELLE
# ==========================================
# Wir speichern die Ergebnisse direkt in einem temporären Dictionary,
# und nutzen die SPIELER-ID als Schlüsselwort!
calc_results = {
"match_id" : match_id,
"sys_id" : sys_id,
"elo_factor" : calculation.calc_elo_factor(winner_id, looser_id, system_name),
"rust_factor" : calculation.calc_rust_factor(winner_id, looser_id, gamesystem_id),
winner_id: {
"base": calculation.calc_base_change(),
"khorne": calculation.wrath_of_khorne(winner_id),
"slaanesh": calculation.slaanesh_delight(),
"tzeentch": calculation.tzeentch_scemes(),
"total": winner_total
},
looser_id: {
"base": looser_base,
"khorne": wrath_of_khorne(looser_id),
"slaanesh": slaanesh_delight(winner_score, looser_score, rules),
"total": looser_total
}
}
meine_ergebnisse = {
# --- Identifikation ---
"match_id": match_id,
"gamesystem_id": sys_id,
# --- Match-Globale Werte ---
"rust_factor": 1.0, # Dein errechneter Wert (als Kommazahl / Float)
"elo_factor": 40.0, # K-Faktor
"point_inflation": 0.7, # Deine 70%
# --- Spieler 1 ---
"p1_id": p1_id,
"p1_score": p1_score,
"p1_base": p1_base_change,
"p1_khorne": khorne_p1,
"p1_slaanesh": slaanesh_points,
"p1_tzeentch": 0,
"p1_total": winner_final, # Die endgültige MMR Änderung!
# --- Spieler 2 ---
"p2_id": p2_id,
"p2_score": p2_score,
"p2_base": p2_base_change,
"p2_khorne": khorne_p2,
"p2_slaanesh": slaanesh_points,
"p2_tzeentch": 0,
"p2_total": looser_final # Die endgültige MMR Änderung!
}
def determine_draw_diff(sys_id):
draw_diff = 0
match sys_id:
case 1:
draw_diff = 3
case 2,3:
draw_diff = 1
return draw_diff