Math.mean

using Toybox.Math;

ThreeSecPwrArray.remove(ThreeSecPwrArray[0]);
ThreeSecPwrArray.add(Pwr);
ThreeSecPwr = Math.mean(ThreeSecPwrArray);

I'm trying to use the above code, but the simulator gives an error.

Error: Symbol Not Found Error
Details: Could not find symbol 'mean'

I changed Math.mean to Math.pow(Pwr,2) just to check and that works fine. Have I got the notation wrong?

  • If you look at the API guide for mean, you'll see this:

    Since: 3.1.0

    That indicates that's it's only available on sim targets/devices running CIQ 3.1.0 or greater.

    If you run your app using a target like a fenix 6, it will run fine, but if you use a target with a lower version of CIQ (say a fr735), you'll get the crash you see, as mean isn't available.

    In your code, you can see if you can use mean with a "has" statement, and if it isn't do your own version of mean.  For example:

    var a=[1,2,3];
    var b=null;
    if(Math has :mean) {
    	b=Math.mean(a);
    } else {
        //do your own mean
    }
    Sys.println("b="+b);

    on devices with CIQ 3.1.0 or greater, you'll see b=2.000000 while on devices with an older CIQ, b=null.

  • Thanks Jim.

    It's for an Edge 1030. I did find the below online for software updates on the 1030. I'm currently running version 9.10.

    So I have also found that SDK is now 3.1.7 (I was running 3.1.6) Now it lets me run 3.1.x in the simulator and mean works. Thanks for your help.

    Changes made from version 8.00 to 8.06:

    • Added support for Connect IQ 3.1
  • 8.06 indicates beta FW (an optional install) so as far as the SDK, it's still 8.00 with CIQ 3.0.

    If you have 8.06 on your device, a sideload should run but you'll crash in the sim.  In an eclipse run configuration you can see when it supports 3.1.x when you can select that as a target SDK version for the e1030.

    If you publish an app that uses mean today, it will crash on devices that aren't running the 8.06 beta, so I wouldn't do that.

  • What sdk are you running?  I just checked and with 3.1.7, and there it sees the e1030 has 9.10 FW and CIQ 3.1.3.

    If you're running an older SDK, you want to update to 3.1.7

  • When I had the issue it was 3.1.6. The simulator would only let me pick 3.0.x for the SDK on a edge 1030. I have updated now to 3.1.7 and now it lets me pick 3.1.x in the simulator

  • I don't think it'll crash Jim.... I *think* what happens is that when you try to DOWNLOAD it from Garmin Connect, you'll get a pink dialogue box popup in your browsers that says that your device needs an update before you can use this app. I just got feedback about this "error" from users when I published 3.1 data fields. Maybe if you try to install it using other techniques you won't get that warning?

  • Actually, the min version in store would be 3.0 if built with the 3.1.6 SDK even if you used "mean" in the code,  Min FW is based on the SDK used to build the app, not on what's currently available for the device.

    It would be very possible for the app to be installed on devices without a 3.1 VM.