<commit_before>import warnings
import time
import datetime

from flask.ext.admin.babel import lazy_gettext
from flask.ext.admin.model import filters
from flask.ext.admin.contrib.sqla import tools
from sqlalchemy.sql import not_

class BaseSQLAFilter(filters.BaseFilter):
    """
        Base SQLAlchemy filter.
    """
    def __init__(self, column, name, options=None, data_type=None):
        """
            Constructor.

            :param column:
                Model field
            :param name:
                Display name
            :param options:
                Fixed set of options
            :param data_type:
                Client data type
        """
        super(BaseSQLAFilter, self).__init__(name, options, data_type)

        self.column = column


# Common filters
class FilterEqual(BaseSQLAFilter):
    def apply(self, query, value):
        return query.filter(self.column == value)

    def operation(self):
        return lazy_gettext('equals')


class FilterNotEqual(BaseSQLAFilter):
    def apply(self, query, value):
        return query.filter(self.column != value)

    def operation(self):
        return lazy_gettext('not equal')


class FilterLike(BaseSQLAFilter):
    def apply(self, query, value):
        stmt = tools.parse_like_term(value)
        return query.filter(self.column.ilike(stmt))

    def operation(self):
        return lazy_gettext('contains')


class FilterNotLike(BaseSQLAFilter):
    def apply(self, query, value):
        stmt = tools.parse_like_term(value)
        return query.filter(~self.column.ilike(stmt))

    def operation(self):
        return lazy_gettext('not contains')


class FilterGreater(BaseSQLAFilter):
    def apply(self, query, value):
        return query.filter(self.column > value)

    def operation(self):
        return lazy_gettext('greater than')


class FilterSmaller(BaseSQLAFilter):
    def apply(self, query, value):
        return query.filter(self.column < value)

    def operation(self):
        return lazy_gettext('smaller than')


# Customized type filters
class BooleanEqualFilter(FilterEqual, filters.BaseBooleanFilter):
    pass
    

class BooleanNotEqualFilter(FilterNotEqual, filters.BaseBooleanFilter):
    pass
    
    
class DateEqualFilter(FilterEqual, filters.BaseDateFilter):
    pass

    
class DateNotEqualFilter(FilterNotEqual, filters.BaseDateFilter):
    pass
        

class DateGreaterFilter(FilterGreater, filters.BaseDateFilter):
    pass
        

class DateSmallerFilter(FilterSmaller, filters.BaseDateFilter):
    pass
        

class DateBetweenFilter(BaseSQLAFilter):
    # do not use clean() for splitting range into values, it will display the [] in the input
    def apply(self, query, value):
        value = [datetime.datetime.strptime(range, '%Y-%m-%d') for range in value.split(' to ')]
        return query.filter(self.column.between(value[0], value[1]))

    def operation(self):
        return lazy_gettext('between')

    def validate(self, value):
        try:
            value = [datetime.datetime.strptime(range, '%Y-%m-%d') for range in value.split(' to ')]
            # if " to " is missing, fail validation
            if len(value) == 2:
                return True
            else:
                return False        
        except ValueError:
            return False        
        

class DateNotBetweenFilter(DateBetweenFilter):
    def apply(self, query, value):
        value = [datetime.datetime.strptime(range, '%Y-%m-%d') for range in value.split(' to ')]
        # ~between() isn't possible until sqlalchemy 1.0.0
        return query.filter(not_(self.column.between(value[0], value[1])))
        
    def operation(self):
        return lazy_gettext('not between')
        
            
class DateTimeEqualFilter(FilterEqual, filters.BaseDateTimeFilter):<commit_msg>remove comment, irrelevant after changing location of .clean()<commit_after>import warnings
import time
import datetime

from flask.ext.admin.babel import lazy_gettext
from flask.ext.admin.model import filters
from flask.ext.admin.contrib.sqla import tools
from sqlalchemy.sql import not_

class BaseSQLAFilter(filters.BaseFilter):
    """
        Base SQLAlchemy filter.
    """
    def __init__(self, column, name, options=None, data_type=None):
        """
            Constructor.

            :param column:
                Model field
            :param name:
                Display name
            :param options:
                Fixed set of options
            :param data_type:
                Client data type
        """
        super(BaseSQLAFilter, self).__init__(name, options, data_type)

        self.column = column


# Common filters
class FilterEqual(BaseSQLAFilter):
    def apply(self, query, value):
        return query.filter(self.column == value)

    def operation(self):
        return lazy_gettext('equals')


class FilterNotEqual(BaseSQLAFilter):
    def apply(self, query, value):
        return query.filter(self.column != value)

    def operation(self):
        return lazy_gettext('not equal')


class FilterLike(BaseSQLAFilter):
    def apply(self, query, value):
        stmt = tools.parse_like_term(value)
        return query.filter(self.column.ilike(stmt))

    def operation(self):
        return lazy_gettext('contains')


class FilterNotLike(BaseSQLAFilter):
    def apply(self, query, value):
        stmt = tools.parse_like_term(value)
        return query.filter(~self.column.ilike(stmt))

    def operation(self):
        return lazy_gettext('not contains')


class FilterGreater(BaseSQLAFilter):
    def apply(self, query, value):
        return query.filter(self.column > value)

    def operation(self):
        return lazy_gettext('greater than')


class FilterSmaller(BaseSQLAFilter):
    def apply(self, query, value):
        return query.filter(self.column < value)

    def operation(self):
        return lazy_gettext('smaller than')


# Customized type filters
class BooleanEqualFilter(FilterEqual, filters.BaseBooleanFilter):
    pass
    

class BooleanNotEqualFilter(FilterNotEqual, filters.BaseBooleanFilter):
    pass
    
    
class DateEqualFilter(FilterEqual, filters.BaseDateFilter):
    pass

    
class DateNotEqualFilter(FilterNotEqual, filters.BaseDateFilter):
    pass
        

class DateGreaterFilter(FilterGreater, filters.BaseDateFilter):
    pass
        

class DateSmallerFilter(FilterSmaller, filters.BaseDateFilter):
    pass
        

class DateBetweenFilter(BaseSQLAFilter):
    def apply(self, query, value):
        value = [datetime.datetime.strptime(range, '%Y-%m-%d') for range in value.split(' to ')]
        return query.filter(self.column.between(value[0], value[1]))

    def operation(self):
        return lazy_gettext('between')

    def validate(self, value):
        try:
            value = [datetime.datetime.strptime(range, '%Y-%m-%d') for range in value.split(' to ')]
            # if " to " is missing, fail validation
            if len(value) == 2:
                return True
            else:
                return False        
        except ValueError:
            return False        
        

class DateNotBetweenFilter(DateBetweenFilter):
    def apply(self, query, value):
        value = [datetime.datetime.strptime(range, '%Y-%m-%d') for range in value.split(' to ')]
        # ~between() isn't possible until sqlalchemy 1.0.0
        return query.filter(not_(self.column.between(value[0], value[1])))
        
    def operation(self):
        return lazy_gettext('not between')
        
            
class DateTimeEqualFilter(FilterEqual, filters.BaseDateTimeFilter):
{'fraction_non_alphanumeric': 0.09841228185277523, 'fraction_numerical': 0.002099462012859205, 'mean_word_length': 2.6874697629414612, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1539651', 'n_tokens_mistral': 2157, 'n_tokens_neox': 2074, 'n_words': 530}