use of eplimited.osea.classification.BeatDetectionAndClassification.BeatDetectAndClassifyResult 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);
}
}
Aggregations