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


10113
10114
# File 'Monkeybrains.rb', line 10113

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


10129
10130
# File 'Monkeybrains.rb', line 10129

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


10147
10148
# File 'Monkeybrains.rb', line 10147

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


10165
10166
# File 'Monkeybrains.rb', line 10165

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


10097
10098
# File 'Monkeybrains.rb', line 10097

def next()
end