예제 #1
0
def calculate_budget(
    budgets: BudgetDict,
    account: str,
    date_from: datetime.date,
    date_to: datetime.date,
) -> Dict[str, Decimal]:
    """Calculate budget for an account.

    Args:
        budgets: A list of :class:`Budget` entries.
        account: An account name.
        date_from: Starting date.
        date_to: End date (exclusive).

    Returns:
        A dictionary of currency to Decimal with the budget for the
        specified account and period.
    """
    if account not in budgets:
        return {}

    currency_dict: Dict[str, Decimal] = defaultdict(Decimal)

    for single_day in days_in_daterange(date_from, date_to):
        matches = _matching_budgets(budgets, account, single_day)
        for budget in matches.values():
            currency_dict[
                budget.currency
            ] += budget.number / number_of_days_in_period(
                budget.period, single_day
            )
    return currency_dict
예제 #2
0
파일: budgets.py 프로젝트: adamgibbins/fava
def calculate_budget(budgets, account_name, date_from, date_to):
    """Calculate budget for an account.

    Args:
        budgets: A list of :class:`Budget` entries.
        account_name: An account name.
        date_from: Starting date.
        date_to: End date (exclusive).

    Returns:
        A dictionary of currency to Decimal with the budget for the
        specified account and period.
    """
    if account_name not in budgets:
        return {}

    currency_dict = defaultdict(Decimal)

    for single_day in days_in_daterange(date_from, date_to):
        matches = _matching_budgets(budgets, account_name, single_day)
        for budget in matches.values():
            currency_dict[budget.currency] += \
                budget.number / number_of_days_in_period(budget.period,
                                                         single_day)
    return currency_dict
예제 #3
0
    def budget(self, account_name, date_from, date_to):
        """
        Returns a dictionary (currency => number) with the budget for the
        specified account and period (excluding date_to).
        """
        currency_dict = defaultdict(lambda: Decimal(0.0))

        if account_name not in self.budgets.keys():
            return currency_dict

        for single_day in days_in_daterange(date_from, date_to):
            budget = self._matching_budget(account_name, single_day)
            if budget:
                currency_dict[budget.currency] += budget.number / number_of_days_in_period(budget.period, single_day)
        return dict(currency_dict)
예제 #4
0
    def budget(self, account_name, date_from, date_to):
        """
        Returns a dictionary (currency => number) with the budget for the
        specified account and period (excluding date_to).
        """
        currency_dict = defaultdict(lambda: Decimal(0.0))

        if account_name not in self.budgets.keys():
            return currency_dict

        for single_day in days_in_daterange(date_from, date_to):
            budget = self._matching_budget(account_name, single_day)
            if budget:
                currency_dict[budget.currency] += \
                    budget.number / number_of_days_in_period(budget.period,
                                                             single_day)
        return dict(currency_dict)
예제 #5
0
파일: budgets.py 프로젝트: aumayr/fava
def calculate_budget(budgets, account_name, date_from, date_to):
    """
    Returns a dictionary (currency => number) with the budget for the
    specified account and period (excluding date_to).
    """
    if account_name not in budgets.keys():
        return {}

    currency_dict = defaultdict(Decimal)

    for single_day in days_in_daterange(date_from, date_to):
        matches = _matching_budgets(budgets, account_name, single_day)
        for budget in matches.values():
            currency_dict[budget.currency] += \
                budget.number / number_of_days_in_period(budget.period,
                                                         single_day)
    return dict(currency_dict)
예제 #6
0
def calculate_budget(budgets, account_name, date_from, date_to):
    """
    Returns a dictionary (currency => number) with the budget for the
    specified account and period (excluding date_to).
    """
    if account_name not in budgets.keys():
        return {}

    currency_dict = defaultdict(Decimal)

    for single_day in days_in_daterange(date_from, date_to):
        matches = _matching_budgets(budgets, account_name, single_day)
        for budget in matches.values():
            currency_dict[budget.currency] += \
                budget.number / number_of_days_in_period(budget.period,
                                                         single_day)
    return dict(currency_dict)