<commit_before>
from .base import Node
from datetime import timedelta
from ebu_tt_live.bindings._ebuttdt import LimitedClockTimingType, FullClockTimingType
import time
import random


class FixedDelayNode(Node):

    _reference_clock = None
    _sequence = None

    def __init__(self, node_id, carriage_impl, reference_clock):
        super(FixedDelayNode, self).__init__(node_id, carriage_impl)
        self._reference_clock = reference_clock

        random_int = random.randint(0, 9999999999)
        new_identifier = 'sequence_{0}'.format(str(random_int))
        self._sequence = new_identifier

    def process_document(self, document):

        fixed_delay = LimitedClockTimingType(timedelta(seconds=2))

        # change the sequence identifier
        document.sequence_identifier = self._sequence

        # TODO: add an ebuttm:trace element to the document metadata

        # document is explicitly timed: modify the document
        if document.binding.body.begin or document.binding.body.end:

            if document.time_base == 'clock':

                document.set_begin(
                    LimitedClockTimingType(document.binding.body.begin.timedelta + fixed_delay.timedelta))

                document.set_end(
                    LimitedClockTimingType(document.binding.body.begin.timedelta + fixed_delay.timedelta))

                document.set_dur(
                    LimitedClockTimingType(document.binding.body.begin.timedelta + fixed_delay.timedelta))

            elif document.time_base == 'media':

                document.set_begin(
                    FullClockTimingType(document.binding.body.begin.timedelta + fixed_delay.timedelta))

                document.set_end(
                    FullClockTimingType(document.binding.body.begin.timedelta + fixed_delay.timedelta))

                document.set_dur(
                    FullClockTimingType(document.binding.body.begin.timedelta + fixed_delay.timedelta))

            # TODO: traverse all the elements on content and change their begin/end/dur attributes

            self._carriage_impl.emit_document(document)

        # document is implicitly timed: pause a while, re-emit later
        else:

            time.sleep(fixed_delay)
            self._carriage_impl.emit_document(document)<commit_msg>small fixes with begin/end/dur times<commit_after>
from .base import Node
from datetime import timedelta
from ebu_tt_live.bindings._ebuttdt import LimitedClockTimingType, FullClockTimingType
import time
import random


class FixedDelayNode(Node):

    _reference_clock = None
    _sequence = None

    def __init__(self, node_id, carriage_impl, reference_clock):
        super(FixedDelayNode, self).__init__(node_id, carriage_impl)
        self._reference_clock = reference_clock

        random_int = random.randint(0, 9999999999)
        new_identifier = 'sequence_{0}'.format(str(random_int))
        self._sequence = new_identifier

    def process_document(self, document):

        # change the sequence identifier
        document.sequence_identifier = self._sequence

        # TODO: add an ebuttm:trace element to the document metadata

        fixed_delay_int = 2

        # document is explicitly timed: modify the document
        if document.binding.body.begin or document.binding.body.end:

            if document.time_base == 'clock':

                fixed_delay = LimitedClockTimingType(timedelta(seconds=fixed_delay_int))

                document.set_begin(
                    LimitedClockTimingType(document.binding.body.begin.timedelta + fixed_delay.timedelta))

                document.set_end(
                    LimitedClockTimingType(document.binding.body.end.timedelta + fixed_delay.timedelta))

                document.set_dur(
                    LimitedClockTimingType(document.binding.body.dur.timedelta + fixed_delay.timedelta))

            elif document.time_base == 'media':

                fixed_delay = FullClockTimingType(timedelta(seconds=fixed_delay_int))

                document.set_begin(
                    FullClockTimingType(document.binding.body.begin.timedelta + fixed_delay.timedelta))

                document.set_end(
                    FullClockTimingType(document.binding.body.end.timedelta + fixed_delay.timedelta))

                document.set_dur(
                    FullClockTimingType(document.binding.body.dur.timedelta + fixed_delay.timedelta))

            # TODO: traverse all the elements on content and change their begin/end/dur attributes

            self._carriage_impl.emit_document(document)

        # document is implicitly timed: pause a while, re-emit later
        else:

            time.sleep(fixed_delay_int)
            self._carriage_impl.emit_document(document)
{'fraction_non_alphanumeric': 0.07264687302590019, 'fraction_numerical': 0.005474836807749, 'mean_word_length': 2.6176694592536176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6405374', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1243, 'n_words': 249}