Ejemplo n.º 1
0
    def create(self, operator, inputs=None, outputs=None, **kwargs):
        if (inputs is not None
                or outputs is not None) and operator is not None:
            # Figure out node type
            if inputs is None and outputs is not None:
                node_type = NodeTypes.INPUT.value
            elif inputs is not None and outputs is None:
                node_type = NodeTypes.MIDDLE.value
            else:
                raise Exception("Invalid node type")

            if inputs is not None:
                if len(inputs) == 1:
                    op_type = OpTypes.UNARY.value
                elif len(inputs) == 2:
                    op_type = OpTypes.BINARY.value
                else:
                    raise Exception("Invalid number of inputs")
            else:
                op_type = OpTypes.OTHER.value

            if outputs is None:
                status = OpStatus.PENDING.value
            else:
                status = OpStatus.COMPUTED.value

            inputs = json.dumps(inputs)
            outputs = json.dumps(outputs)

            op = db.create_op(name=kwargs.get("name", None),
                              graph_id=g.graph_id,
                              node_type=node_type,
                              inputs=inputs,
                              outputs=outputs,
                              op_type=op_type,
                              operator=operator,
                              status=status,
                              params=json.dumps(kwargs))
            # Add op to queue
            if op.status != OpStatus.COMPUTED.value and op.status != OpStatus.FAILED.value:
                if g.graph_id is None:
                    q = RavQueue(name=QUEUE_HIGH_PRIORITY)
                    q.push(op.id)
                else:
                    q = RavQueue(name=QUEUE_LOW_PRIORITY)
                    q.push(op.id)

            return op
        else:
            raise Exception("Invalid parameters")
Ejemplo n.º 2
0
def __create_math_op2(op1, operator, **kwargs):
    if op1 is None:
        raise Exception("Null Op")

    op = db.create_op(name=kwargs.get('name', None),
                      graph_id=g.graph_id,
                      node_type=NodeTypes.MIDDLE.value,
                      inputs=json.dumps([op1.id]),
                      outputs=json.dumps(None),
                      op_type=OpTypes.UNARY.value,
                      operator=operator,
                      status=OpStatus.PENDING.value)

    # Add op to queue
    if op.status != OpStatus.COMPUTED.value and op.status != OpStatus.FAILED.value:
        if g.graph_id is None:
            q = RavQueue(name=QUEUE_HIGH_PRIORITY)
            q.push(op.id)
        else:
            q = RavQueue(name=QUEUE_LOW_PRIORITY)
            q.push(op.id)

    return Op(id=op.id)