edgent-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (QUARKS-107) Add sample use of new Range class in recipe3 - detect value out of range?
Date Tue, 05 Apr 2016 19:03:25 GMT

    [ https://issues.apache.org/jira/browse/QUARKS-107?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15226936#comment-15226936

ASF GitHub Bot commented on QUARKS-107:

GitHub user dlaboss opened a pull request:


    [QUARKS-107] [WIP] new Range recipes

    In an effort to simplify these recipes and focus on their unique aspects I want them to
be able to use a simulated temperature sensor that's defined elsewhere.  Right now the recipes
are expecting  ``quarks.samples.utils.sensor. SimulatedTemperatureSensor`` - which doesn't
yet exist in the incubator-quarks repo.
    @ddebrunner, does that approach / location seem right?  If so, I'll add that class to
that repo.  My impl of it was inspired by the code in recipe_value_out_of_range.md.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dlaboss/incubator-quarks-website quarks107_new_range_recipes

Alternatively you can review and apply these changes as the patch at:


To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #33
commit 647a2ed5bd732c5b2a312711e109432fdf7c4171
Author: Dale LaBossiere <dlaboss@us.ibm.com>
Date:   2016-04-05T18:40:02Z

    [QUARKS-107] new Range recipes


> Add sample use of new Range class in recipe3 - detect value out of range?
> -------------------------------------------------------------------------
>                 Key: QUARKS-107
>                 URL: https://issues.apache.org/jira/browse/QUARKS-107
>             Project: Quarks
>          Issue Type: Improvement
>            Reporter: Dale LaBossiere
>            Assignee: Dale LaBossiere
>              Labels: newbie
> Add sample use of new Range class in recipe3 - detect value out of range?
> Either or both of the recipe's existing samples could be use Range, or one of them could
be cloned to use it.
> ```
> TStream<Double> simpleFiltered = temp.filter(tuple ->
>             tuple < TEMP_LOW || tuple > TEMP_HIGH);
> // could be
> TStream<Double> simpleFiltered = temp.filter(Ranges.open(TEMP_LOW, TEMP_HIGH);
> TStream<Double> deadbandFiltered = Filters.deadband(temp,
>             identity(), tuple -> tuple >= TEMP_LOW && tuple <= TEMP_HIGH);
> // could instead be
> TStream<Double> deadbandFiltered = Filters.deadband(temp,
>             identity(), Ranges.closed(TEMP_LOW, TEMP_HIGH));
> ```
> Use of a Range simplifies the code a bit.  I can also avoid mistakes if one's code "duplicates"
the expressions for a particular range in multiple places.  
> Using Range can be more compelling for the simplicity with which a range may be expressed
and created from a config file for an app.  e.g. imagine how one would express the range in
a Properties config file.  A range property value in a Properties file would simply be:
> ```
> # my sensor filter range
> myFilterRange=[71.0..98.0]
> ```
> and the app code to create the Range would simply be:
> ```
> Range<Double> myFilterRange = Ranges.valueOfDouble(props.getProperty("myFilterRange"));
> ```
> Another compelling case is making a filter range dynamically changeable, for example
as a result of some received IoT "device command".  The range could be declared like:
> ```
> AtomicReference<Range<Double>> myFilterRange = new AtomicReference<>(
>     Ranges.valueOfDouble(props.getProperty("myFilterRange"));  // initial range value
> // code in the device's set-filter-range cmd handler is ultimately:
> //   myFilterRange.set(Ranges.valueOfDouble(the-new-range-string-from-the-cmd));  //
sets a new Range object
> // Using the changeable filter range is simply:
> TStream<Double> simpleFiltered = temp.filter(myFilterRange.get());
> ```
> Dynamic filter Predicates is probably a good recipe unto itself :-)

This message was sent by Atlassian JIRA

View raw message