<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-


class DungeonUnits:

    """
    Dungeon units model
    """

    def __init__(self, **kwargs):
        self.db = kwargs["db"]

    def _get_dungeon_units_map(self, units):
        dungeon_units_map = {}

        for dungeon_unit in units:
            dungeon_id = dungeon_unit["dungeon_id"]

            if dungeon_id not in dungeon_units_map:
                dungeon_units_map[dungeon_id] = []

            dungeon_units_map[dungeon_id].append(dungeon_unit["unit_id"])

        return dungeon_units_map

    def get_dungeon_units(self):
        """
        Fetches units for one or many dungeons
        """
        cursor = self.db.cursor()

        cursor.execute("""SELECT
                          du.dungeon_id,
                          du.unit_id
                          FROM spiffyrpg_dungeon_units du
                          JOIN spiffyrpg_units u ON du.unit_id = u.id""")

        tmp_units = cursor.fetchall()
        cursor.close()
        units = []

        if tmp_units:
            for u in tmp_units:
                unit = dict(u)
                units.append(unit)

        return self._get_dungeon_units_map(units)<commit_msg>Modifies DungeonUnits model to return list instead of map<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-


class DungeonUnits:

    """
    Dungeon units model
    """

    def __init__(self, **kwargs):
        self.db = kwargs["db"]

    def _get_dungeon_units_map(self, units):
        dungeon_units_map = {}

        for dungeon_unit in units:
            dungeon_id = dungeon_unit["dungeon_id"]

            if dungeon_id not in dungeon_units_map:
                dungeon_units_map[dungeon_id] = []

            dungeon_units_map[dungeon_id].append(dungeon_unit["unit_id"])

        return dungeon_units_map

    def get_dungeon_units(self):
        """
        Fetches units for one or many dungeons
        """
        cursor = self.db.cursor()

        cursor.execute("""SELECT
                          du.dungeon_id,
                          du.unit_id
                          FROM spiffyrpg_dungeon_units du
                          JOIN spiffyrpg_units u ON du.unit_id = u.id""")

        tmp_units = cursor.fetchall()
        cursor.close()
        units = []

        if tmp_units:
            for u in tmp_units:
                unit = dict(u)
                units.append(unit)

        return units
{'fraction_non_alphanumeric': 0.09202453987730061, 'fraction_numerical': 0.0008179959100204499, 'mean_word_length': 1.6357758620689655, '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': '124311', 'n_tokens_mistral': 771, 'n_tokens_neox': 748, 'n_words': 149}