# Path: budgettracker/data.py
# def filter_transactions_period(transactions, start_date=None, end_date=None):
#     if not start_date and not end_date:
#         return transactions
#     return filter(
#         lambda tx: (not start_date or tx.date >= start_date) and (not end_date or tx.date < end_date),
#         transactions)


from collections import namedtuple
from .data import filter_transactions_period
import re
    def to_dict(self):
        return {
            'name': self.name,
            'color': self.color,
            'keywords': self.keywords,
            'warning_threshold': self.warning_threshold
        }


class ComputedCategory(namedtuple('ComputedCategory', ['name', 'color', 'keywords', 'warning_threshold', 'amount', 'pct'])):
    @classmethod
    def from_category(cls, category, **kwargs):
        warning_threshold_multiplier = kwargs.pop('warning_threshold_multiplier', 1)
        warning_threshold = category.warning_threshold * warning_threshold_multiplier if category.warning_threshold else None
        return cls(name=category.name, color=category.color, keywords=category.keywords,
            warning_threshold=warning_threshold, **kwargs)

    @property
    def has_warning(self):
        return self.warning_threshold and self.amount > self.warning_threshold

    def to_str(self, famount):
        return "%s = %s (%s%%)%s" % (self.name or 'Uncategorized', famount(self.amount), self.pct,
            ' /!\ %s' % (famount(self.warning_threshold)) if self.has_warning else '')


def compute_categories(transactions, categories=None, start_date=None, end_date=None, warning_threshold_multiplier=1):
    categories = {c.name: c for c in categories or []}
    amounts = {}
    total = 0

# Path: budgettracker/data.py
# def filter_transactions_period(transactions, start_date=None, end_date=None):
#     if not start_date and not end_date:
#         return transactions
#     return filter(
#         lambda tx: (not start_date or tx.date >= start_date) and (not end_date or tx.date < end_date),
#         transactions)


# Path: budgettracker/categories.py
from collections import namedtuple
from .data import filter_transactions_period
import re

    def to_dict(self):
        return {
            'name': self.name,
            'color': self.color,
            'keywords': self.keywords,
            'warning_threshold': self.warning_threshold
        }


class ComputedCategory(namedtuple('ComputedCategory', ['name', 'color', 'keywords', 'warning_threshold', 'amount', 'pct'])):
    @classmethod
    def from_category(cls, category, **kwargs):
        warning_threshold_multiplier = kwargs.pop('warning_threshold_multiplier', 1)
        warning_threshold = category.warning_threshold * warning_threshold_multiplier if category.warning_threshold else None
        return cls(name=category.name, color=category.color, keywords=category.keywords,
            warning_threshold=warning_threshold, **kwargs)

    @property
    def has_warning(self):
        return self.warning_threshold and self.amount > self.warning_threshold

    def to_str(self, famount):
        return "%s = %s (%s%%)%s" % (self.name or 'Uncategorized', famount(self.amount), self.pct,
            ' /!\ %s' % (famount(self.warning_threshold)) if self.has_warning else '')


def compute_categories(transactions, categories=None, start_date=None, end_date=None, warning_threshold_multiplier=1):
    categories = {c.name: c for c in categories or []}
    amounts = {}
    total = 0

    for tx in filter_transactions_period(transactions, start_date, end_date):