summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-01-04 00:34:59 +0100
committeremkael <emkael@tlen.pl>2017-01-04 20:56:21 +0100
commita992859c23b9fe33d2623f5ec53c58c48699ed05 (patch)
treeca1ea96c2e9081e4cf0960ee5e7a40faef57c0f9
parent66cd9985aec868e393842d302beb3f01bcd2ba31 (diff)
Moving config read to entry script
-rw-r--r--ausbutler/butler.py21
-rw-r--r--ausbutler/interface.py11
-rw-r--r--butler.py10
3 files changed, 24 insertions, 18 deletions
diff --git a/ausbutler/butler.py b/ausbutler/butler.py
index 2fae840..2766069 100644
--- a/ausbutler/butler.py
+++ b/ausbutler/butler.py
@@ -1,17 +1,10 @@
-import json
-from os import path
-import __main__
-
-config = json.load(
- open(path.join(path.dirname(__main__.__file__), 'config', 'butler.json')))
-
-def cutoff(score):
+def cutoff(score, cutoff_point=32, cutoff_rate=0.1):
sign = 1 if score > 0 else -1
score = abs(score)
- if score > config['cutoff_point']:
- score -= config['cutoff_point']
- score *= config['cutoff_rate']
- score += config['cutoff_point']
+ if score > cutoff_point:
+ score -= cutoff_point
+ score *= cutoff_rate
+ score += cutoff_point
return score * sign
def get_opponents(butler, player):
@@ -32,10 +25,10 @@ def get_room(butler, player):
if player in [table.closeE, table.closeW, table.closeN, table.closeS]:
return 'closed'
-def normalize(butler):
+def normalize(butler, opp_factor=0.5):
if butler.board_count == 0:
return 0.0
return (
butler.cut_score / butler.board_count
- + butler.opp_score * config['opponent_factor']
+ + butler.opp_score * opp_factor
) * butler.board_count
diff --git a/ausbutler/interface.py b/ausbutler/interface.py
index 99b0e9d..cd8df45 100644
--- a/ausbutler/interface.py
+++ b/ausbutler/interface.py
@@ -6,8 +6,9 @@ import re
class Interface:
- def __init__(self):
+ def __init__(self, config):
self.session = Session()
+ self.config = config
def init_db(self, force=False):
from .model import Base
@@ -28,7 +29,10 @@ class Interface:
aus_b.match = int(column_match.group(1), base=10)
aus_b.segment = int(column_match.group(2))
aus_b.score = float(value)
- aus_b.cut_score = cutoff(aus_b.score)
+ aus_b.cut_score = cutoff(
+ aus_b.score,
+ self.config['cutoff_point'],
+ self.config['cutoff_rate'])
aus_b.board_count = aus_b.table.butler_count[
get_room(aus_b, butler.id)]
self.session.add(aus_b)
@@ -52,5 +56,6 @@ class Interface:
def normalize_scores(self):
for butler in self.session.query(AusButler).all():
- butler.corrected_score = normalize(butler)
+ butler.corrected_score = normalize(
+ butler, self.config['opponent_factor'])
self.session.commit()
diff --git a/butler.py b/butler.py
index 03f79d1..35a84d6 100644
--- a/butler.py
+++ b/butler.py
@@ -1,6 +1,14 @@
+import json
+import __main__
+
+from os import path
+
from ausbutler.interface import Interface
-i = Interface()
+config = json.load(
+ open(path.join(path.dirname(__main__.__file__), 'config', 'butler.json')))
+
+i = Interface(config)
i.init_db()
i.populate_db()
i.opp_scores()