Alyssa Rolfe
Posts: 0
Joined: Fri Jun 20, 2014 12:48 pm

Find separate Averages of separate columns in db

Right now I am a bit stuck on the details of getting my project done.

I want the user to be able to calculate their average sugars for the 4 different times of the day based on the data they they put in. Making the list and deleting and everything works great. I can query the list and get it report a list of all the morning sugars, but I dont know where to go from here.

I have read whats online and I know that I need to save the query into localStorage and then report it back out with the calculations performed.

As far as the JS is concerned, I am novice at best. I know that I need to call the localStorage item use code to count the number of items in my list and divide by the sum of all my numbers. I have the general idea, but I am so lost with the specifics and some guidance would be greatly appreciated.

Thanks!

Image Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Find separate Averages of separate columns in db

Hello Alyssa,

Please look at this link, it should be helpful:
https://getsatisfaction.com/apperyio/...

Alyssa Rolfe
Posts: 0
Joined: Fri Jun 20, 2014 12:48 pm

Find separate Averages of separate columns in db

I have worked through some of what is going on in that post, but still having little success. I can get the query to work when I test it but I am getting a NaN response in my UI label. So...something is of but Im not sure where.

I have it set to my Get Averages button invokes the query and sets my local storage variable that is specific to my morning average.

Under data I have set to run the following JS when the query is a success:

var morningVal = 0,
i;

if(data.length) {

for (i = 0; i < data.length; i++)
{
morningVal += data.local_morning_av;
}
morningVal = morningVal / data.length;
}

Appery("Morning_Average_Reported").text(morningVal);

In my query_service I have my where request to return the following data which gives me when I have non-blank recordings basically. (This works fine when I test it)

{"Morning":{"$gte":1}}

Thanks for the help. I have really spent a great deal of time trying to figure this out on my own.

My issue I think lies in my mapping because I really dont know where to pull things from or where to put them. Image Image

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Find separate Averages of separate columns in db

Hi Alyssa .

You code looks ok.

Please give us your app public link and steps to reproduce the problem.

We need to take a look to define what is wrong in your implementation.

Thanks & regards.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Find separate Averages of separate columns in db

Hi Alyssa,

Please use following code instead of yours:

pre

var morningVal = 0, i;

if(data&#46;length) {

Code: Select all

 for (i = 0; i < data&#46;length; i++){ 

     &#47;&#47;You don't have "local_morning_av" in item&#46; But "Morning" exist&#46; 
     &#47;&#47;morningVal += data[i]&#46;local_morning_av;  
     morningVal += data[i]&#46;Morning;  
 }; 
 morningVal = morningVal / data&#46;length;  

};

Appery("Morning_Average_Reported")&#46;text(morningVal);

/pre

Regards.

Alyssa Rolfe
Posts: 0
Joined: Fri Jun 20, 2014 12:48 pm

Find separate Averages of separate columns in db

Worked wonderful! I would have taken me forever to catch that error.

Thanks so much for the help!

Return to “Issues”