<commit_before>from sqlalchemy import Column, Integer, String, Text, ForeignKey
from sqlalchemy.orm import relationship

from database.main import Base


class SavedCharacter(Base):
    """
    This table holds information about saved player characters
        name - the name of the character
        character_class - the class of the character
        level - the level of the character
        XXX_id - the ID to the row in the saved_character_XXX table associated with this saved character
        gold - the amount of gold the character has
    """
    __tablename__ = 'saved_character'

    entry = Column(Integer, primary_key=True)
    name = Column(String(60))
    character_class = Column('class', String(60))
    level = Column(Integer)
    loaded_scripts_id = Column(Integer, ForeignKey('saved_character_loaded_scripts.saved_character_id'))
    killed_monsters_id = Column(Integer, ForeignKey('saved_character_killed_monsters.saved_character_id'))
    completed_quests_id = Column(Integer, ForeignKey('saved_character_completed_quests.saved_character_id'))
    inventory_id = Column(Integer, ForeignKey('saved_character_inventory.saved_character_id'))
    gold = Column(Integer)

    loaded_scripts = relationship('LoadedScripts', foreign_keys=[loaded_scripts_id], uselist=True)
    killed_monsters = relationship('KilledMonsters', foreign_keys=[killed_monsters_id], uselist=True)
    inventory = relationship('Inventory', foreign_keys=[inventory_id], uselist=True)
    completed_quests = relationship('CompletedQuests', foreign_keys=[completed_quests_id], uselist=True)

    headpiece_id = Column(Integer, ForeignKey('item_template.entry'))
    shoulderpad_id = Column(Integer, ForeignKey('item_template.entry'))
    necklace_id = Column(Integer, ForeignKey('item_template.entry'))
    chestguard_id = Column(Integer, ForeignKey('item_template.entry'))
    bracer_id = Column(Integer, ForeignKey('item_template.entry'))
    gloves_id = Column(Integer, ForeignKey('item_template.entry'))
    belt_id = Column(Integer, ForeignKey('item_template.entry'))
    leggings_id = Column(Integer, ForeignKey('item_template.entry'))
    boots_id = Column(Integer, ForeignKey('item_template.entry'))

    headpiece = relationship('ItemTemplate', foreign_keys=[headpiece_id])
    shoulderpad = relationship('ItemTemplate', foreign_keys=[shoulderpad_id])
    necklace = relationship('ItemTemplate', foreign_keys=[necklace_id])
    chestguard = relationship('ItemTemplate', foreign_keys=[chestguard_id])
    bracer = relationship('ItemTemplate', foreign_keys=[bracer_id])
    gloves = relationship('ItemTemplate', foreign_keys=[gloves_id])
    belt = relationship('ItemTemplate', foreign_keys=[belt_id])
    leggings = relationship('ItemTemplate', foreign_keys=[leggings_id])
    boots = relationship('ItemTemplate', foreign_keys=[boots_id])

    def build_equipment(self) -> {str: 'Item' or None}:
        """
        Create a dictionary holding the character's equipment as the Character class holds it
        :return:
        """
        from entities import (CHARACTER_DEFAULT_EQUIPMENT, CHARACTER_EQUIPMENT_BOOTS_KEY,
                              CHARACTER_EQUIPMENT_LEGGINGS_KEY,
                              CHARACTER_EQUIPMENT_BELT_KEY, CHARACTER_EQUIPMENT_GLOVES_KEY,
                              CHARACTER_EQUIPMENT_BRACER_KEY,
                              CHARACTER_EQUIPMENT_CHESTGUARD_KEY, CHARACTER_EQUIPMENT_HEADPIECE_KEY,
                              CHARACTER_EQUIPMENT_NECKLACE_KEY,
                              CHARACTER_EQUIPMENT_SHOULDERPAD_KEY)
        saved_equipment = CHARACTER_DEFAULT_EQUIPMENT

        saved_equipment[CHARACTER_EQUIPMENT_BOOTS_KEY] = self.boots
        saved_equipment[CHARACTER_EQUIPMENT_LEGGINGS_KEY] = self.leggings
        saved_equipment[CHARACTER_EQUIPMENT_BELT_KEY] = self.belt
        saved_equipment[CHARACTER_EQUIPMENT_GLOVES_KEY] = self.gloves
        saved_equipment[CHARACTER_EQUIPMENT_BRACER_KEY] = self.bracer
        saved_equipment[CHARACTER_EQUIPMENT_CHESTGUARD_KEY] = self.chestguard
        saved_equipment[CHARACTER_EQUIPMENT_SHOULDERPAD_KEY] = self.shoulderpad
        saved_equipment[CHARACTER_EQUIPMENT_NECKLACE_KEY] = self.necklace
        saved_equipment[CHARACTER_EQUIPMENT_HEADPIECE_KEY] = self.headpiece

        return saved_equipment<commit_msg>:bug: Loading a character will now properly convert its equipment to an Item object from ItemTemplate<commit_after>from sqlalchemy import Column, Integer, String, Text, ForeignKey
from sqlalchemy.orm import relationship

from models.items.item_template import ItemTemplate
from database.main import Base


class SavedCharacter(Base):
    """
    This table holds information about saved player characters
        name - the name of the character
        character_class - the class of the character
        level - the level of the character
        XXX_id - the ID to the row in the saved_character_XXX table associated with this saved character
        gold - the amount of gold the character has
    """
    __tablename__ = 'saved_character'

    entry = Column(Integer, primary_key=True)
    name = Column(String(60))
    character_class = Column('class', String(60))
    level = Column(Integer)
    loaded_scripts_id = Column(Integer, ForeignKey('saved_character_loaded_scripts.saved_character_id'))
    killed_monsters_id = Column(Integer, ForeignKey('saved_character_killed_monsters.saved_character_id'))
    completed_quests_id = Column(Integer, ForeignKey('saved_character_completed_quests.saved_character_id'))
    inventory_id = Column(Integer, ForeignKey('saved_character_inventory.saved_character_id'))
    gold = Column(Integer)

    loaded_scripts = relationship('LoadedScripts', foreign_keys=[loaded_scripts_id], uselist=True)
    killed_monsters = relationship('KilledMonsters', foreign_keys=[killed_monsters_id], uselist=True)
    inventory = relationship('Inventory', foreign_keys=[inventory_id], uselist=True)
    completed_quests = relationship('CompletedQuests', foreign_keys=[completed_quests_id], uselist=True)

    headpiece_id = Column(Integer, ForeignKey('item_template.entry'))
    shoulderpad_id = Column(Integer, ForeignKey('item_template.entry'))
    necklace_id = Column(Integer, ForeignKey('item_template.entry'))
    chestguard_id = Column(Integer, ForeignKey('item_template.entry'))
    bracer_id = Column(Integer, ForeignKey('item_template.entry'))
    gloves_id = Column(Integer, ForeignKey('item_template.entry'))
    belt_id = Column(Integer, ForeignKey('item_template.entry'))
    leggings_id = Column(Integer, ForeignKey('item_template.entry'))
    boots_id = Column(Integer, ForeignKey('item_template.entry'))

    headpiece: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[headpiece_id])
    shoulderpad: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[shoulderpad_id])
    necklace: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[necklace_id])
    chestguard: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[chestguard_id])
    bracer: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[bracer_id])
    gloves: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[gloves_id])
    belt: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[belt_id])
    leggings: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[leggings_id])
    boots: ItemTemplate or None = relationship('ItemTemplate', foreign_keys=[boots_id])

    def build_equipment(self) -> {str: 'Item' or None}:
        """
        Create a dictionary holding the character's equipment as the Character class holds it
        :return:
        """
        from entities import (CHARACTER_DEFAULT_EQUIPMENT, CHARACTER_EQUIPMENT_BOOTS_KEY,
                              CHARACTER_EQUIPMENT_LEGGINGS_KEY,
                              CHARACTER_EQUIPMENT_BELT_KEY, CHARACTER_EQUIPMENT_GLOVES_KEY,
                              CHARACTER_EQUIPMENT_BRACER_KEY,
                              CHARACTER_EQUIPMENT_CHESTGUARD_KEY, CHARACTER_EQUIPMENT_HEADPIECE_KEY,
                              CHARACTER_EQUIPMENT_NECKLACE_KEY,
                              CHARACTER_EQUIPMENT_SHOULDERPAD_KEY)
        saved_equipment = CHARACTER_DEFAULT_EQUIPMENT

        saved_equipment[CHARACTER_EQUIPMENT_BOOTS_KEY] = self.boots
        saved_equipment[CHARACTER_EQUIPMENT_LEGGINGS_KEY] = self.leggings
        saved_equipment[CHARACTER_EQUIPMENT_BELT_KEY] = self.belt
        saved_equipment[CHARACTER_EQUIPMENT_GLOVES_KEY] = self.gloves
        saved_equipment[CHARACTER_EQUIPMENT_BRACER_KEY] = self.bracer
        saved_equipment[CHARACTER_EQUIPMENT_CHESTGUARD_KEY] = self.chestguard
        saved_equipment[CHARACTER_EQUIPMENT_SHOULDERPAD_KEY] = self.shoulderpad
        saved_equipment[CHARACTER_EQUIPMENT_NECKLACE_KEY] = self.necklace
        saved_equipment[CHARACTER_EQUIPMENT_HEADPIECE_KEY] = self.headpiece

        # convert the each equipment ItemTemplate to an Item object
        for slot, item in saved_equipment.items():
            if item is not None:
                saved_equipment[slot] = item.convert_to_item_object()

        return saved_equipment
{'fraction_non_alphanumeric': 0.08077298881771795, 'fraction_numerical': 0.0008685267614808381, 'mean_word_length': 4.352701917489831, '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': '112204', 'n_tokens_mistral': 2777, 'n_tokens_neox': 2687, 'n_words': 502}