本文介绍了为什么过滤器方法不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Doctor Edgent的文档中所述,我试图过滤掉传感器读数,其中温度传感器的值必须介于80至85 F之间.

As given in the docs of Apache Edgent I tried to filter out my sensor readings wherein the values of the temperature sensor must lie in between 80 to 85 F.

但是当我尝试连接传感器时,读数为75F,并且没有显示任何消息,例如:温度超出范围.

But when I tried connecting my sensor the readings were 75F and no message was shown like: temperature is out of range.

是filter方法不起作用吗?如果是这样,请尝试帮助我.谢谢.

Is it that the filter method isn't working? if so please try help me out. thanks.

范围值设置为:

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);

传感器对象为TempSensor ts

TempSensor ts = new TempSensor();
Stream<Double> temp = top.poll(ts, 1, TimeUnit.MILLISECONDS);

过滤部分:

TStream<Double> simpleFiltered = temp.filter(tuple ->
tuple < OPTIMAL_TEMP_LOW || tuple > OPTIMAL_TEMP_HIGH);
simpleFiltered.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));

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

// See what the temperatures look like
simpleFiltered.print();

dp.submit(top);

输出:

Selet a port:
1: ttyACM0 Port opened succesefully.
7373.40
73.40
73.40 ...

推荐答案

我认为发生这种情况是因为您的过滤器和接收器已分配给另一个TStream对象,而不是要打印的对象.
可能您需要尝试以下方法:

I think that happened because your filter and sink have been assigned to another TStream object, not the one you are printing out.
Probably you need to try this:

TempSensor ts = new TempSensor();
TStream<Double> temp = top.poll(ts, 1, TimeUnit.MILLISECONDS).filter(tuple ->
tuple < OPTIMAL_TEMP_LOW || tuple > OPTIMAL_TEMP_HIGH);
temp.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));

// See what the temperatures look like
temp.print();

dp.submit(top);

这篇关于为什么过滤器方法不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:16