예제 #1
0
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
예제 #2
0
파일: tasks.py 프로젝트: bxm156/beans
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"
예제 #3
0
파일: metrics.py 프로젝트: bxm156/beans
def metrics_api():
    keys_only = ndb.QueryOptions(keys_only=True)

    meeting_subscriptions = MeetingSubscription.query().fetch()
    metrics = []
    for subscription in meeting_subscriptions:
        data = {
            'title':
            subscription.title,
            'subscribed':
            UserSubscriptionPreferences.query(
                UserSubscriptionPreferences.subscription ==
                subscription.key).count(options=keys_only),
            'meetings':
            Meeting.query().count(options=keys_only),
        }
        metrics.append(data)
    return json.dumps(metrics)