30 lines
863 B
Python
30 lines
863 B
Python
from data import data_api
|
|
import json
|
|
import os
|
|
|
|
def calc_mmr_change(systemname, winner_id, looser_id, winner_points, looser_points, match_is_draw):
|
|
gamesystem_id = data_api.get_gamesystem_id_by_name(systemname)
|
|
winner_rank = data_api.get_player_rank(winner_id,gamesystem_id)
|
|
looser_rank = data_api.get_player_rank(looser_id, gamesystem_id)
|
|
|
|
rules = load_mmr_rule_matrix(systemname)
|
|
|
|
if match_is_draw:
|
|
mmr_change = rules["rank_matrix"][str(winner_rank-looser_rank)]["draw"]
|
|
|
|
else:
|
|
mmr_change = rules["rank_matrix"][str(winner_rank-looser_rank)]["win"]
|
|
|
|
|
|
|
|
|
|
def load_mmr_rule_matrix(systemname):
|
|
safe_name = systemname.replace(" ", "_").lower()
|
|
|
|
file_path = f"mmr_calculations/mmr_rules_{safe_name}.json"
|
|
with open(file_path, "r", encoding="utf-8") as file:
|
|
rules = json.load(file)
|
|
|
|
return rules
|
|
|