Lap average vertical speed

Dear all,
I would like to have on my Vivoactive HR a data field which shows the lap average vertical speed, in m/h. What I mean is the following: say that the lap time is 10 minutes, and I have climbed 15 m during this lap, I would like the data field to show 900 m/h.
I have created an app that does that for the Suunto platform and it's been pretty easy, but Connect IQ is much more complicated and I'm afraid I don't have the necessary skills to do it.

This would be an interesting data field for cyclists, hikers, and basically anyone climbing mountains.

Thank you for your help

GM
  • I think that this should work...

    class MyDataField extends Ui.SimpleDataField
    {
    // accumulated values from before the most recent pause or stop
    hidden var _M_accumulatedTime;
    hidden var _M_accumulatedAscent;

    // values at the time of the most recent resume or start
    hidden var _M_previousTime;
    hidden var _M_previousAscent;

    hidden var _M_paused;

    hidden static const _C_scale = [
    1.0, // convert from meters to meters
    3.28084 // convert from meters to feet
    ];

    function initialize() {
    SimpleDataField.initialize();
    label = Ui.loadResource(Rez.Strings.AppName);

    // maybe this should be derived from info.timerState?
    _M_paused = true;

    _M_accumulatedTime = 0;
    _M_accumulatedAscent = 0;
    }

    function compute(info) {
    //Sys.println("compute");

    // time in milliseconds since last start or resume
    var deltaTime = 0;

    // ascent in meters since last start or resume
    var deltaAscent = 0;

    if (!_M_paused) {

    // guard against null since this can be called before the session
    // has started recording

    if (info.elapsedTime != null) {
    if (_M_previousTime == null) {
    _M_previousTime = info.elapsedTime;
    }

    deltaTime = (info.elapsedTime - _M_previousTime);
    }

    if (info.totalAscent != null) {
    if (_M_previousAscent == null) {
    _M_previousAscent = info.totalAscent;
    }

    deltaAscent = (info.totalAscent - _M_previousAscent);
    }
    }

    var deviceSettings = Sys.getDeviceSettings();

    // milliseconds to seconds
    var time = (_M_accumulatedTime + deltaTime) / 1000.0;
    if (time < 1.0) {
    return 0.0;
    }

    // seconds to hours
    time /= 3600.0;

    // meters
    var distance = (_M_accumulatedAscent + deltaAscent);

    // meters to user units (meters or feet)
    distance *= _C_scale[deviceSettings.elevationUnits];

    return distance / time;
    }

    hidden function pause() {

    if (_M_paused) {
    return;
    }

    _M_paused = true;

    var info = Activity.getActivityInfo();

    //
    // should not need to do null checking here since the activity
    // session should have started before being paused
    //

    _M_accumulatedTime += (info.elapsedTime - _M_previousTime);
    _M_accumulatedAscent += (info.totalAscent - _M_previousAscent);
    }

    hidden function resume() {
    _M_paused = false;

    var info = Activity.getActivityInfo();

    _M_previousTime = info.elapsedTime;
    _M_previousAscent = info.totalAscent;
    }

    hidden function reset() {
    _M_accumulatedTime = 0;
    _M_accumulatedAscent = 0;

    _M_previousTime = null;
    _M_previousAscent = null;
    }

    function onTimerStop() {
    //Sys.println("onTimerStop");
    pause();
    }

    function onTimerStart() {
    //Sys.println("onTimerStart");
    resume();
    }

    function onTimerPause() {
    //Sys.println("onTimerPause");
    pause();
    }

    function onTimerResume() {
    //Sys.println("onTimerResume");
    resume();
    }

    function onTimerReset() {
    //Sys.println("onTimerReset");
    reset();
    }

    function onTimerLap() {
    //Sys.println("onTimerLap");
    reset();
    }
    }

    class MyApp extends App.AppBase
    {
    function initialize() {
    AppBase.initialize();
    }

    function getInitialView() {
    return [ new MyDataField() ];
    }
    }
  • cool! now, will you publish it? can I test it on my watch?
    Thank you!
  • There is no reason that someone can't copy/paste the source into a project and use it.
  • hi,
    i have just uploaded the app to the app store. it will take a couple of days to be approve.
    i think that the url will be this one:
    https://apps.garmin.com/de-DE/apps/5d4f0611-4f97-462b-b803-b7260906523f

    the source code is public available here
    https://github.com/danielp27/Lap-average-vertical-speed

    this line was causing problems, i have modified it.
    distance *= _C_scale[deviceSettings.elevationUnits
  • this line was causing problems, i have modified it.
    distance *= _C_scale[deviceSettings.elevationUnits



    That must have been a copy/paste error on your part. The code above does not have that error, and the post hasn't been edited.

    Travis
  • That must have been a copy/paste error on your part. The code above does not have that error, and the post hasn't been edited.

    Travis

    hi Travis,
    ishould have been more specific. my bad.
    i dont think it was a copy paste issue.
    with your code i can build the app, and execute it in the simulator.
    but when that line is reached, the app crashes. something like "expected number but got boolean".

    i didnt spend lot of time looking for the root cause. but i think "deviceSettings.elevationUnits" does not equal to 0 or 1 so that you can use it as an index for the array.
    or at least not for every single device. i simulated on the FR230, by the way.
    i replaced by this, which works fine
    if(Sys.getDeviceSettings().elevationUnits == Sys.UNIT_METRIC)


    {


    distance *= _C_scale[0];


    }


    else


    {


    distance *= _C_scale[1];


    }


    according the docu, elevationUnits is a number, so maybe the problem is a different one. the fact is that for me the code crashes with the boolean error message
    - (Number) elevationUnitsUNIT_METRIC if elevation is shown in meters, UNIT_STATUTE if it is shown in feet.
  • Oops. Yes, those unit values are booleans in some versions, but they should be numbers. I've previously reported this to Garmin.

    Travis
  • App is available
    Your app submission to the Connect IQ store has been approved. It may take up to 24 hours for the app to appear in the store for download. To access your app submission, go to: https://apps.garmin.com/en-US/apps/5d4f0611-4f97-462b-b803-b7260906523f.
    Sincerely,
    - The Garmin Connect IQ Team
  • App is available


    wow! great job! Thanks a lot! Great Christmas present. I will test it on my next run.
  • v1.1

    v1.1 add user setting to choose if average vertical speed should be reset on every lap

    feature was requested by an user in a review