Skip to content

Direct Measure

Antonin Abherve edited this page Feb 16, 2017 · 5 revisions

Direct Measure API

A direct Measure is used to collect data in physical world. This kind of measure can be executed on Platform Side on on Client Side.

To defined a Direct Measure, implement the IDirectMeasure interface. This interface will be calledby the MeasurePlatform to rettive the measurements.


public interface IDirectMeasure {
  public List<IMeasurement> getMeasurement() throws Exception;
  public Map<String,String> getProperties();
}

  • getMeasurement() : Calculate and Return a liste of Measurement.
  • getProperties() : Provide a way for the MeasurePlatform to communicate properties to DirectMeasure implementation.

To implement a direct measure, please extend the **DirectMeasure **class.

Direct Measure Example

RandomGenerator : A toy measure whch return a random number between MinRange and MaxRange value at each call.

public class RandomGenerator extends DirectMeasure {

	@Override
	public List<IMeasurement> getMeasurement() throws Exception {
		List<IMeasurement> result = new ArrayList<>();
		
                // Retrive Platform Properties by her name
		int maxRange =  Integer.valueOf(getProperty("MaxRange"));
		int minRange = Integer.valueOf(getProperty("MinRange"));

                // Collect Measure
		Random gen = new Random();
		int value = gen.nextInt(maxRange - minRange) + minRange;
		
                // Create Measurement :  In this case, a simple IntegerMeasurement
		IntegerMeasurement measurement = new IntegerMeasurement();
		measurement.setValue(value);		
		result.add(measurement);

		return result;
	}
}
Clone this wiki locally