def test_generate_save_meetings(minimal_database, subscription): 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='*****@*****.**', metadata={ 'department': 'dept' }, subscription_preferences=[user_pref]).put() user2 = User(email='*****@*****.**', metadata={ 'department': 'dept2' }, subscription_preferences=[user_pref]).put() meeting_spec = MeetingSpec(meeting_subscription=subscription, datetime=pref_1.get().datetime) meeting_spec.put() MeetingRequest(user=user1, meeting_spec=meeting_spec.key).put() MeetingRequest(user=user2, meeting_spec=meeting_spec.key).put() matches, unmatched = generate_meetings( [user1.get(), user2.get()], meeting_spec) save_meetings(matches, meeting_spec) assert unmatched == [] participants = [ participant.user for participant in MeetingParticipant.query().fetch() ] assert participants == [user1, user2]
def get_meeting_participants(): meetings = defaultdict(list) participants = MeetingParticipant.query().fetch() for participant in participants: try: email = participant.user.get().email meeting = participant.meeting meetings[meeting].append(email) except AttributeError: pass metrics = [] for meeting_key in meetings.keys(): meeting_spec = meeting_key.get().meeting_spec.get() meeting_title = meeting_spec.meeting_subscription.get().title participants = meetings[meeting_key] for participant in participants: metrics.append({ 'participant': participant, 'meeting': meeting_key.urlsafe(), 'meeting_title': meeting_title, 'date': meeting_spec.datetime.isoformat(), 'time': get_meeting_datetime(meeting_spec).strftime('%I:%M%p'), }) return metrics
def get_previous_meetings(cooldown=MEETING_COOLDOWN_WEEKS): meetings = defaultdict(list) # get all meeting specs from x weeks ago til now time_threshold_for_meetings = datetime.now() - timedelta(weeks=cooldown) meeting_spec_keys = [ spec.key for spec in MeetingSpec.query( MeetingSpec.datetime > time_threshold_for_meetings).fetch() ] logging.info('Previous Meeting History: ') logging.info([ meeting.get().datetime.strftime("%Y-%m-%d %H:%M") for meeting in meeting_spec_keys ]) if meeting_spec_keys == []: return set([]) # get all meetings from meeting specs meeting_keys = [ meeting.key for meeting in Meeting.query().filter( Meeting.meeting_spec.IN(meeting_spec_keys)).fetch() ] if meeting_keys == []: return set([]) # get all participants from meetings participants = MeetingParticipant.query().filter( MeetingParticipant.meeting.IN(meeting_keys)).fetch() if participants == []: return set([]) # group by meeting Id for participant in participants: meetings[participant.meeting.id()].append(participant.user) # ids are sorted, all matches should be in increasing order by id for the matching algorithm to work disallowed_meetings = set([ tuple(sorted(meeting, key=lambda Key: Key.id())) for meeting in meetings.values() ]) logging.info('Past Meetings') logging.info([ tuple([meeting.get().get_username() for meeting in meeting]) for meeting in disallowed_meetings ]) disallowed_meetings = { tuple([meeting.id() for meeting in meeting]) for meeting in disallowed_meetings } return disallowed_meetings
def send_match_emails(): specs = get_specs_for_current_week() for spec in specs: matches = [] meetings = Meeting.query(Meeting.meeting_spec == spec.key).fetch() for meeting in meetings: participants = MeetingParticipant.query(MeetingParticipant.meeting == meeting.key).fetch() matches.append((participants[0].user.get(), participants[1].user.get())) logging.info(spec) logging.info(matches) send_batch_meeting_confirmation_email(matches, spec) return "OK"