summaryrefslogtreecommitdiff
path: root/ausbutler/interface.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-01-04 00:26:05 +0100
committeremkael <emkael@tlen.pl>2017-01-04 20:56:19 +0100
commit9e475e3cc99849c3238995aebac9a1dd361bfec3 (patch)
treeb87f2263e13b3c53775c0287c8375f48dd8ed562 /ausbutler/interface.py
parent41007b36132e8594c17f4d11f2d1834340c75456 (diff)
Compiling opponents previous scores for each segment butler
Diffstat (limited to 'ausbutler/interface.py')
-rw-r--r--ausbutler/interface.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/ausbutler/interface.py b/ausbutler/interface.py
index 50bd8b3..37af0e3 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_room
+from .butler import cutoff, get_opponents, get_room
import re
@@ -34,3 +34,19 @@ class Interface:
self.session.add(aus_b)
self.session.commit()
+ def opp_scores(self):
+ butlers = self.session.query(AusButler).all()
+ for butler in butlers:
+ opps = get_opponents(butler, butler.id)
+ averages = {opps[0]: {'sum': 0.0, 'count': 0},
+ opps[1]: {'sum': 0.0, 'count': 0}}
+ for opp_butler in butlers:
+ if opp_butler.id in opps and (opp_butler.match < butler.match or (opp_butler.match == butler.match and opp_butler.segment < butler.segment)):
+ averages[opp_butler.id]['sum'] += opp_butler.score
+ averages[opp_butler.id]['count'] += opp_butler.board_count
+ butler.opp_score = sum(
+ [opp['sum'] / opp['count'] if opp['count'] > 0 else 0.0
+ for opp in averages.values()]
+ ) / 2
+ self.session.commit()
+