From 169475778c998b4198ac7d6a1cebbc3c389e41b8 Mon Sep 17 00:00:00 2001 From: Minsuk Kahng Date: Tue, 15 Dec 2015 20:03:29 -0500 Subject: [PATCH] Inserting meeting vote data --- pokr/models/meeting_statement_vote.py | 15 ++++++++++++++ pokr/scripts/meeting.py | 30 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 pokr/models/meeting_statement_vote.py diff --git a/pokr/models/meeting_statement_vote.py b/pokr/models/meeting_statement_vote.py new file mode 100644 index 0000000..2283725 --- /dev/null +++ b/pokr/models/meeting_statement_vote.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +from sqlalchemy import Column, ForeignKey, Integer, Enum + +from pokr.database import Base + + +class MeetingStatementVote(Base): + __tablename__ = 'meeting_statement_vote' + + id = Column(Integer, autoincrement=True, primary_key=True) + meeting_id = Column(ForeignKey('meeting.id'), nullable=False, index=True) + statement_id = Column(ForeignKey('statement.id'), nullable=False, index=True) + person_id = Column(ForeignKey('person.id'), nullable=False, index=True) + vote = Column(Enum('yea', 'nay', 'forfeit', name='enum_meeting_statement_vote_type'), nullable=False, index=True) diff --git a/pokr/scripts/meeting.py b/pokr/scripts/meeting.py index 5ba6d9f..ef25b07 100644 --- a/pokr/scripts/meeting.py +++ b/pokr/scripts/meeting.py @@ -143,6 +143,18 @@ def insert_meeting(region_id, obj, update=False): meeting.dialogue = obj['dialogue'] # TODO: votes = obj['votes'] + # The following code should be reviewed + meeting.votes = [] + options = ['yea', 'nay', 'forfeit'] + for option in options: + if option in stmt['votes']: + for person_name in stmt['votes'][option]: + person = guess_attendee(attendees, person_name) + statement = guess_statement(statements, stmt['name']) + if person and statement: + item = create_vote(meeting, statement, person, option) + session.add(item) + meeting.votes.append(item) def get_attendee_names(obj): @@ -178,9 +190,27 @@ def create_statement(meeting, seq, statement, attendees): return item +def create_vote(meeting, statement, person, option): + item = MeetingStatementVote( + meeting_id=meeting.id, + statement_id=statement['id'] + person_id=person.id, + vote=option, + ) + return item + + def guess_attendee(attendees, name): for attendee in attendees: if attendee.name in name: return attendee return None + +def guess_statement(statements, name): + # Not sure whether it works properly + for statement in statements: + if statement.name in name: + return statement + return None +