Complete
over 5 years ago

WERETECH-8574

Bug: Activity.Info.elapsedDistance is way off if playback a .fit file using simulator 3.1.6

Activity.Info.elapsedDistance is way off not only due to lat/lon = [0.0, 0.0]

https://forums.garmin.com/developer/connect-iq/i/bug-reports/initial-values-lat-lon-0-0-if-replaying-a-fit-in-simulator

but rather it seems there are more bugs in the sim.

info.elapsedDistance should be the sum of the distances between the recorded position points lat/lon. So I've calculated the sum of this distance increments and compared it to the value of info.elapsedDistance. I've only used a fast and easy formula to calculate the distances between 2 position points without any smoothing or interpolation. Thus my calculated elapsed distance may differ somewhat to info.elapsedDistance.

By replaying a .fit I get the following values
My sum of distance increments = 125.82m
Activity.info.elapsedDistance = 194.69m
This is a difference of >54% which is well way off.

In the .tcx file of the .fit for the same lat/lon there is stored the value
<DistanceMeters>123.29000091552734</DistanceMeters>

If I don't use the "Playback File" option but instead use the option "Simulate Data" I get this values
My sum of distance increments = 124.67m
Activity.info.elapsedDistance = 129.09m
This is a difference 3.5% that seems to be reasonable to me.

Since "Simulate Data" generates random values the distances are different to the "Playback File" values.

  • Now I've switched the units to miles and made a short run activity. But as you've already mentioned it hasn't any effect to info.elapsedDistance.

    Garmin Connect shows my total run distance = 2.67 km .

    I've replayed the entire .fit in the sim using System.println(info.elapsedDistance) . At the end of the .fit the sim stops with info.elapsedDistance = 3769.1 m . This is again 39% off.

    But the running time from GC coincides very well with info.elapsedTime.

    You've said: "... my distances are correct with the fit files I've tested. (some past 5k's etc)"

    Please tell me how did you've checked that your info.elapsedDistance is correct? Have you replayed your entire 5K .fit and compared it to info.elapsedDistance = 5000 m at the end?

  • For example, if you look at the API guide:

    elapsedDistance ⇒ Toybox::Lang::Float
    The elapsed distance of the current activity in meters (m).

    and this is what you need to do to display it:

    var actInfo=Activity.getActivityInfo();
    var devSet=Sys.getDeviceSettings();
    var distVal=0.0;
    
    if(actInfo.elapsedDistance!=null) {
    	//elapsedDistance - distance in meters
    	distVal=actInfo.elapsedDistance;
    	if(devSet.distanceUnits==Sys.UNIT_STATUTE) {
    		distVal=distVal* 0.000621371;
    	} else {
    		distVal=distVal/1000;
    	}
    }
    
    //display distVal (miles or km)

  • The data in a .fit is always metric.  When you play it back your app sees metric.  If you want to display statute (based on the setting) you do that conversion in your app.

    You can see this by looking at Activity.getActivityInfo() in the API doc.

  • OK, thanks Jim, I've understand. The settings in the sim are only for testing the settings on the real device. The settings in the sim are only transfered to the app and the sim itself makes no actions regarding the settings. The app can request the settings and control the program flow and calculations of the values depending on this settings.

    In summary my DF runs on real device or sim and it doesn't handle the units.

    The difference only appears with sim "Playback File".

    The thoughts of a conversion error for the units in the sim can't get me out of my head. If the .fit is recorded in miles and the app handles the miles by multiplication with the factor 1.6 to km then there is no error viewable. But if the .fit is recorded in km and there is also (improperly) a multiplication with the factor 1.6 the distance is 60% off. Or the sim uses the earth radius in miles vs. km for calculating the distance increments between the position points or somewhat else in this direction.

    Soon I make a test recording my activity in miles and look at the results.

  • In a CIQ app, you see what that setting is (Sys.getDeviceSettings().distanceUnits for example), and you use that to display statute or metric in your all.  The sim just defines what you see in getDeviceSettings(),  Doing the conversion is all up to you.  This is how a real devices works.

    Ad far as my comment, I was assuming that your app did things like pay attention to the GPS accuracy.  In my apps, I don't actually start recording until after there's a gps lock.  So the actual recording doesn't start until a .fit is being played back, even if the app is started before playback..