How to query 2 different type measurements for different devices with EPL

Dear All,
spi_measurement_json.txt (1.3 KB)
aoi_measurement_json.txt (790 Bytes)

I am working for a demo to build relationship between different type measurements from different devices .

There are 2 measurements now, SPI_measurement & AOI_measurement.

AOI measurement is the data about fail qualify production .

SPI measurement is the data about Height/Area/Volume for the paint on the board.

The relation ship between these 2 json should be like below.
{
Aoi.boardId=SPI.boardId

Aoi.boardUnits = SPI.boardUnits

Aois. boardUnitId = SPI. boardUnitId
}

The SPI measurement will be post to C8Y first.

My first idea is to setup a monitor in apama for it, I set up a monitor for AOI measurement, then search for available SPI measurements in time windows.

But in EPL editor, it’s not allow to query with criterial for Measurement.params.

Do you have any suggestion for this requirement ?

using com.apama.cumulocity.Measurement;
using com.apama.cumulocity.MeasurementValue;
using com.apama.cumulocity.MeasurementFragment;
monitor PerDeviceAOIFailureSPITracker {
event FillSPIMeasurement {
string measurementName;
float measurementValue;
string unit;
}

////////Constant ////////
event Constants {
    constant string INPUT_MEASUREMENT_TYPE := "c8y_AoiBoardWindow";
    constant string INPUT_MEASUREMENT_FRAGMENT := "c8y_AoiBoardWindow";

	constant string SPI_MEASUREMENT_TYPE := "c8y_SPIBoardWindow";
	constant string SPI_MEASUREMENT_NAME := "algorithm_H_Value";
}

action onload() {
    spawn factory to context("PerDeviceAOIFailureSPITracker", true);
}
action factory() {
    monitor.subscribe(Measurement.SUBSCRIBE_CHANNEL);
    on all Measurement(type = Constants.INPUT_MEASUREMENT_TYPE) as m {
        fillSPIVariables(m);
    }
}

action fillSPIVariables(Measurement aoiMeasurement) {
	dictionary<string, any> params := aoiMeasurement.params;
	string boardId := params["boardId"].toString();
	string CompName := params.getOr("CompName","-1").toString();
	string boardUnitId := params.getOr("boardUnitId","-1").toString();
	string boardUnits := params.getOr("boardUnits","-1").toString();
	dictionary<string,any> checkParams := {"boardUnitId":boardUnitId, "boardUnits":boardUnits,"boardId":boardId};
	from spi in all Measurement(type=Constants.SPI_MEASUREMENT_TYPE,params=checkParams) within (1800.0) 
		select FillSPIMeasurement(Constants.SPI_MEASUREMENT_NAME, spi.measurements[Constants.SPI_MEASUREMENT_TYPE][Constants.SPI_MEASUREMENT_NAME].value,spi.measurements[Constants.SPI_MEASUREMENT_TYPE][Constants.SPI_MEASUREMENT_NAME].unit) as fill{

		}
}

}

Above is my EPL, but fail to compile for line ‘all Measurement(type=Constants.SPI_MEASUREMENT_TYPE,params=checkParams)’

Yes Weihan, event expressions can only match on top-level primitive fields. Only top-level primitive types can be indexed in an event expression.
You can try like this:

action fillSPIVariables(Measurement aoiMeasurement) {
		dictionary<string, any> params := aoiMeasurement.params;
		string boardId := params["boardId"].toString();
		string CompName := params.getOr("CompName","-1").toString();
		string boardUnitId := params.getOr("boardUnitId","-1").toString();
		string boardUnits := params.getOr("boardUnits","-1").toString();
		
		from spi in all Measurement(type=Constants.SPI_MEASUREMENT_TYPE) within (1800.0)
		  	where ( boardUnitId = spi.params.getOr("boardUnitId","-1").toString()
		  	       and boardUnits = spi.params.getOr("boardUnits","-1").toString()
		  	       and boardId = spi.params["boardId"].toString())
			select FillSPIMeasurement(Constants.SPI_MEASUREMENT_NAME, 
			              spi.measurements[Constants.SPI_MEASUREMENT_TYPE][Constants.SPI_MEASUREMENT_NAME].value,
			              spi.measurements[Constants.SPI_MEASUREMENT_TYPE][Constants.SPI_MEASUREMENT_NAME].unit) as fill{
				 
	
			}
		
	}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.