<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2016 The Pycroft Authors. See the AUTHORS file.
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.
from abc import ABCMeta, abstractmethod
from collections import namedtuple
import csv
from datetime import datetime, date, timedelta
from decimal import Decimal
import difflib
from functools import partial
from itertools import chain, islice, starmap, tee, zip_longest
from io import StringIO
import operator
import re

from sqlalchemy import or_, and_, literal_column, literal, select, exists, not_
from sqlalchemy.orm import aliased
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy import func, between, Integer, cast

from pycroft import config, model
from pycroft.helpers.i18n import deferred_gettext, gettext, Message
from pycroft.lib.logging import log_user_event
from pycroft.lib.membership import make_member_of, remove_member_of
from pycroft.model import session
from pycroft.model.finance import (
    Account, BankAccount, BankAccountActivity, Split, Transaction, MembershipFee)
from pycroft.helpers.interval import (
    closed, single, Bound, Interval, IntervalSet, UnboundedInterval, closedopen,
    PositiveInfinity)
from pycroft.model.functions import sign, least
from pycroft.model.property import CurrentProperty
from pycroft.model.session import with_transaction
from pycroft.model.types import Money
from pycroft.model.user import User, Membership, PropertyGroup


def get_membership_fees(interval_set=None):
    """

    :param when:
    :return:
    """

    queries = []

    if interval_set is not None:
        for interval in interval_set:
            criteria = []

            if interval.begin is not None:
                if not interval.end == PositiveInfinity:
                    criteria.append(or_(
                        interval.begin <= MembershipFee.begins_on,
                        between(interval.begin,
                                MembershipFee.begins_on,
                                MembershipFee.ends_on)
                    ))

            if interval.end is not None:
                if interval.end == PositiveInfinity:
                    criteria.append(
                        interval.end > MembershipFee.begins_on
                    )
                else:
                    criteria.append(or_(
                        interval.end >= MembershipFee.ends_on,
                        between(interval.end,
                                MembershipFee.begins_on,
                                MembershipFee.ends_on)
                    ))


            queries.append(MembershipFee.q.filter(or_(*criteria)) \
                           .order_by(MembershipFee.begins_on))

    if len(queries) >= 1:
        result = queries[0]

        queries.pop(0)

        result.union(*tuple(queries))

        return result.all()
    else:
        return []


def get_membership_fee_for_date(target_date):
    """
    Get the membership fee which contains a given target date.
    :param date target_date: The date for which a corresponding membership
    fee should be found.
    :rtype: MembershipFee
    :raises sqlalchemy.orm.exc.NoResultFound if no membership fee was found
    :raises sqlalchemy.orm.exc.MultipleResultsFound if multiple membership fees
    were found.
    """
    return MembershipFee.q.filter(
        between(target_date, MembershipFee.begins_on,
                MembershipFee.ends_on)
    ).one()
<commit_msg>Remove unused function<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2016 The Pycroft Authors. See the AUTHORS file.
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.
from abc import ABCMeta, abstractmethod
from collections import namedtuple
import csv
from datetime import datetime, date, timedelta
from decimal import Decimal
import difflib
from functools import partial
from itertools import chain, islice, starmap, tee, zip_longest
from io import StringIO
import operator
import re

from sqlalchemy import or_, and_, literal_column, literal, select, exists, not_
from sqlalchemy.orm import aliased
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy import func, between, Integer, cast

from pycroft import config, model
from pycroft.helpers.i18n import deferred_gettext, gettext, Message
from pycroft.lib.logging import log_user_event
from pycroft.lib.membership import make_member_of, remove_member_of
from pycroft.model import session
from pycroft.model.finance import (
    Account, BankAccount, BankAccountActivity, Split, Transaction, MembershipFee)
from pycroft.helpers.interval import (
    closed, single, Bound, Interval, IntervalSet, UnboundedInterval, closedopen,
    PositiveInfinity)
from pycroft.model.functions import sign, least
from pycroft.model.property import CurrentProperty
from pycroft.model.session import with_transaction
from pycroft.model.types import Money
from pycroft.model.user import User, Membership, PropertyGroup


def get_membership_fee_for_date(target_date):
    """
    Get the membership fee which contains a given target date.
    :param date target_date: The date for which a corresponding membership
    fee should be found.
    :rtype: MembershipFee
    :raises sqlalchemy.orm.exc.NoResultFound if no membership fee was found
    :raises sqlalchemy.orm.exc.MultipleResultsFound if multiple membership fees
    were found.
    """
    return MembershipFee.q.filter(
        between(target_date, MembershipFee.begins_on,
                MembershipFee.ends_on)
    ).one()

{'fraction_non_alphanumeric': 0.06320422535211268, 'fraction_numerical': 0.003697183098591549, 'mean_word_length': 2.9922698524244553, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '3062899', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1509, 'n_words': 510}