Skip to content

Commit

Permalink
Save multiple participants for a meeting into db + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshit Kumar committed Jul 28, 2017
1 parent 8194ed1 commit 60eed5a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions tests/match_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from yelp_beans.matching.match import generate_meetings
from yelp_beans.matching.match_utils import get_counts_for_pairs
from yelp_beans.matching.match_utils import get_previous_meetings
from yelp_beans.matching.pair_match import save_pair_meetings
from yelp_beans.matching.match_utils import save_meetings
from yelp_beans.models import Meeting
from yelp_beans.models import MeetingParticipant
from yelp_beans.models import MeetingRequest
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_generate_save_meetings(minimal_database, subscription):
MeetingRequest(user=user2, meeting_spec=meeting_spec.key).put()

matches, unmatched = generate_meetings([user1.get(), user2.get()], meeting_spec)
save_pair_meetings(matches, meeting_spec)
save_meetings(matches, meeting_spec)

assert unmatched == []

Expand Down
10 changes: 10 additions & 0 deletions yelp_beans/matching/match_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
from yelp_beans.models import MeetingSpec


def save_meetings(matches, spec, group_size=2):
for match in matches:
meeting_key = Meeting(meeting_spec=spec.key).put()
for idx in range(group_size):
MeetingParticipant(meeting=meeting_key, user=match[idx].key).put()
username_list = [user.get_username for user in match]
logging.info(meeting_key)
logging.info(', '.join(username_list))


def get_counts_for_pairs(pairs):
counts = {}
for pair in pairs:
Expand Down
14 changes: 0 additions & 14 deletions yelp_beans/matching/pair_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

from yelp_beans.logic.user import user_preference
from yelp_beans.matching.match_utils import get_previous_meetings
from yelp_beans.models import Meeting
from yelp_beans.models import MeetingParticipant


def get_disallowed_meetings(users, prev_meeting_tuples, spec):
Expand All @@ -36,18 +34,6 @@ def is_same(field, match, users):
return users[match[0]].metadata[field] == users[match[1]].metadata[field]


def save_pair_meetings(matches, spec):
for match in matches:
meeting_key = Meeting(meeting_spec=spec.key).put()
MeetingParticipant(meeting=meeting_key, user=match[0].key).put()
MeetingParticipant(meeting=meeting_key, user=match[1].key).put()
logging.info(meeting_key)
logging.info('{}, {}'.format(
match[0].get_username(),
match[1].get_username(),
))


def generate_pair_meetings(users, spec, prev_meeting_tuples=None):
"""
Returns 2 tuples:
Expand Down
8 changes: 4 additions & 4 deletions yelp_beans/routes/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from yelp_beans.logic.subscription import get_specs_from_subscription
from yelp_beans.logic.subscription import store_specs_from_subscription
from yelp_beans.logic.user import sync_employees
from yelp_beans.matching.pair_match import generate_pair_meetings
from yelp_beans.matching.pair_match import save_pair_meetings
from yelp_beans.matching.match import generate_meetings
from yelp_beans.matching.match_utils import save_meetings
from yelp_beans.models import Meeting
from yelp_beans.models import MeetingParticipant
from yelp_beans.models import MeetingRequest
Expand Down Expand Up @@ -67,8 +67,8 @@ def match_employees():
logging.info('Users: ')
logging.info([user.get_username() for user in users])

matches, unmatched = generate_pair_meetings(users, spec)
save_pair_meetings(matches, spec)
matches, unmatched = generate_meetings(users, spec, prev_meeting_tuples=None, group_size=2)
save_meetings(matches, spec, group_size=2)

send_batch_unmatched_email(unmatched)
send_batch_meeting_confirmation_email(matches, spec)
Expand Down

0 comments on commit 60eed5a

Please sign in to comment.