# Path: budgettracker/data.py
# def split_income_expenses(transactions):
#     income = filter(lambda tx: tx.amount > 0.0, transactions)
#     expenses = filter(lambda tx: tx.amount <= 0.0, transactions)
#     return income, expenses
# 
# def extract_transactions_by_label(transactions, labels):
#     def match_label(tx):
#         for exp in labels:
#             if re.match(exp, tx.label):
#                 return True
#         return False
#     matching = filter(match_label, transactions)
#     transactions = filter_out_transactions(transactions, matching)
#     return matching, transactions
# 
# 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)
# 
# def sort_transactions(transactions):
#     return sorted(transactions, key=lambda tx: tx.date, reverse=True)
# 
# def period_to_months(start_date, end_date):
#     dates = [start_date.replace(day=1)]
#     end_date = end_date.replace(day=1) - monthdelta(1)
#     while dates[-1] < end_date:
#         dates.append(dates[-1] + monthdelta(1))
#     return dates


from collections import namedtuple, OrderedDict
from .data import (split_income_expenses, extract_transactions_by_label, filter_transactions_period,
                   sort_transactions, period_to_months)
from monthdelta import monthdelta
import datetime


class Budget(namedtuple('Budget', ['month', 'transactions', 'income_transactions', 'planned_expenses_transactions',
    'expenses_transactions', 'real_balance', 'balance', 'income', 'planned_expenses', 'expenses',
    'savings',  'savings_goal', 'expected_real_balance', 'expected_balance', 'expected_income',
    'expected_planned_expenses', 'expected_savings', 'expected_remaining'])):

    @property
    def undetected_planned_expenses(self):
        return self.expected_planned_expenses - self.planned_expenses

    @property
    def all_expenses(self):
        current = datetime.date.today().replace(day=1)
        if self.month >= current:
            return self.expenses + self.expected_planned_expenses
        return self.expenses + self.planned_expenses

    @property
    def all_expected_expenses(self):

# Path: budgettracker/data.py
# def split_income_expenses(transactions):
#     income = filter(lambda tx: tx.amount > 0.0, transactions)
#     expenses = filter(lambda tx: tx.amount <= 0.0, transactions)
#     return income, expenses
# 
# def extract_transactions_by_label(transactions, labels):
#     def match_label(tx):
#         for exp in labels:
#             if re.match(exp, tx.label):
#                 return True
#         return False
#     matching = filter(match_label, transactions)
#     transactions = filter_out_transactions(transactions, matching)
#     return matching, transactions
# 
# 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)
# 
# def sort_transactions(transactions):
#     return sorted(transactions, key=lambda tx: tx.date, reverse=True)
# 
# def period_to_months(start_date, end_date):
#     dates = [start_date.replace(day=1)]
#     end_date = end_date.replace(day=1) - monthdelta(1)
#     while dates[-1] < end_date:
#         dates.append(dates[-1] + monthdelta(1))
#     return dates


# Path: budgettracker/budget.py
from collections import namedtuple, OrderedDict
from .data import (split_income_expenses, extract_transactions_by_label, filter_transactions_period,
                   sort_transactions, period_to_months)
from monthdelta import monthdelta
import datetime



class Budget(namedtuple('Budget', ['month', 'transactions', 'income_transactions', 'planned_expenses_transactions',
    'expenses_transactions', 'real_balance', 'balance', 'income', 'planned_expenses', 'expenses',
    'savings',  'savings_goal', 'expected_real_balance', 'expected_balance', 'expected_income',
    'expected_planned_expenses', 'expected_savings', 'expected_remaining'])):

    @property
    def undetected_planned_expenses(self):
        return self.expected_planned_expenses - self.planned_expenses

    @property
    def all_expenses(self):
        current = datetime.date.today().replace(day=1)
        if self.month >= current:
            return self.expenses + self.expected_planned_expenses
        return self.expenses + self.planned_expenses

    @property
    def all_expected_expenses(self):

        return self.expenses + self.expected_planned_expenses