<commit_before># -*- coding: utf-8 -*-

"""
byceps.blueprints.ticket.service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2016 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from ...database import db

from ..party.models import Party
from ..seating.models import Category

from .models import Ticket


def find_ticket_for_user(user, party):
    """Return the ticket used by the user for the party, or `None` if not
    found.
    """
    if user.is_anonymous:
        return None

    return Ticket.query \
        .filter_by(used_by=user) \
        .options(
            db.joinedload('occupied_seat').joinedload('area'),
        ) \
        .for_party(party) \
        .first()


def uses_any_ticket_for_party(user, party):
    """Return `True` if the user uses any ticket for that party."""
    count = Ticket.query \
        .filter_by(used_by=user) \
        .for_party(party) \
        .count()

    return count > 0


def get_attended_parties(user):
    """Return the parties the user has attended."""
    return Party.query \
        .join(Category).join(Ticket).filter(Ticket.used_by == user) \
        .all()


def count_tickets_for_party(party):
    """Return the number of "sold" (i.e. generated) tickets for that party."""
    return Ticket.query \
        .join(Category).filter(Category.party_id == party.id) \
        .count()<commit_msg>Simlified by using custom query method.<commit_after># -*- coding: utf-8 -*-

"""
byceps.blueprints.ticket.service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2016 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from ...database import db

from ..party.models import Party
from ..seating.models import Category

from .models import Ticket


def find_ticket_for_user(user, party):
    """Return the ticket used by the user for the party, or `None` if not
    found.
    """
    if user.is_anonymous:
        return None

    return Ticket.query \
        .filter_by(used_by=user) \
        .options(
            db.joinedload('occupied_seat').joinedload('area'),
        ) \
        .for_party(party) \
        .first()


def uses_any_ticket_for_party(user, party):
    """Return `True` if the user uses any ticket for that party."""
    count = Ticket.query \
        .filter_by(used_by=user) \
        .for_party(party) \
        .count()

    return count > 0


def get_attended_parties(user):
    """Return the parties the user has attended."""
    return Party.query \
        .join(Category).join(Ticket).filter(Ticket.used_by == user) \
        .all()


def count_tickets_for_party(party):
    """Return the number of "sold" (i.e. generated) tickets for that party."""
    return Ticket.query.for_party(party).count()
{'fraction_non_alphanumeric': 0.14863870493009565, 'fraction_numerical': 0.007358351729212656, 'mean_word_length': 2.73489010989011, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3389380', 'n_tokens_mistral': 873, 'n_tokens_neox': 826, 'n_words': 227}