<commit_before>from stp_core.common.log import getlogger
from collections import deque
from common.exceptions import PlenumValueError, LogicError

logger = getlogger()


class LedgerUncommittedTracker:

    def __init__(self):
        self.un_committed = deque()

    def apply_batch(self, state_root, ledger_size):

        un_committed_state = ()

        if state_root != "":
            un_committed_state += (state_root,)
        else:
            raise PlenumValueError('state_root',
                                   state_root,
                                   "No state root given")

        if ledger_size > 0:
            un_committed_state += (ledger_size,)
        else:
            raise PlenumValueError('ledger_size',
                                   ledger_size,
                                   "Incorrect size of ledger given")

        self.un_committed.append(un_committed_state)

    def commit_batch(self):
        return self.un_committed.popleft()

    def reject_batch(self):
        if len(self.un_committed) != 0:
            return self.un_committed.pop()
        else:
            raise LogicError("No items to return")<commit_msg>small refactor and improved logic<commit_after>from stp_core.common.log import getlogger
from collections import deque
from common.exceptions import PlenumValueError, LogicError

logger = getlogger()


class LedgerUncommittedTracker:

    def __init__(self):
        self.un_committed = deque()

    def apply_batch(self, state_root, ledger_size):
        if state_root is None:
            raise PlenumValueError
        if (ledger_size is None) or ledger_size <= 0:
            raise PlenumValueError

        self.un_committed.append((state_root, ledger_size))

    def commit_batch(self):
        return self.un_committed.popleft()

    def reject_batch(self):
        if len(self.un_committed) == 0:
            raise LogicError
        self.un_committed.pop()
{'fraction_non_alphanumeric': 0.07553026383859286, 'fraction_numerical': 0.0020693222969477496, 'mean_word_length': 2.234113712374582, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5385216', 'n_tokens_mistral': 569, 'n_tokens_neox': 539, 'n_words': 127}