<commit_before>from os import path

from ffflash import args, log, now, timeout
from ffflash.lib.files import read_json_file, write_json_file


def recent(changes):
    recent_file = path.abspath(args.recent)
    current = read_json_file(recent_file, fallback={})

    for field, values in changes.items():
        if field not in args.rignore:
            current[field] = current.get(field, {})
            for nid, data in values.items():
                data.update({'time': now})
                current[field][nid] = data

    current = dict(
        (field, dict(
            (nid, data) for nid, data in values.items() if
            data.get('time') and data['time'] > timeout
        )) for field, values in current.items()
    )
    write_json_file(recent_file, current)
    log.info('written recent {}'.format(recent_file))<commit_msg>Rewrite recent method in service module to use the new Container<commit_after>from ffflash import args, now, timeout
from ffflash.lib.container import Container


def recent(changes):
    container = Container('recent', args.recent)
    info = {'recent': {}}

    for field, data in changes.items():
        if field not in args.rignore:
            container.data[field] = container.data.get(field, {})
            info['recent'][field] = info['recent'].get(field, 0)

            for nid, message in data.items():
                message.update({'time': now})
                container.data[field][nid] = message
                info['recent'][field] += 1

    container.data = dict(
        (field, dict(
            (nid, msg) for nid, msg in data.items() if
            msg.get('time') and msg['time'] > timeout
        )) for field, data in container.data.items() if
        not field.startswith('_')
    )

    container.save(info=info)
{'fraction_non_alphanumeric': 0.12569832402234637, 'fraction_numerical': 0.0011173184357541898, 'mean_word_length': 2.5255905511811023, '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': '3579205', 'n_tokens_mistral': 542, 'n_tokens_neox': 514, 'n_words': 147}