<commit_before>"""
This module provides filters.
"""

import re
from itertools import izip
from pprint import pprint

from penchy.jobs.elements import Filter


class Tamiflex(Filter):
    pass


class HProf(Filter):
    pass


class DacapoHarness(Filter):
    """
    Filters output of a DaCapo Harness.

    Inputs:
    - ``stderr``:  List of Paths to stderror output files, or
                   list of file-like objects
    - ``exit_code``: List of program exit codes

    Exports:
    - ``failures``: failure count per invocation ([int])
    - ``times``: execution time per itertion per invocation ([[int]])
    - ``valid``: flag that indicates if execution was valid
    """
    inputs = set(('stderror', 'error'))
    exports = set(('failures', 'times', 'flawed'))
    TIME_RE = re.compile(
        r"""
        (?:completed\ warmup\ \d+|        # for iterations
        (?P<success>FAILED|PASSED))       # check if run failed or passed
        \ in\ (?P<time>\d+)\ msec         # time of execution
        """, re.VERBOSE)

    def _run(self, **kwargs):
        exit_codes = kwargs['exit_code']
        stderror = kwargs['stderr']

        for f, exit_code in izip(stderror, exit_codes):
            failures = 0<commit_msg>filters: Fix exports and inputs of DacapoHarness.<commit_after>"""
This module provides filters.
"""

import re
from itertools import izip
from pprint import pprint

from penchy.jobs.elements import Filter


class Tamiflex(Filter):
    pass


class HProf(Filter):
    pass


class DacapoHarness(Filter):
    """
    Filters output of a DaCapo Harness.

    Inputs:
    - ``stderr``:  List of Paths to stderror output files, or
                   list of file-like objects
    - ``exit_code``: List of program exit codes

    Exports:
    - ``failures``: failure count per invocation ([int])
    - ``times``: execution time per itertion per invocation ([[int]])
    - ``valid``: flag that indicates if execution was valid
    """
    inputs = set(('stderr', 'exit_code'))
    exports = set(('failures', 'times', 'valid'))
    TIME_RE = re.compile(
        r"""
        (?:completed\ warmup\ \d+|        # for iterations
        (?P<success>FAILED|PASSED))       # check if run failed or passed
        \ in\ (?P<time>\d+)\ msec         # time of execution
        """, re.VERBOSE)

    def _run(self, **kwargs):
        exit_codes = kwargs['exit_code']
        stderror = kwargs['stderr']

        for f, exit_code in izip(stderror, exit_codes):
            failures = 0
{'fraction_non_alphanumeric': 0.12634946021591364, 'fraction_numerical': 0.0007996801279488205, 'mean_word_length': 2.5338983050847457, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '623576', 'n_tokens_mistral': 786, 'n_tokens_neox': 758, 'n_words': 245}