Search in sources :

Example 1 with OutputTuple

use of com.ibm.streams.operator.OutputTuple in project streamsx.health by IBMStreams.

the class QRSDetector method process.

/**
	 * Process an incoming tuple that arrived on the specified port.
	 * <P>
	 * Copy the incoming tuple to a new output tuple and submit to the output
	 * port.
	 * </P>
	 * 
	 * @param inputStream
	 *            Port the tuple is arriving on.
	 * @param tuple
	 *            Object representing the incoming tuple.
	 * @throws Exception
	 *             Operator failure, will cause the enclosing PE to terminate.
	 */
@Override
public final void process(StreamingInput<Tuple> inputStream, Tuple tuple) throws Exception {
    int sample = getInputDataAttr().getValue(tuple);
    double timestamp = getInputTimestampAttr().getValue(tuple);
    timeBuffer.add(timestamp);
    BeatDetectAndClassifyResult result = detector.BeatDetectAndClassify(sample);
    logger.trace("tuple=" + tuple.toString());
    logger.trace("result=" + result);
    if (!isOutputDetectionOnly() || (isOutputDetectionOnly() && result.samplesSinceRWaveIfSuccess != 0)) {
        StreamingOutput<OutputTuple> outStream = getOutput(0);
        OutputTuple outTuple = outStream.newTuple();
        outTuple.assign(tuple);
        Double qrsTimestamp = Double.NaN;
        int qrsPosition = -1;
        Double rrInterval = Double.NaN;
        Double rrMinusOneInterval = Double.NaN;
        if (result.samplesSinceRWaveIfSuccess != 0) {
            // calculate timestamp for detected QRS
            qrsPosition = result.samplesSinceRWaveIfSuccess;
            if (qrsPosition <= timeBuffer.size()) {
                qrsTimestamp = calculateTimestampFromQrsPosition(qrsPosition);
            } else {
                logger.error("Detected position larger than available historical data points: qrsPosition=" + qrsPosition);
            }
            // calculate RR interval
            if (qrsTimestamp != Double.NaN) {
                if (previousQrsTimestamp != Double.NaN) {
                    rrMinusOneInterval = previousRRInterval;
                    rrInterval = calculateRRInterval(qrsTimestamp);
                    previousRRInterval = rrInterval;
                }
                previousQrsTimestamp = qrsTimestamp;
            }
        }
        outTuple.setLong(getQrsTimestampAttrName(), Math.round(qrsTimestamp));
        outTuple.setInt(getQrsDelayAttrName(), qrsPosition);
        outTuple.setString(getQrsClassificationAttrName(), BeatType.getByCode(result.beatType).toString());
        outTuple.setDouble(getRRIntervalAttrName(), rrInterval);
        outTuple.setDouble(getPrevRRIntervalAttrName(), rrMinusOneInterval);
        outStream.submit(outTuple);
    }
}
Also used : BeatDetectAndClassifyResult(eplimited.osea.classification.BeatDetectionAndClassification.BeatDetectAndClassifyResult) OutputTuple(com.ibm.streams.operator.OutputTuple)

Example 2 with OutputTuple

use of com.ibm.streams.operator.OutputTuple in project streamsx.topology by IBMStreams.

the class HashAdder method process.

@Override
public void process(StreamingInput<Tuple> stream, Tuple tuple) throws Exception {
    // Take the hash code, add it to the tuple, and submit.
    Object value = mapping.convertFrom(tuple);
    OutputTuple ot = output.newTuple();
    ot.setObject(0, tuple.getObject(0));
    ot.setInt(1, hasher.applyAsInt(value));
    output.submit(ot);
}
Also used : FunctionalHelper.getLogicObject(com.ibm.streamsx.topology.internal.functional.FunctionalHelper.getLogicObject) OutputTuple(com.ibm.streams.operator.OutputTuple)

Example 3 with OutputTuple

use of com.ibm.streams.operator.OutputTuple in project streamsx.topology by IBMStreams.

the class HashRemover method process.

/**
 * Removes the __spl_hash attribute at the start of a parallel region.
 */
public void process(StreamingInput<Tuple> stream, Tuple tuple) throws Exception {
    OutputTuple out_t = output.newTuple();
    out_t.setObject(0, tuple.getObject(0));
    output.submit(out_t);
}
Also used : OutputTuple(com.ibm.streams.operator.OutputTuple)

Example 4 with OutputTuple

use of com.ibm.streams.operator.OutputTuple in project streamsx.topology by IBMStreams.

the class FunctionConvertToSPL method process.

@Override
public void process(StreamingInput<Tuple> stream, Tuple tuple) throws Exception {
    Object value = inputMapping.convertFrom(tuple);
    final BiFunction<Object, OutputTuple, OutputTuple> convert = convertHandler.getLogic();
    OutputTuple outTuple = output.newTuple();
    synchronized (convert) {
        outTuple = convert.apply(value, outTuple);
    }
    if (outTuple != null)
        output.submit(outTuple);
}
Also used : OutputTuple(com.ibm.streams.operator.OutputTuple)

Example 5 with OutputTuple

use of com.ibm.streams.operator.OutputTuple in project streamsx.topology by IBMStreams.

the class SPLStreamsTest method createSPLFlowFromStream.

@SuppressWarnings("serial")
private static SPLStream createSPLFlowFromStream(final Topology topology, final boolean skipSecond) {
    TStream<String> source = topology.strings("325", "457", "9325");
    TStream<IntAndString> iands = source.transform(new Function<String, IntAndString>() {

        @Override
        public IntAndString apply(String v1) {
            IntAndString is = new IntAndString();
            is.s = v1;
            is.n = Integer.valueOf(v1) + 93;
            return is;
        }
    });
    StreamSchema schema = Type.Factory.getStreamSchema("tuple<int32 ii, rstring ss>");
    SPLStream splStream = SPLStreams.convertStream(iands, new BiFunction<IntAndString, OutputTuple, OutputTuple>() {

        @Override
        public OutputTuple apply(IntAndString v1, OutputTuple v2) {
            if (skipSecond & v1.n == 550)
                return null;
            v2.setString("ss", v1.s);
            v2.setInt("ii", v1.n);
            return v2;
        }
    }, schema);
    assertSPLStream(splStream, schema);
    return splStream;
}
Also used : StreamSchema(com.ibm.streams.operator.StreamSchema) OutputTuple(com.ibm.streams.operator.OutputTuple) SPLStream(com.ibm.streamsx.topology.spl.SPLStream)

Aggregations

OutputTuple (com.ibm.streams.operator.OutputTuple)9 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)3 StreamSchema (com.ibm.streams.operator.StreamSchema)2 Message (ca.uhn.hl7v2.model.Message)1 Tuple (com.ibm.streams.operator.Tuple)1 TupleType (com.ibm.streams.operator.meta.TupleType)1 RString (com.ibm.streams.operator.types.RString)1 HapiMessageSupplier (com.ibm.streamsx.health.hapi.internal.HapiMessageSupplier)1 ObxToSplMapper (com.ibm.streamsx.health.hapi.mapper.ObxToSplMapper)1 Observation (com.ibm.streamsx.health.hapi.model.Observation)1 Topology (com.ibm.streamsx.topology.Topology)1 FunctionalHelper.getLogicObject (com.ibm.streamsx.topology.internal.functional.FunctionalHelper.getLogicObject)1 BeatDetectAndClassifyResult (eplimited.osea.classification.BeatDetectionAndClassification.BeatDetectAndClassifyResult)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Random (java.util.Random)1