<commit_before>from gnucash import Session
from decimal import Decimal
import time
from datetime import date
import enum


@enum.unique
class AccountTypes(enum.IntEnum):
    none = -1
    bank = 0
    cash = 1
    credit = 3
    asset = 2
    liability = 4
    stock = 5
    mutual_fund = 6
    currency = 7
    income = 8
    expense = 9
    equity = 10
    accounts_receivable = 11
    accounts_payable = 12
    root = 13
    trading = 14

gnucash_session = None


def initialize(file_uri):
    global gnucash_session
    gnucash_session = Session(file_uri, is_new=False)
    return gnucash_session


def get_session():
    return gnucash_session


def get_account(account_name):

    account = gnucash_session.get_book().get_root_account().lookup_by_full_name(account_name)

    if account is None:
        raise RuntimeError('Account %s is not found' % account_name)

    return account


def get_decimal(numeric):
    return Decimal(numeric.num()) / Decimal(numeric.denom())


def get_splits(account, start_date, end_date=None, credit=True, debit=True):

    start_time = time.mktime(start_date.timetuple())
    if not end_date:
        end_date = date.today()

    end_time = time.mktime(end_date.timetuple())

    result = []

    for split in account.GetSplitList():
        split_date = split.parent.GetDate()

        if start_time <= split_date < end_time:

            is_credit = split.GetAmount().num() > 0

            if credit and is_credit:
                result.append(split)
            elif debit and not is_credit:
                result.append(split)

    return result


def account_walker(account_list, ignore_list=None, place_holders=False, recursive=True):
    """<commit_msg>Get Splits should include end date.<commit_after>from gnucash import Session
from decimal import Decimal
import time
from datetime import date
import enum


@enum.unique
class AccountTypes(enum.IntEnum):
    none = -1
    bank = 0
    cash = 1
    credit = 3
    asset = 2
    liability = 4
    stock = 5
    mutual_fund = 6
    currency = 7
    income = 8
    expense = 9
    equity = 10
    accounts_receivable = 11
    accounts_payable = 12
    root = 13
    trading = 14

gnucash_session = None


def initialize(file_uri):
    global gnucash_session
    gnucash_session = Session(file_uri, is_new=False)
    return gnucash_session


def get_session():
    return gnucash_session


def get_account(account_name):

    account = gnucash_session.get_book().get_root_account().lookup_by_full_name(account_name)

    if account is None:
        raise RuntimeError('Account %s is not found' % account_name)

    return account


def get_decimal(numeric):
    return Decimal(numeric.num()) / Decimal(numeric.denom())


def get_splits(account, start_date, end_date=None, credit=True, debit=True):

    start_time = time.mktime(start_date.timetuple())
    if not end_date:
        end_date = date.today()

    end_time = time.mktime(end_date.timetuple())

    result = []

    for split in account.GetSplitList():
        split_date = split.parent.GetDate()

        if start_time <= split_date <= end_time:

            is_credit = split.GetAmount().num() > 0

            if credit and is_credit:
                result.append(split)
            elif debit and not is_credit:
                result.append(split)

    return result


def account_walker(account_list, ignore_list=None, place_holders=False, recursive=True):
    """
{'fraction_non_alphanumeric': 0.0851063829787234, 'fraction_numerical': 0.012824249489944622, 'mean_word_length': 2.895573212258797, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6403786', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1058, 'n_words': 275}