<commit_before>from malcolm.core import method_takes, REQUIRED
from malcolm.core.vmetas import PointGeneratorMeta, NumberMeta
from malcolm.parts.builtin.layoutpart import LayoutPart
from malcolm.controllers.runnablecontroller import RunnableController
from malcolm.parts.ADCore.hdfwriterpart import DatasetSourceInfo


class DetectorDriverPart(LayoutPart):
    # Attributes
    readoutTime = None

    # Stored futures
    start_future = None

    def create_attributes(self):
        for data in super(DetectorDriverPart, self).create_attributes():
            yield data
        self.readoutTime = NumberMeta(
            "float64", "Time taken to readout detector").make_attribute(0.002)
        yield "readoutTime", self.readoutTime, self.readoutTime.set_value

    @RunnableController.PreConfigure
    def report_info(self, _):
        return [DatasetSourceInfo("detector", "primary")]

    @RunnableController.Configuring
    @method_takes(
        "generator", PointGeneratorMeta("Generator instance"), REQUIRED)
    def configure(self, task, completed_steps, steps_to_do, part_info, params):
        durations = set()
        for i in range(completed_steps, completed_steps + steps_to_do):
            point = params.generator.get_point(i)
            durations.add(point.duration)
        assert len(durations) == 1, \<commit_msg>Only check up to 5000 points for duration as it's slow...<commit_after>from malcolm.core import method_also_takes, REQUIRED, method_takes
from malcolm.core.vmetas import PointGeneratorMeta, NumberMeta
from malcolm.parts.builtin.layoutpart import LayoutPart
from malcolm.controllers.runnablecontroller import RunnableController
from malcolm.parts.ADCore.hdfwriterpart import DatasetSourceInfo


# Maximum number of points to check for fixed duration
MAX_CHECK = 5000


class DetectorDriverPart(LayoutPart):
    # Attributes
    readoutTime = None

    # Stored futures
    start_future = None

    def create_attributes(self):
        for data in super(DetectorDriverPart, self).create_attributes():
            yield data
        self.readoutTime = NumberMeta(
            "float64", "Time taken to readout detector").make_attribute(0.002)
        yield "readoutTime", self.readoutTime, self.readoutTime.set_value

    @RunnableController.PreConfigure
    def report_info(self, _):
        return [DatasetSourceInfo("detector", "primary")]

    @RunnableController.Configuring
    @method_takes(
        "generator", PointGeneratorMeta("Generator instance"), REQUIRED)
    def configure(self, task, completed_steps, steps_to_do, part_info, params):
        durations = set()
        max_points = min(MAX_CHECK, completed_steps + steps_to_do)
        for i in range(completed_steps, max_points):
            point = params.generator.get_point(i)
            durations.add(point.duration)
        assert len(durations) == 1, \
{'fraction_non_alphanumeric': 0.08208173244848062, 'fraction_numerical': 0.007684247293049249, 'mean_word_length': 3.789297658862876, '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': '6070814', 'n_tokens_mistral': 835, 'n_tokens_neox': 790, 'n_words': 195}