Here are some parts of the code that I'm using.
it = SensorHistory.getHeartRateHistory({:period => 30, :order => SensorHistory.ORDER_OLDEST_FIRST});
var min = it.getMin();
var max = it.getMax();
var sample_last = it.next();
if(null == min ||
...