# 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
            continue
        for name in sorted(tx.categories or []):
            amounts.setdefault(name, 0)
            amounts[name] += abs(tx.amount)
            total += abs(tx.amount)
    categorized_total = sum(amounts.values())
    if total - categorized_total > 0:
        amounts[None] = total - categorized_total

    final = []
    for name, amount in sorted(amounts.items(), key=lambda t: t[0]):
        pct = round(amount * 100 / total, 0)
        if name in categories:
            final.append(ComputedCategory.from_category(categories[name], amount=amount, pct=pct,
                warning_threshold_multiplier=warning_threshold_multiplier))
        else:
            final.append(ComputedCategory(name=name, color=None, keywords=[],
                warning_threshold=None, amount=amount, pct=pct))
    for category in categories.values():
        if category.name not in amounts:
            final.append(ComputedCategory.from_category(category, amount=0, pct=0,
                warning_threshold_multiplier=warning_threshold_multiplier))
    return final


def match_categories(categories, label):
    matches = []
    for category in categories:
        for keyword in (category.keywords or []):
            if re.search(r"\b%s\b" % keyword, label, re.I):

# 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

            continue
        for name in sorted(tx.categories or []):
            amounts.setdefault(name, 0)
            amounts[name] += abs(tx.amount)
            total += abs(tx.amount)
    categorized_total = sum(amounts.values())
    if total - categorized_total > 0:
        amounts[None] = total - categorized_total

    final = []
    for name, amount in sorted(amounts.items(), key=lambda t: t[0]):
        pct = round(amount * 100 / total, 0)
        if name in categories:
            final.append(ComputedCategory.from_category(categories[name], amount=amount, pct=pct,
                warning_threshold_multiplier=warning_threshold_multiplier))
        else:
            final.append(ComputedCategory(name=name, color=None, keywords=[],
                warning_threshold=None, amount=amount, pct=pct))
    for category in categories.values():
        if category.name not in amounts:
            final.append(ComputedCategory.from_category(category, amount=0, pct=0,
                warning_threshold_multiplier=warning_threshold_multiplier))
    return final


def match_categories(categories, label):
    matches = []
    for category in categories:
        for keyword in (category.keywords or []):
            if re.search(r"\b%s\b" % keyword, label, re.I):

                matches.append(category.name)