edgent-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christofer Dutz <christofer.d...@c-ware.de>
Subject Re: why isn't the filtering working?
Date Sun, 27 May 2018 08:03:23 GMT
Hi Arun,

first of all … welcome to the Apache Edgent list.

I had a quick look at your code … I guess you are assuming the temperature of the sensor
is within a given range, which it doesn’t seem to be. I guess it starts at agiven point
and then every new value differs from the previous by a random value. I have seen it go from
0 to 300 or from 0 to -300 …
I updated your code a little and can see both “in” and “out of range” messages so
you can see what’s happening.

package org.apache.edgent.samples.topology;

import org.apache.edgent.analytics.sensors.Range;
import org.apache.edgent.analytics.sensors.Ranges;
import org.apache.edgent.providers.direct.DirectProvider;
import org.apache.edgent.topology.TStream;
import org.apache.edgent.topology.Topology;

import java.util.concurrent.TimeUnit;

public class Test {
    static double OPTIMAL_TEMP_LOW = 80.0;
    static double OPTIMAL_TEMP_HIGH = 85.0;
    static Range<Double> optimalTempRange = Ranges.closed(OPTIMAL_TEMP_LOW, OPTIMAL_TEMP_HIGH);

    public static void main(String[] args) throws Exception {
        TempSensor sensor = new TempSensor();
        DirectProvider dp = new DirectProvider();
        Topology topology = dp.newTopology();

        TStream<Double> tempReadings = topology.poll(sensor, 1, TimeUnit.MILLISECONDS);

        TStream<Double> inRangeTempReadings = tempReadings.filter(tuple ->
                optimalTempRange.contains(tuple));
        inRangeTempReadings.sink(tuple -> System.out.println("Temperature is in range!
"
                + "It is " + tuple + "\u00b0F!"));

        TStream<Double> outOfRangeTempReadings = tempReadings.filter(tuple ->
                !optimalTempRange.contains(tuple));
        outOfRangeTempReadings.sink(tuple -> System.out.println("Temperature is out of
range! "
                + "It is " + tuple + "\u00b0F!"));

        dp.submit(topology);
    }

}

By the way … you didn’t need the “print” as with the sink you already had a sink for
your stream.

Chris


Von: arun subba <arunsbb@live.com>
Antworten an: "dev@edgent.apache.org" <dev@edgent.apache.org>
Datum: Sonntag, 27. Mai 2018 um 09:43
An: "dev@edgent.apache.org" <dev@edgent.apache.org>
Betreff: why isn't the filtering working?

[cid:2fdbea19-7190-445c-86fe-c21253206e6c]

Hi,

    I am trying to implement Apache Edgent in my project but before that I ran into a problem.
The basic objective up till now is to filter the readings of temperature sensor, but unfortunately
I could not understand the error that I am getting. I have been following the Apache Edgent
Documentation but does not help my queries. The code is as follows:


static double OPTIMAL_TEMP_LOW = 80.0;
    static double OPTIMAL_TEMP_HIGH = 85.0;
    static Range<Double> optimalTempRange = Ranges.closed(OPTIMAL_TEMP_LOW, OPTIMAL_TEMP_HIGH);

    public static void main(String[] args) throws Exception {
        TempSensor sensor = new TempSensor();
        DirectProvider dp = new DirectProvider();
        Topology topology = dp.newTopology();


        TStream<Double> tempReadings = topology.poll(sensor, 1, TimeUnit.MILLISECONDS).filter(tuple
->
                !optimalTempRange.contains(tuple));
 tempReadings.sink(tuple -> System.out.println("Temperature is out of range! "
        + "It is " + tuple + "\u00b0F!"));
 tempReadings.print();



        dp.submit(topology);
}

This program outputs the above figure with no Message. Why is it so?


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message