From 66cd9985aec868e393842d302beb3f01bcd2ba31 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 4 Jan 2017 00:26:31 +0100 Subject: Applying normalization to butler scores --- ausbutler/butler.py | 7 +++++++ ausbutler/interface.py | 6 +++++- butler.py | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ausbutler/butler.py b/ausbutler/butler.py index fb78fdb..2fae840 100644 --- a/ausbutler/butler.py +++ b/ausbutler/butler.py @@ -32,3 +32,10 @@ def get_room(butler, player): if player in [table.closeE, table.closeW, table.closeN, table.closeS]: return 'closed' +def normalize(butler): + if butler.board_count == 0: + return 0.0 + return ( + butler.cut_score / butler.board_count + + butler.opp_score * config['opponent_factor'] + ) * butler.board_count diff --git a/ausbutler/interface.py b/ausbutler/interface.py index 37af0e3..99b0e9d 100644 --- a/ausbutler/interface.py +++ b/ausbutler/interface.py @@ -1,6 +1,6 @@ from .db import Session from .model import AusButler, Butler -from .butler import cutoff, get_opponents, get_room +from .butler import cutoff, get_opponents, get_room, normalize import re @@ -50,3 +50,7 @@ class Interface: ) / 2 self.session.commit() + def normalize_scores(self): + for butler in self.session.query(AusButler).all(): + butler.corrected_score = normalize(butler) + self.session.commit() diff --git a/butler.py b/butler.py index a15d6be..03f79d1 100644 --- a/butler.py +++ b/butler.py @@ -4,3 +4,4 @@ i = Interface() i.init_db() i.populate_db() i.opp_scores() +i.normalize_scores() -- cgit v1.2.3