Complete
over 4 years ago

Closing out ticket since this is the same as issue WERETECH-9599.

getOxygenSaturationHistory() issue

Hi.

I m trying to use the Oxygen Saturation Sensor History. i m using code below:

var strValue = "";
var spo2 = null;
if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getOxygenSaturationHistory)) {
	var spo2H = Toybox.SensorHistory.getOxygenSaturationHistory({});
	var sample = spo2H != null ? spo2H.next() : null;
	if (sample != null && sample.data != null) { spo2 = [sample.data, Utils.momentToString(sample.when,0,true)]; }
}
if(spo2 != null){ strValue = spo2[0].format("%d") + "%" + spo2[1]; }

It seems to not work correctly, as i some times i obtain no value even if i just made mesure.

Other times, even if the moment value of last mesure is correct, the value is wrong and change even if no new mesure provided.

Overmore, as soon as i try to define period using duration i got an error specialy when the period used doesn't contain mesure.

Please note that all is working fine on simulator but not on watch.

Can you please open a ticket.

Parents
  • Just tried something else.

    I provided a o2 mesure at 13h38 value mesured was 96%.

    I modififed the code as below

    var spo2 = null;
    var strValue = "";
    if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getOxygenSaturationHistory)) {
    	var spo2H = Toybox.SensorHistory.getOxygenSaturationHistory({
    		:period => 2,
    		:order => Toybox.SensorHistory.ORDER_NEWEST_FIRST
    	});
    	var sample = spo2H != null ? spo2H.next() : null;
    	if (sample != null && sample.data != null) { spo2 = [sample.data, Utils.momentToString(sample.when,0,true)]; }
    }
    if(spo2 != null){ strValue = spo2[0].format("%d") + "%" + spo2[1]; }
    
    

    In this case the value displayed is : 0% 13h38

Comment
  • Just tried something else.

    I provided a o2 mesure at 13h38 value mesured was 96%.

    I modififed the code as below

    var spo2 = null;
    var strValue = "";
    if ((Toybox has :SensorHistory) && (Toybox.SensorHistory has :getOxygenSaturationHistory)) {
    	var spo2H = Toybox.SensorHistory.getOxygenSaturationHistory({
    		:period => 2,
    		:order => Toybox.SensorHistory.ORDER_NEWEST_FIRST
    	});
    	var sample = spo2H != null ? spo2H.next() : null;
    	if (sample != null && sample.data != null) { spo2 = [sample.data, Utils.momentToString(sample.when,0,true)]; }
    }
    if(spo2 != null){ strValue = spo2[0].format("%d") + "%" + spo2[1]; }
    
    

    In this case the value displayed is : 0% 13h38

Children
  • One of the bugs is that in getOxygenSensorHistor, is the order is ignored and the oldest is always first.  Another bug is the "when" for a sample is in newest first order.  So the first sample is the oldest, but when says it's the newest.  These is on real devices vs the sim.