Numerical expression for obtaining max from list of variables

All about the standard Meteobridge devices based on mobile routers from TP-Link, D-Link, ASUS

Moderator: Mattk

Post Reply
swyman18
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: Wed Jan 24, 2024 11:26 pm

Numerical expression for obtaining max from list of variables

Post by swyman18 »

Hi,
I have a specific scenario where I want to pass an HTTP request command that includes the maximum value of the last 5 wind sensor readings. I have confirmed that the template variables [wind0wind-prev1], [wind0wind-prev2], [wind0wind-prev3], etc... are returning the correct values that I want, and I am trying to figure out if there is an expression available to get the maximum value from that list if template variables.

I see in the documentation there are numerical expressions "max" and "min", can that be used in this scenario? If so, what would the syntax be to take the maximum of an array of variables?

Let me know if anyone has any ideas.

Thank you very much.
Mattk
Platinum Boarder
Platinum Boarder
Posts: 1395
Joined: Mon Sep 22, 2014 3:24 am

Re: Numerical expression for obtaining max from list of variables

Post by Mattk »

For that specific scenario I don't believe there is a specific selector but Add (+) the last/previous five(5) prev1, 2, 3, 4&5 values and divide (/) by 5
swyman18
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: Wed Jan 24, 2024 11:26 pm

Re: Numerical expression for obtaining max from list of variables

Post by swyman18 »

Mattk wrote: Tue Jan 30, 2024 1:11 am For that specific scenario I don't believe there is a specific selector but Add (+) the last/previous five(5) prev1, 2, 3, 4&5 values and divide (/) by 5
Thanks yeah, I was going to try to calc the average instead but I can't seem to get the sum (+) expression to work. Minus, multiply and divide work fine.
If I try this simple test passing to my MB, it seems to ignore the +100:

http://x.x.x.x/cgi-bin/template.cgi?template={*[wind0wind-act=mph.1:0]+100*}&contenttype=text/plain;charset=iso-8859-1

But - , * and / work as expected. Is it because + is a special character in the URL?
swyman18
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: Wed Jan 24, 2024 11:26 pm

Re: Numerical expression for obtaining max from list of variables

Post by swyman18 »

Actually, looks like the “+” expression is working for me when I put it in the actual HTTP request URL in MB. So I’ve got that working to get the average of the last 5 wind sensor readings.

It would be good if I could get the max, but this works for now. Thanks!
Mattk
Platinum Boarder
Platinum Boarder
Posts: 1395
Joined: Mon Sep 22, 2014 3:24 am

Re: Numerical expression for obtaining max from list of variables

Post by Mattk »

Sorry where did I get the average from? You wanted the Max over the previous 5 instances. However Sum (+) does work ok as in the following average mock up to email.

Avg5#Avg5={*([wind0wind-prev1]+[wind0wind-prev3]+[wind0wind-prev5])/3*}

Need to think some more regard the Max from the prevx instances.
Post Reply