<commit_before>from rockit.core import serializers
from rockit.core.holders import Holder

class MixesHolder(Holder):
    """
    A holder that collects all items that can be assigned to when action
    """

    CONTAINER_WHEN = 'when'
    CONTAINER_THEN = 'then'
    CONTAINER_FINAL = 'final'

    def __init__(self, association):
        super(MixesHolder, self).__init__()

        self.association = serializers.AssociationSerializer(association).data

        self.when = self._create_container(self.CONTAINER_WHEN)
        self.then = self._create_container(self.CONTAINER_THEN)
        self.final = self._create_container(self.CONTAINER_FINAL)

        self.dirty = False

    def add_final(self, **kwargs):
        """
        Add a final item
        """
        self.final['items'].append({
            'identifier': kwargs.get('identifier', 'NOT_SET'),
            'name': kwargs.get('name', 'NOT_SET')
        })

        self.dirty = True


    def add_then(self, **kwargs):
        """
        Add a then item
        """
        self.then['items'].append({
            'identifier': kwargs.get('identifier', 'NOT_SET'),
            'name': kwargs.get('name', 'NOT_SET')
        })

        self.dirty = True

    def add_when(self, **kwargs):
        """
        Add a when item
        """
        self.when['items'].append({
            'identifier': kwargs.get('identifier', 'NOT_SET'),
            'name': kwargs.get('name', 'NOT_SET')
        })

        self.dirty = True


    def get_content(self):
        """
        Override by adding when, then, final before get content
        """
        if self.dirty:
            self.reset_group(self.CONTAINER_WHEN)
            self.reset_group(self.CONTAINER_THEN)
            self.reset_group(self.CONTAINER_FINAL)

            if len(self.when['items']) > 0:
                self.append(self.when, self.CONTAINER_WHEN)

            if len(self.then['items']) > 0:
                self.append(self.then, self.CONTAINER_THEN)

            if len(self.final['items']) > 0:
                self.append(self.final, self.CONTAINER_FINAL)
        
        return super(MixesHolder, self).get_content()

    def _create_container(self, container):
        self.create_group(container)

        return {
            'association': self.association,
            'items': list()
        }

class MixesDetailsHolder(Holder):
    """
    Mixes details holder
    """

    <commit_msg>Updates<commit_after>from rockit.core import serializers
from rockit.core.holders import Holder

class MixesHolder(Holder):
    """
    A holder that collects all items that can be assigned to when action
    """

    CONTAINER_WHEN = 'when'
    CONTAINER_THEN = 'then'
    CONTAINER_FINAL = 'final'

    def __init__(self, association):
        super(MixesHolder, self).__init__()

        self.association = serializers.AssociationSerializer(association).data

        self.when = self._create_container(self.CONTAINER_WHEN)
        self.then = self._create_container(self.CONTAINER_THEN)
        self.final = self._create_container(self.CONTAINER_FINAL)

        self.dirty = False

    def add_final(self, **kwargs):
        """
        Add a final item
        """
        self.final['items'].append({
            'identifier': kwargs.get('identifier', 'NOT_SET'),
            'name': kwargs.get('name', 'NOT_SET')
        })

        self.dirty = True


    def add_then(self, **kwargs):
        """
        Add a then item
        """
        self.then['items'].append({
            'identifier': kwargs.get('identifier', 'NOT_SET'),
            'name': kwargs.get('name', 'NOT_SET')
        })

        self.dirty = True

    def add_when(self, **kwargs):
        """
        Add a when item
        """
        self.when['items'].append({
            'identifier': kwargs.get('identifier', 'NOT_SET'),
            'name': kwargs.get('name', 'NOT_SET')
        })

        self.dirty = True


    def get_content(self):
        """
        Override by adding when, then, final before get content
        """
        if self.dirty:
            self.reset_group(self.CONTAINER_WHEN)
            self.reset_group(self.CONTAINER_THEN)
            self.reset_group(self.CONTAINER_FINAL)

            if len(self.when['items']) > 0:
                self.append(self.when, self.CONTAINER_WHEN)

            if len(self.then['items']) > 0:
                self.append(self.then, self.CONTAINER_THEN)

            if len(self.final['items']) > 0:
                self.append(self.final, self.CONTAINER_FINAL)
        
        return super(MixesHolder, self).get_content()

    def _create_container(self, container):
        self.create_group(container)

        return {
            'association': self.association,
            'items': list()
        }

class MixesDetailsHolder(Holder):
    """
    Mixes details holder
    """
{'fraction_non_alphanumeric': 0.12525667351129363, 'fraction_numerical': 0.0012320328542094457, 'mean_word_length': 2.0848638378720707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '638547', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1419, 'n_words': 280}