Data field examples?

Former Member
Former Member
Is there any more examples of simple data fields? Might try creating some.

Was looking here and tried an example based off this sample but I can't seem to divide an activity.info by a number or by another activity.info object?

http://developer.garmin.com/connect-iq/programmers-guide/dynamic-data-fields/

Was trying to divide calories by elapsed time to play with in the simulator....(eventually looking to get a calories per minute / per second interval type field)

Thanks
  • Most likely the problem is that you need to check for null, and possibly also a divide by zero. Then, you need to simulate data (via the simulator menu) so that you get actual numbers coming through.

    If you just write this...

    function calculate(info) {
    // average calories per minute
    return (info.calories / (info.timerTime / 60000.0)).format("%.2f");
    }


    You'll likely find that info.calories and info.timerTime are null until you simulate data. If you are testing on a device info.calories will probably be 0, but info.timerTime will be null. If you add the null checks...

    function calculate(info) {
    if (info.calories == null || info.timerTime == null) {
    return "--";
    }

    return (info.calories / (info.timerTime / 60000.0)).format("%.2f");
    }


    You should be okay. You could run into a divide by zero problem if info.timerTime you are doing integral division and the timerTime is smaller than the divisor.
  • Former Member
    Former Member over 9 years ago
    Most likely the problem is that you need to check for null, and possibly also a divide by zero. Then, you need to simulate data (via the simulator menu) so that you get actual numbers coming through.

    If you just write this...

    function calculate(info) {
    // average calories per minute
    return (info.calories / (info.timerTime / 60000.0)).format("%.2f");
    }


    You'll likely find that info.calories and info.timerTime are null until you simulate data. If you are testing on a device info.calories will probably be 0, but info.timerTime will be null. If you add the null checks...

    function calculate(info) {
    if (info.calories == null || info.timerTime == null) {
    return "--";
    }

    return (info.calories / (info.timerTime / 60000.0)).format("%.2f");
    }


    You should be okay. You could run into a divide by zero problem if info.timerTime you are doing integral division and the timerTime is smaller than the divisor.


    Thanks for the response. I think I'm way over my head on how to get that back into the datafield:(. How is function compute different from function calculate?

    Sorry I'm not a programmer but trying to learn the basics on how to get some of these simple fields going with existing watch data.

    Cheers.
  • Sorry. I was writing code on my break and typed the wrong function name...