-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* group matching * simplify naming, add tests, add docstrings, enable group size in tasks * fix linting errors
- Loading branch information
Showing
7 changed files
with
255 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ | |
|
||
from yelp_beans.logic.subscription import get_specs_from_subscription | ||
from yelp_beans.logic.subscription import store_specs_from_subscription | ||
from yelp_beans.matching.group_match import generate_groups | ||
from yelp_beans.matching.group_match import get_previous_meetings_counts | ||
from yelp_beans.matching.group_match import get_user_weights | ||
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 | ||
|
@@ -205,7 +207,7 @@ def test_pair_to_counts(): | |
assert(counts[('user1', 'user2')] == 2) | ||
|
||
|
||
def test_get_previous_meetings_counts(): | ||
def test_get_previous_meetings_counts(minimal_database): | ||
pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() | ||
subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() | ||
user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() | ||
|
@@ -217,3 +219,97 @@ def test_get_previous_meetings_counts(): | |
MeetingParticipant(meeting=meeting, user=user1).put() | ||
|
||
assert(get_previous_meetings_counts([user1.get(), user2.get()], subscription) == {(user1.id(), user2.id()): 1}) | ||
|
||
|
||
def test_generate_groups(): | ||
result = generate_groups([1, 2, 3, 4, 5], 3) | ||
assert [x for x in result] == [[1, 2, 3], [4, 5]] | ||
|
||
result = generate_groups([1, 2, 3, 4], 2) | ||
assert [x for x in result] == [[1, 2], [3, 4]] | ||
|
||
result = generate_groups([1, 2, 3], 3) | ||
assert [x for x in result] == [[1, 2, 3]] | ||
|
||
|
||
def test_get_user_weights(minimal_database): | ||
pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() | ||
subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() | ||
user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() | ||
user1 = User(email='[email protected]', metadata={'department': 'dept'}, subscription_preferences=[user_pref]).put() | ||
user2 = User(email='[email protected]', metadata={'department': 'dept2'}, subscription_preferences=[user_pref]).put() | ||
meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime).put() | ||
meeting = Meeting(meeting_spec=meeting_spec, cancelled=False).put() | ||
MeetingParticipant(meeting=meeting, user=user2).put() | ||
MeetingParticipant(meeting=meeting, user=user1).put() | ||
previous_meetings_count = get_previous_meetings_counts([user1.get(), user2.get()], subscription) | ||
|
||
assert(get_user_weights([user1.get(), user2.get()], previous_meetings_count, 10, 5) == [[0, 5], [5, 0]]) | ||
|
||
|
||
def test_generate_group_meeting(minimal_database): | ||
pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() | ||
subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1]).put() | ||
user_pref = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() | ||
meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime) | ||
meeting_spec.put() | ||
|
||
users = [] | ||
num_users = 21 | ||
for i in range(0, num_users): | ||
user = User(email='{}@yelp.com'.format(i), metadata={ | ||
'department': 'dept{}'.format(i)}, subscription_preferences=[user_pref]) | ||
user.put() | ||
MeetingRequest(user=user.key, meeting_spec=meeting_spec.key).put() | ||
users.append(user) | ||
|
||
matches, unmatched = generate_meetings(users, meeting_spec, prev_meeting_tuples=None, group_size=3) | ||
assert(len(matches) == 7) | ||
assert (len(unmatched) == 0) | ||
matches, unmatched = generate_meetings(users, meeting_spec, prev_meeting_tuples=None, group_size=5) | ||
assert(len(matches) == 4) | ||
assert (len(unmatched) == 1) | ||
|
||
|
||
def test_previous_meeting_penalty(minimal_database): | ||
pref_1 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 1)).put() | ||
pref_2 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 2)).put() | ||
pref_3 = SubscriptionDateTime(datetime=datetime.now() - timedelta(weeks=MEETING_COOLDOWN_WEEKS - 3)).put() | ||
subscription = MeetingSubscription(title='all engineering weekly', datetime=[pref_1, pref_2, pref_3]).put() | ||
user_pref1 = UserSubscriptionPreferences(preference=pref_1, subscription=subscription).put() | ||
user_pref2 = UserSubscriptionPreferences(preference=pref_2, subscription=subscription).put() | ||
user_pref3 = UserSubscriptionPreferences(preference=pref_3, subscription=subscription).put() | ||
meeting_spec1 = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime) | ||
meeting_spec1.put() | ||
meeting_spec2 = MeetingSpec(meeting_subscription=subscription, datetime=pref_2.get().datetime) | ||
meeting_spec2.put() | ||
meeting_spec3 = MeetingSpec(meeting_subscription=subscription, datetime=pref_3.get().datetime) | ||
meeting_spec3.put() | ||
|
||
users = [] | ||
num_users = 20 | ||
for i in range(0, num_users): | ||
user = User(email='{}@yelp.com'.format(i), metadata={ | ||
'department': 'dept{}'.format(i)}, subscription_preferences=[user_pref1, user_pref2, user_pref3]) | ||
user.put() | ||
MeetingRequest(user=user.key, meeting_spec=meeting_spec1.key).put() | ||
MeetingRequest(user=user.key, meeting_spec=meeting_spec2.key).put() | ||
MeetingRequest(user=user.key, meeting_spec=meeting_spec3.key).put() | ||
users.append(user) | ||
|
||
meeting1 = Meeting(meeting_spec=meeting_spec1.key, cancelled=False).put() | ||
MeetingParticipant(meeting=meeting1, user=users[1].key).put() | ||
MeetingParticipant(meeting=meeting1, user=users[0].key).put() | ||
meeting2 = Meeting(meeting_spec=meeting_spec2.key, cancelled=False).put() | ||
MeetingParticipant(meeting=meeting2, user=users[1].key).put() | ||
MeetingParticipant(meeting=meeting2, user=users[0].key).put() | ||
meeting3 = Meeting(meeting_spec=meeting_spec3.key, cancelled=False).put() | ||
MeetingParticipant(meeting=meeting3, user=users[1].key).put() | ||
MeetingParticipant(meeting=meeting3, user=users[0].key).put() | ||
|
||
for run in range(10): | ||
matches, unmatched = generate_meetings(users, meeting_spec1, prev_meeting_tuples=None, group_size=3) | ||
assert(len(matches) == 6) | ||
assert (len(unmatched) == 2) | ||
for matched_group in matches: | ||
assert(not (users[0] in matched_group and users[1] in matched_group)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters