<commit_before>"""Provide data suitable for Fava's charts. """
import datetime
from typing import Generator
from typing import List
from typing import Optional
from typing import Tuple
from typing import Union

from beancount.core import flags
from beancount.core import realization
from beancount.core.amount import Amount
from beancount.core.data import iter_entry_dates
from beancount.core.data import Transaction
from beancount.core.inventory import Inventory
from beancount.core.number import Decimal
from beancount.core.position import Position
from flask.json import JSONEncoder

from fava.core.module_base import FavaModule
from fava.core.tree import Tree
from fava.helpers import FavaAPIException
from fava.template_filters import cost_or_value
from fava.template_filters import units
from fava.util import listify
from fava.util import pairwise
from fava.util.date import Interval


def inv_to_dict(inventory):
    """Convert an inventory to a simple cost->number dict."""
    return {pos.units.currency: pos.units.number for pos in inventory}


Inventory.for_json = inv_to_dict  # type: ignore


class FavaJSONEncoder(JSONEncoder):<commit_msg>be explicit about using simplejson<commit_after>"""Provide data suitable for Fava's charts. """
import datetime
from typing import Generator
from typing import List
from typing import Optional
from typing import Tuple
from typing import Union

from beancount.core import flags
from beancount.core import realization
from beancount.core.amount import Amount
from beancount.core.data import iter_entry_dates
from beancount.core.data import Transaction
from beancount.core.inventory import Inventory
from beancount.core.number import Decimal
from beancount.core.position import Position
from simplejson import JSONEncoder

from fava.core.module_base import FavaModule
from fava.core.tree import Tree
from fava.helpers import FavaAPIException
from fava.template_filters import cost_or_value
from fava.template_filters import units
from fava.util import listify
from fava.util import pairwise
from fava.util.date import Interval


def inv_to_dict(inventory):
    """Convert an inventory to a simple cost->number dict."""
    return {pos.units.currency: pos.units.number for pos in inventory}


Inventory.for_json = inv_to_dict  # type: ignore


class FavaJSONEncoder(JSONEncoder):
{'fraction_non_alphanumeric': 0.053671103477887505, 'fraction_numerical': 0.0, 'mean_word_length': 5.695402298850575, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5768073', 'n_tokens_mistral': 646, 'n_tokens_neox': 634, 'n_words': 241}