I want to get average of device data where my device send me ppm value of Co2 in every minute like 10ppm , 9ppm etc
so everyday i will get 60*24 =1440 updates from device and i want calculate a day-average value so that next day i can show its more than yesterday or not , if yes then how much it is…
how i can approach this ?
how to get average of that so that i can display statistics?
Something like this should work:
const getDayAverage = async (model, date) => {
// Depending on how date stored
const _dateFormatted = new Date(date).toDateString();
const average = await model.aggregate([
{ $match: { date: _dateFormatted } },
{ $group: { _id: null, average: { $avg: 'ppm' } } },
]).exec();
return average;
};
Disclaimer: it’s been long time I used Mongo/Mongoose