What's the error you see? If it's from type checking, use ORDER_NEWEST_FIRST or ORDER_OLDEST_FIRST and not a Number for order
You can walk the iterator and count them. You may find you have two cases where you use the info from SensorHistory.get*History - you either want only the newest sample, or you want to graph what's there…
Well i can say that the fenix 5 has 180 samples for temp, press and elev but only 120 for Heart Rate...
Turn off the f5 turn it back on, and check again. You'll see far lower numbers.…
What's the error you see? If it's from type checking, use ORDER_NEWEST_FIRST or ORDER_OLDEST_FIRST and not a Number for order
ops.. you are right, now the compile error is gone. Is there any way to know the number of elements of the history?
You can walk the iterator and count them. You may find you have two cases where you use the info from SensorHistory.get*History - you either want only the newest sample, or you want to graph what's there.
In the case of the graph, you'll know the max width of the graph. In that case you just walk the iterator until you hit the max width of the graph or you run out of samples.
i tried to count items inside an HR history of the fenix 5. I debugged and found that records are 120. Unfortunately when i'm counting if i retrieve the value... i hit the:
Error: Unexpected Type Error Details: Failed invoking <symbol>
because the next() went over the 120th record...
just for debug i tried the following and the 120 record invoke the error...
This is something where the sim is different than real devices. The number of samples differ as does the time between samples. What happens if you see less than 120 sample in the sim? You don't want to use a count - you want to go until "next()" is null. When you first turn on a watch, you might only have one sample
maybe you didnt get the point:
when i execute
value =((HRHist.next().data)); <----- error is here
the "value" didnt get the null ... the app just crash there...
Well i can say that the fenix 5 has 180 samples for temp, press and elev but only 120 for Heart Rate...
No you have a bug here:
value =((HRHist.next().data));
HRHist.next() will be nulll when you reach the end and doing "null.data" throws an error.
You want to null check HRHist().next() and only if it's not null do you want to use .data
var a =HRHist.next();
if(a!=null) {value=a.data;}
A clearer way to do this is:
//iter is what you get back from the get*History() call
if(iter!=null) {
var sample=iter.next();
var count=0;
while(sample!=null && count<100) { //you can add a counter and use at most, say 100 sampples here
var data=sample.data;
if(data!=null) {
//do what you want with the data
}
count++;
sample=iter.next();
}
}
i apologize... i didnt get the point!!! ok.. going to work on it to change my code
Well i can say that the fenix 5 has 180 samples for temp, press and elev but only 120 for Heart Rate...
Turn off the f5 turn it back on, and check again. You'll see far lower numbers. And on different devices, it won't top out at the same numbers. That's why you want to null check.
yes correct...
i did the homework, i find the history length first and then show the data into graphs. Looks like working like a charm. I must say that i didnt carefully read the documentation... your example is better than the one into doc!
thank you very much. My watchface is almost ready... (camuflage watchface)