<commit_before>import math
from datetime import datetime, timedelta

from flask import jsonify
from sqlalchemy import and_, not_

from server import app, sqldb
from server.auth import internal_auth
from server.notifications import Notification, NotificationToken, send_push_notification_batch
from server.studyspaces.availability import get_room_name
from server.studyspaces.models import GSRRoomName, StudySpacesBooking


@app.route('/studyspaces/reminders/send', methods=['POST'])
@internal_auth
def request_send_reminders():
    send_reminders()
    return jsonify({'result': 'success'})


def send_reminders():
    # Query logic
    # Get bookings that meet the following criteria:
    # 1) Start within the next 10 minutes
    # 2) Booked more than 30 minutes before the start time
    # 3) Have not been cancelled
    # 4) Have not been sent a reminder yet
    # 5) Have an associated account with an iOS push notification token

    now = datetime.now()
    check_start_date = now + timedelta(minutes=10)
    get_gsr = StudySpacesBooking.query \
                                .filter(StudySpacesBooking.start <= check_start_date) \
                                .filter(StudySpacesBooking.start > now) \
                                .filter(StudySpacesBooking.date < StudySpacesBooking.start - timedelta(minutes=30)) \
                                .filter(not_(StudySpacesBooking.is_cancelled)) \
                                .filter(not_(StudySpacesBooking.reminder_sent)) \
                                .filter(StudySpacesBooking.account is not None) \
                                .subquery()

    get_tokens = NotificationToken.query.filter(NotificationToken.ios_token is not None).subquery()

    join_qry = sqldb.session.query(get_gsr.c.id, get_gsr.c.lid, get_gsr.c.rid, GSRRoomName.name,
                                   get_gsr.c.start, get_tokens.c.ios_token, get_tokens.c.dev) \
                            .select_from(get_gsr) \
                            .join(get_tokens, get_gsr.c.account == get_tokens.c.account) \
                            .join(GSRRoomName, and_(get_gsr.c.lid == GSRRoomName.lid,
                                                    get_gsr.c.rid == GSRRoomName.rid), isouter=True) \<commit_msg>test reminders<commit_after>import math
from datetime import datetime, timedelta

from flask import jsonify
from sqlalchemy import and_, not_

from server import app, sqldb
from server.auth import internal_auth
from server.notifications import Notification, NotificationToken, send_push_notification_batch
from server.studyspaces.availability import get_room_name
from server.studyspaces.models import GSRRoomName, StudySpacesBooking


@app.route('/studyspaces/reminders/send', methods=['POST'])
@internal_auth
def request_send_reminders():
    send_reminders()
    return jsonify({'result': 'success'})


def send_reminders():
    # Query logic
    # Get bookings that meet the following criteria:
    # 1) Start within the next 10 minutes
    # 2) Booked more than 30 minutes before the start time
    # 3) Have not been cancelled
    # 4) Have not been sent a reminder yet
    # 5) Have an associated account with an iOS push notification token

    now = datetime.now()
    check_start_date = now + timedelta(minutes=30)
    get_gsr = StudySpacesBooking.query \
                                .filter(StudySpacesBooking.start <= check_start_date) \
                                .filter(StudySpacesBooking.start > now) \
                                .filter(StudySpacesBooking.date < StudySpacesBooking.start - timedelta(minutes=30)) \
                                .filter(not_(StudySpacesBooking.is_cancelled)) \
                                .filter(not_(StudySpacesBooking.reminder_sent)) \
                                .filter(StudySpacesBooking.account is not None) \
                                .subquery()

    get_tokens = NotificationToken.query.filter(NotificationToken.ios_token is not None).subquery()

    join_qry = sqldb.session.query(get_gsr.c.id, get_gsr.c.lid, get_gsr.c.rid, GSRRoomName.name,
                                   get_gsr.c.start, get_tokens.c.ios_token, get_tokens.c.dev) \
                            .select_from(get_gsr) \
                            .join(get_tokens, get_gsr.c.account == get_tokens.c.account) \
                            .join(GSRRoomName, and_(get_gsr.c.lid == GSRRoomName.lid,
                                                    get_gsr.c.rid == GSRRoomName.rid), isouter=True) \
{'fraction_non_alphanumeric': 0.0831674408316744, 'fraction_numerical': 0.0057509400575094, 'mean_word_length': 2.2025495750708215, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2997471', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1265, 'n_words': 291}