Class: Toybox::SensorHistory::SensorHistoryIterator

Inherits:
Lang::Object
  • Object
show all

Overview

A class containing sensor data for a given period of time.

The SensorHistoryIterator object is an Array of SensorSample objects. The iterator is retrieved using the appropriate “get” methods found in SensorHistory at the module level. This class provides the methods needed to retrieve information from each of the SensorSample objects included in the iterator.

Examples:

Gets a SensorHistoryIterator object to be used with the below methods

using Toybox.SensorHistory;
using Toybox.Lang;
using Toybox.System;

// Create a method to get the SensorHistoryIterator object
function getIterator() {
    // Check device for SensorHistory compatibility
    if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getHeartRateHistory)) {
        return Toybox.SensorHistory.getHeartRateHistory({});
    }
    return null;
}

// Store the iterator info in a variable. The options are 'null' in this
// case so the entire available history is returned with the newest
// samples returned first.
var sensorIter = getIterator();

See Also:

Since:

  • 2.1.0

Instance Method Summary collapse

Methods inherited from Lang::Object

equals, hashCode, method, toString, weak

Instance Method Details

getMaxToybox::Lang::Number

Get the maximum SensorSample data value contained in this iterator.

Examples:

Print out the maximum SensorSample data value

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the
// maximum sample value entry in the iterator
System.println(sensorIter.getMax().data);

Returns:

See Also:

Since:

  • 2.1.0


8963
8964
# File 'Monkeybrains.rb', line 8963

def getMax()
end

getMinToybox::Lang::Number

Get the minimum SensorSample data value contained in this iterator.

Examples:

Print out the minimum SensorSample data value

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the
// minimum sample value entry in the iterator
System.println(sensorIter.getMin().data);

Returns:

See Also:

Since:

  • 2.1.0


8979
8980
# File 'Monkeybrains.rb', line 8979

def getMin()
end

getNewestSampleTimeToybox::Time::Moment

Get the Moment of the newest SensorSample in this iterator.

Examples:

Print out the Moment of the newest SensorSample

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the Moment
// of the newest sample entry in the iterator
System.println(sensorIter.getNewestSampleTime());

Returns:

See Also:

Since:

  • 2.1.0


8997
8998
# File 'Monkeybrains.rb', line 8997

def getNewestSampleTime()
end

getOldestSampleTimeToybox::Time::Moment

Get the Moment of the oldest SensorSample in this iterator.

Examples:

Print out the Moment of the oldest SensorSample

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the Moment
// of the oldest sample entry in the iterator
System.println(sensorIter.getOldestSampleTime());

Returns:

See Also:

Since:

  • 2.1.0


9015
9016
# File 'Monkeybrains.rb', line 9015

def getOldestSampleTime()
end

nextToybox::SensorHistory::SensorSample

Get the next SensorSample entry in the iterator.

This must be called to get the initial data from the iterator.

Examples:

Print out the next SensorSample data value

using Toybox.SensorHistory;
using Toybox.System;
// Given a valid SensorHistoryIterator object, print out the next
// entry in the iterator
System.println(sensorIter.next().data);

Returns:

See Also:

Since:

  • 2.1.0


8947
8948
# File 'Monkeybrains.rb', line 8947

def next()
end