108 lines
3.4 KiB
Python
108 lines
3.4 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']
|
|
|
|
match_is_draw = False
|
|
|
|
# ==========================================
|
|
# 1. IDENTIFIKATION (Bleibt gleich)
|
|
# ==========================================
|
|
# Draw
|
|
if -draw_diff <= (p1_score - p2_score) <= draw_diff:
|
|
winner_id, looser_id = p1_id, p2_id
|
|
winner_score, looser_score = p1_score, p2_score
|
|
match_is_draw = True
|
|
# P1 Winner
|
|
elif p1_score > p2_score:
|
|
winner_id, looser_id = p1_id, p2_id
|
|
winner_score, looser_score = p1_score, p2_score
|
|
# P2 Winner
|
|
else:
|
|
winner_id, looser_id = p2_id, p1_id
|
|
winner_score, looser_score = p2_score, p1_score
|
|
|
|
|
|
# ==========================================
|
|
# 2. DIE BERECHNUNG & ROUTING-TABELLE
|
|
# ==========================================
|
|
# Wir speichern die Ergebnisse direkt in einem temporären Dictionary,
|
|
# und nutzen die SPIELER-ID als Schlüsselwort!
|
|
elo_factor = calculation.calc_elo_factor(winner_id, looser_id, system_name)
|
|
base_change = calculation.calc_base_change(elo_factor, match_is_draw)
|
|
rust_factor = calculation.calc_rust_factor(winner_id, looser_id, gamesystem_id)
|
|
|
|
#winner
|
|
w_base = base_change
|
|
w_khorne = calculation.wrath_of_khorne(winner_id)
|
|
|
|
#looser
|
|
l_base = int(base_change*point_inflation)
|
|
l_khorne = calculation.wrath_of_khorne(looser_id)
|
|
|
|
slaanesh = calculation.slaanesh_delight(),
|
|
tzeentch = calculation.tzeentch_scemes(winner_score, looser_score),
|
|
|
|
|
|
|
|
# ==========================================
|
|
# 3. Daten Verpacken
|
|
# ==========================================
|
|
calc_results = {
|
|
"match_id" : match_id,
|
|
"elo_factor" : elo_factor,
|
|
"rust_factor" : rust_factor,
|
|
"point_inflation" : point_inflation,
|
|
|
|
winner_id: {
|
|
"base": w_base,
|
|
"khorne": w_khorne,
|
|
"slaanesh": slaanesh,
|
|
"tzeentch": tzeentch,
|
|
"total": int((w_base + w_khorne + slaanesh + tzeentch)*rust_factor),
|
|
},
|
|
looser_id: {
|
|
"base": l_base,
|
|
"khorne": l_khorne,
|
|
"slaanesh": -slaanesh,
|
|
"tzeentch": calculation.tzeentch_scemes(winner_score, looser_score),
|
|
"total": int((calc_results[looser_id]["base"] + calc_results[looser_id]["khorne"] - calc_results[looser_id]["slaanesh"] - calc_results[looser_id]["tzeentch"])*calc_results["rust_factor"]),
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 |