You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@edgent.apache.org by dlaboss <gi...@git.apache.org> on 2016/04/05 23:30:19 UTC

[GitHub] incubator-quarks pull request: [QUARKS-107] [WIP] create Simulated...

GitHub user dlaboss opened a pull request:

    https://github.com/apache/incubator-quarks/pull/75

    [QUARKS-107] [WIP] create SimulatedTemperatureSensor for recipes

    For the motivation / use of this see: https://github.com/apache/incubator-quarks-website/pull/33
    Awaiting response to question in the pr.

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

    $ git pull https://github.com/dlaboss/incubator-quarks quarks107-simulatedTempSensor

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

    https://github.com/apache/incubator-quarks/pull/75.patch

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

    This closes #75
    
----
commit 55cdb79533a07156302c0333a9b219a265f60db8
Author: Dale LaBossiere <dl...@us.ibm.com>
Date:   2016-04-05T21:21:38Z

    [QUARKS-107] create SimulatedTemperatureSensor for recipes

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-107] [WIP] create Simulated...

Posted by ddebrunner <gi...@git.apache.org>.
Github user ddebrunner commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/75#discussion_r58628617
  
    --- Diff: samples/utils/src/main/java/quarks/samples/utils/sensor/SimulatedTemperatureSensor.java ---
    @@ -0,0 +1,110 @@
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements.  See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership.  The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied.  See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +package quarks.samples.utils.sensor;
    +
    +import java.text.DecimalFormat;
    +import java.util.Objects;
    +import java.util.Random;
    +
    +import quarks.analytics.sensors.Range;
    +import quarks.analytics.sensors.Ranges;
    +import quarks.function.Supplier;
    +
    +/**
    + * A Simulated temperature sensor.
    + * <p>
    + * The sensor starts off with an initial value.
    + * Each call to {@link #get()} changes the current value by
    + * a random amount between plus/minus a {@code deltaFactor}.
    + * The new current value is limited to a {@code maxTempRange}.
    + * <p>
    + * Temperature values are in Fahrenheit.
    --- End diff --
    
    'Temperature values are in Fahrenheit."
    
    Isn't that up to whoever is creating an instance?
    
    The default constructor maps to a normal air temperature Fahrenheit range, but wouldn't something like this be suitable for Kelvin around the same range?
    
    `new SimulatedTemperatureSensor(300, Ranges.closed(265, 315), 0.5);`



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-107] create SimulatedTemper...

Posted by ddebrunner <gi...@git.apache.org>.
Github user ddebrunner commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/75#discussion_r58737187
  
    --- Diff: samples/utils/src/main/java/quarks/samples/utils/sensor/SimulatedTemperatureSensor.java ---
    @@ -0,0 +1,115 @@
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements.  See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership.  The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied.  See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +package quarks.samples.utils.sensor;
    +
    +import java.text.DecimalFormat;
    +import java.util.Objects;
    +import java.util.Random;
    +
    +import quarks.analytics.sensors.Range;
    +import quarks.analytics.sensors.Ranges;
    +import quarks.function.Supplier;
    +
    +/**
    + * A Simulated temperature sensor.
    + * <p>
    + * The sensor starts off with an initial value.
    + * Each call to {@link #get()} changes the current value by
    + * a random amount between plus/minus a {@code deltaFactor}.
    + * The new current value is limited to a {@code maxTempRange}.
    + * <p>
    + * No temperature scale is implied (e.g., Fahrenheit, Kelvin, ...).
    + * The {@code double} temperature values are simply generated as described.
    + * The user of the class decides how to interpret them.
    + * <p>
    + * Sample use:
    + * <pre>{@code
    + * Topology t = ...;
    + * SimulatedTemperatureSensor tempSensor = new SimulatedTemperatureSensor();
    + * TStream<Double> temp = t.poll(tempSensor, 1, TimeUnit.SECONDS);
    + * }</pre>
    + */
    +public class SimulatedTemperatureSensor implements Supplier<Double> {
    +    private static final long serialVersionUID = 1L;
    +    private static DecimalFormat df = new DecimalFormat("#.#");
    +    private Random r = new Random();
    +    private final Range<Double> maxTempRange;
    +    private final double deltaFactor;
    +    private double currentTemp;
    +   
    +    /**
    +     * Create a temperature sensor.
    +     * <p>
    +     * Same as {@code SimulatedTemperatureSensor(80.0, 
    +     *              Ranges.closed(28.0, 112.0), 1.0)}
    +     * <p>
    +     * These default values roughly correspond to normal air temperature
    +     * in the Fahrenheit scale.
    +     */
    +    public SimulatedTemperatureSensor() {
    +        this(80.0, Ranges.closed(28.0, 112.0), 1.0);
    +    }
    +    
    +    /**
    +     * Create a temperature sensor.
    +     * <p>
    +     * No temperature scale is implied. 
    +     * @param initialTemp the initial temperature.  Must be within maxTempRange.
    +     * @param maxTempRange maximum sensor value range
    +     * @param deltaFactor maximum plus/minus change on each {@code get()}.
    +     *              e.g., 1.0 to limit change to +/- 1.0.
    +     *              Must be > 0.0
    +     */
    +    public SimulatedTemperatureSensor(double initialTemp,
    +            Range<Double> maxTempRange, double deltaFactor) {
    +        this.currentTemp = initialTemp;
    +        this.maxTempRange = maxTempRange;
    +        this.deltaFactor = deltaFactor;
    +        Objects.requireNonNull(maxTempRange, "maxTempRange");
    +        if (!maxTempRange.contains(currentTemp))
    +            throw new IllegalArgumentException("currentTemp");
    +        if (deltaFactor <= 0.0)
    +            throw new IllegalArgumentException("deltaFactor");
    +    }
    +    
    +    /** Get the maxTempRange setting */
    +    public Range<Double> getMaxTempRange() {
    --- End diff --
    
    Why is this a "maximum temperature range"? Isn't it just a temperature range?
    
    What would be a "minimum temperature range" ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-107] create SimulatedTemper...

Posted by ddebrunner <gi...@git.apache.org>.
Github user ddebrunner commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/75#discussion_r58736804
  
    --- Diff: samples/utils/src/main/java/quarks/samples/utils/sensor/SimulatedTemperatureSensor.java ---
    @@ -0,0 +1,115 @@
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements.  See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership.  The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied.  See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +package quarks.samples.utils.sensor;
    +
    +import java.text.DecimalFormat;
    +import java.util.Objects;
    +import java.util.Random;
    +
    +import quarks.analytics.sensors.Range;
    +import quarks.analytics.sensors.Ranges;
    +import quarks.function.Supplier;
    +
    +/**
    + * A Simulated temperature sensor.
    + * <p>
    + * The sensor starts off with an initial value.
    + * Each call to {@link #get()} changes the current value by
    + * a random amount between plus/minus a {@code deltaFactor}.
    + * The new current value is limited to a {@code maxTempRange}.
    + * <p>
    + * No temperature scale is implied (e.g., Fahrenheit, Kelvin, ...).
    + * The {@code double} temperature values are simply generated as described.
    + * The user of the class decides how to interpret them.
    + * <p>
    + * Sample use:
    + * <pre>{@code
    + * Topology t = ...;
    + * SimulatedTemperatureSensor tempSensor = new SimulatedTemperatureSensor();
    + * TStream<Double> temp = t.poll(tempSensor, 1, TimeUnit.SECONDS);
    + * }</pre>
    + */
    +public class SimulatedTemperatureSensor implements Supplier<Double> {
    +    private static final long serialVersionUID = 1L;
    +    private static DecimalFormat df = new DecimalFormat("#.#");
    +    private Random r = new Random();
    +    private final Range<Double> maxTempRange;
    +    private final double deltaFactor;
    +    private double currentTemp;
    +   
    +    /**
    +     * Create a temperature sensor.
    +     * <p>
    --- End diff --
    
    It's a good habit in javadoc to close opened `<P>` with `</P>`.
    
    Some HTML verification/sccessibility testing tools will complain about paragraphs that are not closed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-107] create SimulatedTemper...

Posted by ddebrunner <gi...@git.apache.org>.
Github user ddebrunner commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/75#discussion_r58736939
  
    --- Diff: samples/utils/src/main/java/quarks/samples/utils/sensor/SimulatedTemperatureSensor.java ---
    @@ -0,0 +1,115 @@
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements.  See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership.  The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied.  See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +package quarks.samples.utils.sensor;
    +
    +import java.text.DecimalFormat;
    +import java.util.Objects;
    +import java.util.Random;
    +
    +import quarks.analytics.sensors.Range;
    +import quarks.analytics.sensors.Ranges;
    +import quarks.function.Supplier;
    +
    +/**
    + * A Simulated temperature sensor.
    + * <p>
    + * The sensor starts off with an initial value.
    + * Each call to {@link #get()} changes the current value by
    + * a random amount between plus/minus a {@code deltaFactor}.
    + * The new current value is limited to a {@code maxTempRange}.
    + * <p>
    + * No temperature scale is implied (e.g., Fahrenheit, Kelvin, ...).
    + * The {@code double} temperature values are simply generated as described.
    + * The user of the class decides how to interpret them.
    + * <p>
    + * Sample use:
    + * <pre>{@code
    + * Topology t = ...;
    + * SimulatedTemperatureSensor tempSensor = new SimulatedTemperatureSensor();
    + * TStream<Double> temp = t.poll(tempSensor, 1, TimeUnit.SECONDS);
    + * }</pre>
    + */
    +public class SimulatedTemperatureSensor implements Supplier<Double> {
    +    private static final long serialVersionUID = 1L;
    +    private static DecimalFormat df = new DecimalFormat("#.#");
    +    private Random r = new Random();
    +    private final Range<Double> maxTempRange;
    +    private final double deltaFactor;
    +    private double currentTemp;
    +   
    +    /**
    +     * Create a temperature sensor.
    +     * <p>
    +     * Same as {@code SimulatedTemperatureSensor(80.0, 
    +     *              Ranges.closed(28.0, 112.0), 1.0)}
    +     * <p>
    +     * These default values roughly correspond to normal air temperature
    +     * in the Fahrenheit scale.
    +     */
    +    public SimulatedTemperatureSensor() {
    +        this(80.0, Ranges.closed(28.0, 112.0), 1.0);
    +    }
    +    
    +    /**
    +     * Create a temperature sensor.
    +     * <p>
    +     * No temperature scale is implied. 
    +     * @param initialTemp the initial temperature.  Must be within maxTempRange.
    +     * @param maxTempRange maximum sensor value range
    +     * @param deltaFactor maximum plus/minus change on each {@code get()}.
    +     *              e.g., 1.0 to limit change to +/- 1.0.
    +     *              Must be > 0.0
    +     */
    +    public SimulatedTemperatureSensor(double initialTemp,
    +            Range<Double> maxTempRange, double deltaFactor) {
    +        this.currentTemp = initialTemp;
    +        this.maxTempRange = maxTempRange;
    +        this.deltaFactor = deltaFactor;
    +        Objects.requireNonNull(maxTempRange, "maxTempRange");
    +        if (!maxTempRange.contains(currentTemp))
    +            throw new IllegalArgumentException("currentTemp");
    --- End diff --
    
    The api argument is initialTemp.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-107] [WIP] create Simulated...

Posted by dlaboss <gi...@git.apache.org>.
Github user dlaboss commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/75#discussion_r58714507
  
    --- Diff: samples/utils/src/main/java/quarks/samples/utils/sensor/SimulatedTemperatureSensor.java ---
    @@ -0,0 +1,110 @@
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements.  See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership.  The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License.  You may obtain a copy of the License at
    +
    +  http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied.  See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +package quarks.samples.utils.sensor;
    +
    +import java.text.DecimalFormat;
    +import java.util.Objects;
    +import java.util.Random;
    +
    +import quarks.analytics.sensors.Range;
    +import quarks.analytics.sensors.Ranges;
    +import quarks.function.Supplier;
    +
    +/**
    + * A Simulated temperature sensor.
    + * <p>
    + * The sensor starts off with an initial value.
    + * Each call to {@link #get()} changes the current value by
    + * a random amount between plus/minus a {@code deltaFactor}.
    + * The new current value is limited to a {@code maxTempRange}.
    + * <p>
    + * Temperature values are in Fahrenheit.
    --- End diff --
    
    Good point.  Thx.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-107] create SimulatedTemper...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-quarks/pull/75


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---