diff options
Diffstat (limited to 'ausbutler/interface.py')
-rw-r--r-- | ausbutler/interface.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ausbutler/interface.py b/ausbutler/interface.py index 95696c1..50bd8b3 100644 --- a/ausbutler/interface.py +++ b/ausbutler/interface.py @@ -1,4 +1,7 @@ from .db import Session +from .model import AusButler, Butler +from .butler import cutoff, get_room +import re class Interface: @@ -12,3 +15,22 @@ class Interface: Base.metadata.drop_all(self.session.get_bind()) Base.metadata.create_all(self.session.get_bind()) + def populate_db(self): + self.session.query(AusButler).delete() + column_name = re.compile(r'^seg(\d+)_(\d+)$') + for butler in self.session.query(Butler).all(): + for column, value in butler.__dict__.iteritems(): + column_match = re.match(column_name, column) + if column_match: + if value is not None: + aus_b = AusButler() + aus_b.id = butler.id + 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.board_count = aus_b.table.butler_count[ + get_room(aus_b, butler.id)] + self.session.add(aus_b) + self.session.commit() + |