diff options
author | emkael <emkael@tlen.pl> | 2017-01-04 00:24:14 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-01-04 20:56:19 +0100 |
commit | 41007b36132e8594c17f4d11f2d1834340c75456 (patch) | |
tree | 2570ab37caefa4860a81a48ecf3e1c954d7d3280 /ausbutler/interface.py | |
parent | d0c93a1c1813213d2f55fa9b4c6798d131d08484 (diff) |
Populating model database with normalized (RDBMS-wise) data, with cut-off from config applied
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() + |