<commit_before>import json
import hunting.sim.entities as entities


class GameObjectEncoder(json.JSONEncoder):
    def default(self, o):
        d = o.__dict__
        d.pop('owner', None)

        if isinstance(o, entities.GameObject):
            d.pop('log', None)
            d.pop('ai', None)
            return d
        elif isinstance(o, entities.Fighter):
            d.pop('death_function')
            return d
        elif isinstance(o, entities.ChangeableProperty):
            return {k: o.__dict__[k] for k in ['property_type', 'base']}
        else:
            return d


def encode_level(level):
    save_factions = [f for f in level.get_factions() if level.get_faction_info(f)['save'] is True]
    factions_to_objects = {f: level.get_objects_inside_faction(f) for f in save_factions}
    return json.dumps(factions_to_objects, cls=GameObjectEncoder, indent=2)<commit_msg>Add log to encoding output (still fails due to objects)<commit_after>import json
import hunting.sim.entities as entities


class GameObjectEncoder(json.JSONEncoder):
    def default(self, o):
        d = o.__dict__
        d.pop('owner', None)

        if isinstance(o, entities.GameObject):
            d.pop('log', None)
            d.pop('ai', None)
            return d
        elif isinstance(o, entities.Fighter):
            d.pop('death_function')
            return d
        elif isinstance(o, entities.ChangeableProperty):
            return {k: o.__dict__[k] for k in ['property_type', 'base']}
        else:
            return d


def encode_level(level):
    save_factions = {f: level.get_faction_info(f) for f in level.get_factions()
                     if level.get_faction_info(f)['save'] is True}

    for f in save_factions:
        save_factions[f]['objects'] = level.get_objects_inside_faction(f)

    output = {'log': level.log.events,
              'factions': save_factions}

    return json.dumps(output, cls=GameObjectEncoder, indent=2)
{'fraction_non_alphanumeric': 0.1105424769703173, 'fraction_numerical': 0.0010235414534288639, 'mean_word_length': 2.5871559633027523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5075934', 'n_tokens_mistral': 602, 'n_tokens_neox': 588, 'n_words': 147}