Cumulative widget for Rain Gauge

Hey Everyone,

Is there a way to do a Widget that graphs out total inputs added up as a cumulative bar graph (or similar)
I have rain gauge inputs I want to add up and say the total for a 24hour period to 9am, then the next “day” starts at 9am to 9am.

Regards

Toby

Hi @tobyj,

My suggestion: you can create an Analysis to count the total of inputs that you got in your variable.
I did an example for you:

const Analysis = require(‘tago/analysis’);
const Utils = require(‘tago/utils’);
const Device = require(‘tago/device’);

async function myAnalysis(context) {
const device = new Device(‘YOUR_DEVICE_TOKEN_HERE’);
const data = await device.find({
‘query’: ‘count’,
‘start_date’: ‘1 day’, // replace ‘1 day’ interval to your choosing
‘variable’: ‘temperature’. // replace temperature by your variable
})
context.log(data);

await device.insert({
‘variable’: ‘count’,
‘value’: data
});
}

module.exports = new Analysis(myAnalysis, ‘MY-ANALYSIS-TOKEN-HERE’);

After you created your analysis, you will need to create an Action by schedule to run your analysis at the time you want it.
Then, you need to add your variable in your widget to display the total of inputs that you have.

I hope to help you! :v:

Hey Thanks for the reply,

I cleaned it up a bit but what is happening it is counting how many payloads or data points have come in over a 24 hour period / 1 day period.

I have this node measuring every 15 minutes reliably, so the below code is outputing: 96 As in 96 measurements per day.

I want it count the Values, so if there 1x tip that is 0.2mm.

const Analysis = require(‘tago/analysis’);

const Utils = require(‘tago/utils’);

const Device = require(‘tago/device’);

// The function myAnalysis will run when you execute your analysis

async function myAnalysis(context) {

// reads the values from the environment and saves it in the variable env_vars

const env_vars = Utils.env_to_obj(context.environment);

const device = new Device(env_vars.device_token);

const data = await device.find({

query: 'count',

start_date: '24 hours',

variable: 'precipitation'

});

context.log(data);

await device.insert({

variable: ‘count’,

value: ‘data’,

});

}

module.exports = new Analysis(myAnalysis, ‘MY-ANALYSIS-TOKEN-HERE’);

Rather I want it to count up any value at any time to a total number for the day.

Hi @tobyj,
In this case you need to get all the data from your device for the current day and apply the sum.

const device = new Device(env_vars.device_token);
const data = await device.find({ variable: 'precipitation', start_date: '1day', end_date: '0day', qty: 10000 });
const result = data.reduce((a, b) => a.value + b.value, 0);
context.log('My total result is', result);