<commit_before>import flow.command_runner.executors.nets as enets
import flow.redisom as rom
import flow.petri.netbuilder as nb
import flow.petri.safenet as sn

from collections import namedtuple

import logging

LOG = logging.getLogger(__name__)

GENOME_WRAPPER = "workflow-wrapper"

ParallelBySpec = namedtuple("ParallelBySpec", "property index")
OperationSpec = namedtuple("OperationSpec", "type id")


def get_workflow_outputs(net):
    workflow_id = net.variable('workflow_id')
    output_names = _operation_outputs(net, workflow_id)

    result = {}
    for on in output_names:
        munged_name = _output_variable_name(workflow_id, on)
        result[on] = net.variable(munged_name)

    return result


def _output_variable_name(operation_id, output_name):
    return "_wf_outp_%d_%s" % (int(operation_id), output_name)


def _op_outputs_variable_name(operation_id):
    return "_wf_outp_%d" % int(operation_id)


def _store_outputs(outputs, net, operation_id):
    if not outputs:
        return

    keys = []
    for k, v in outputs.iteritems():
        keys.append(k)
        name = _output_variable_name(operation_id, k)
        net.set_variable(name, v)

    net.set_variable(_op_outputs_variable_name(operation_id), keys)


def _operation_outputs(net, operation_id):
    key = _op_outputs_variable_name(operation_id)
    return net.variable(key)


def _do_converge(inputs, input_property_order, output_properties):
    out_list = [inputs[x] for x in input_property_order]
    return {prop: out_list for prop in output_properties}


class InputsMixin(object):
    def _fetch_inputs(self, net, data_arcs):
        inputs = {}
        if data_arcs:
            for src_id, prop_hash in data_arcs.iteritems():
                if not prop_hash:
                    names = _operation_outputs(net, src_id)
                    prop_hash = {x: x for x in names}

                for dst_prop, src_prop in prop_hash.iteritems():
                    varname = _output_variable_name(src_id, src_prop)
                    value = net.variable(varname)
                    if value:
                        inputs[dst_prop] = value

        return inputs

    def input_data(self, active_tokens_key, net):
        inputs = self._fetch_inputs(net, self.args["input_connections"])
        parallel_by = self.args.get("parallel_by")
        parallel_by_idx = self.args.get("parallel_by_idx")<commit_msg>input_connections default to missing for InputsMixin<commit_after>import flow.command_runner.executors.nets as enets
import flow.redisom as rom
import flow.petri.netbuilder as nb
import flow.petri.safenet as sn

from collections import namedtuple

import logging

LOG = logging.getLogger(__name__)

GENOME_WRAPPER = "workflow-wrapper"

ParallelBySpec = namedtuple("ParallelBySpec", "property index")
OperationSpec = namedtuple("OperationSpec", "type id")


def get_workflow_outputs(net):
    workflow_id = net.variable('workflow_id')
    output_names = _operation_outputs(net, workflow_id)

    result = {}
    for on in output_names:
        munged_name = _output_variable_name(workflow_id, on)
        result[on] = net.variable(munged_name)

    return result


def _output_variable_name(operation_id, output_name):
    return "_wf_outp_%d_%s" % (int(operation_id), output_name)


def _op_outputs_variable_name(operation_id):
    return "_wf_outp_%d" % int(operation_id)


def _store_outputs(outputs, net, operation_id):
    if not outputs:
        return

    keys = []
    for k, v in outputs.iteritems():
        keys.append(k)
        name = _output_variable_name(operation_id, k)
        net.set_variable(name, v)

    net.set_variable(_op_outputs_variable_name(operation_id), keys)


def _operation_outputs(net, operation_id):
    key = _op_outputs_variable_name(operation_id)
    return net.variable(key)


def _do_converge(inputs, input_property_order, output_properties):
    out_list = [inputs[x] for x in input_property_order]
    return {prop: out_list for prop in output_properties}


class InputsMixin(object):
    def _fetch_inputs(self, net, data_arcs):
        inputs = {}
        if data_arcs:
            for src_id, prop_hash in data_arcs.iteritems():
                if not prop_hash:
                    names = _operation_outputs(net, src_id)
                    prop_hash = {x: x for x in names}

                for dst_prop, src_prop in prop_hash.iteritems():
                    varname = _output_variable_name(src_id, src_prop)
                    value = net.variable(varname)
                    if value:
                        inputs[dst_prop] = value

        return inputs

    def input_data(self, active_tokens_key, net):
        inputs = self._fetch_inputs(net, self.args.get("input_connections"))
        parallel_by = self.args.get("parallel_by")
        parallel_by_idx = self.args.get("parallel_by_idx")
{'fraction_non_alphanumeric': 0.08719851576994433, 'fraction_numerical': 0.0, 'mean_word_length': 3.1936041486603286, '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': '6775539', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1496, 'n_words': 334}