Page 1 of 3

How can I average numbers from the database?

Posted: Thu Jan 05, 2017 3:14 am
by Ellen Schlechter

Using some some of the cases in already on the forum, I was able to figure this out to some extent but I am getting an end result of NaN. I am not sure why it is not a number though. To me it should be.

Here I map the weights to a number array.Image

Here is how that LSV is set up.
Image
Image

Then in the success of the mapping, I run this javascript. Notice that I have an array commented out. If I use that array instead of the one that is saved as a LSV, the average works as expected. Image

This is the result of the above code. I get NaN but I don't know why. Image

Do you have any ideas as to why my database numbers that are stored as the number type are remaining numbers in the array?


How can I average numbers from the database?

Posted: Thu Jan 05, 2017 11:13 am
by Serhii Kulibaba

Hello Ellen,

Please look at this example how to save an array of values into the Storage variable: https://docs.appery.io/docs/appbuilde...


How can I average numbers from the database?

Posted: Thu Jan 05, 2017 6:19 pm
by Ellen Schlechter

So I tried putting this code in the JS area where I map the array (first picture in original post):
var myIDs = [];
$.each( data.results, function( key, value ) {
myIDs.push(value._id);
});
Apperyio.storage.myIDs.set(myIDs);

Then when I tested, I checked the console and there wasn't a value saved in the array at all.


How can I average numbers from the database?

Posted: Fri Jan 06, 2017 12:49 pm
by Serhii Kulibaba

Please check the same JS code, but change predata.results/pre to predata/pre


How can I average numbers from the database?

Posted: Fri Jan 06, 2017 3:14 pm
by Ellen Schlechter

Eliminating the ".results" part of the code didn't change anything. It still comes back as an empty array instead of a number array.


How can I average numbers from the database?

Posted: Mon Jan 09, 2017 10:16 pm
by Ellen Schlechter

If I shared my app with support, would that help?


How can I average numbers from the database?

Posted: Tue Jan 10, 2017 5:41 pm
by Serhii Kulibaba

Could you check a service response with a code below?
prealert(JSON.stringify(data));/pre Is it empty or not? Could you send us a screenshot with it's values?


How can I average numbers from the database?

Posted: Tue Jan 10, 2017 10:56 pm
by Ellen Schlechter

I tried putting that code before the code I tried a few days ago (in the js mapping) but it didn't fire. I then tried putting it after and it still didn't fire. I commented out the old code and tried it...didn't fire. I put it on success of that service and it fired but it was just [].


How can I average numbers from the database?

Posted: Wed Jan 11, 2017 4:52 pm
by Serhii Kulibaba

Yes, it has to be used in the success event. If you get [] - in that case - the service response is empty.


How can I average numbers from the database?

Posted: Thu Jan 12, 2017 12:32 am
by Ellen Schlechter

Ok so the reason that it was empty was because I had the wrong column type. I fixed the column type back to number and tried running the recommend code and got
"User transformation function exception. Reason: Can't find variable: data"
When I run my regular query and do a data.length, I get back the proper number and it saves the values in local storage as it should. It just doesn't recognize them as numbers or something along those lines.

In summary, I can get the numbers in a lsv, but when they come out, there are no longer identified as numbers.