black-mirror-1 / singlestat-math

Panel based on the default single stat panel with added feature to do math across metrics from multiple queries.
MIT License
14 stars 14 forks source link

Support using Math queries in thresholds #14

Closed sillyfrog closed 6 years ago

sillyfrog commented 6 years ago

This PR adds support for using the Math feature in the Thresholds. This way you can dynamicially update the thresholds based on incoming data.

My use case is battery charge level, based on solar system output. The main bar in the chart is the current level, and the threshold shows the current target charge level.

My first time using TypeScript, so please excuse any newbie mistakes.

sillyfrog commented 6 years ago

I see you are working on this at the same time :)

I have tried to resolve the merge conflicts - hopefully you'll know if this works of the top of your head. I had ensure I had ng-change="ctrl.refresh()" in editor.html for things to update correctly - I'm hoping with won't mess with the sorting (but the sorting may mess with things if using Math).

black-mirror-1 commented 6 years ago

Hi sillyfrog,

I think this would work perfectly if you are able to evaluate the math first and then return the number result to the auto sort. So auto sort will still work alongside the queries inside the thresholds.

sillyfrog commented 6 years ago

Closing this one, I created a new PR that will also support sorting.

jfoxe commented 6 years ago

Thanks sillyfrog, very useful functionality added! How difficult would it be to change the min and max fields to dynamic values too in the same fashion?

sillyfrog commented 6 years ago

@jfoxe Shouldn't be too hard I think. I'll check it out and see if I can add it to my current PR.