Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting meeting votes data into database #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pokr/models/meeting_statement_vote.py
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 30 additions & 0 deletions pokr/scripts/meeting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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