Tuesday, November 1, 2016

Medusa update...


Last weekend I've found some time to give some love the Medusa project again. Besides some minor cosmetics I've decided to add a moving average feature to the Gauge class.
Usually I would say that such a feature should not be part of a control but in this case I've decided to add it anyway. It's just nice if a Gauge or LCD display could display a moving average of the measured values. And for this reason I've added all the needed properties to the Gauge class.
These properties are

  • averagingEnabled (switch averaging in general on/off)
  • averagingPeriod (defines the number of values to average over from 1-1000)
  • averageVisible (defines the visibility of an average indicator)
  • averageColor (defines the color for an average indicator)

In addition you will now find new methods in the Gauge class to get the average. These methods are

  • getAveragingWindow() (returns the list of Data objects used for the average)
  • getAverage() (returns the moving average over the given averagePeriod)
  • getTimeBasedAverageOf(Duration) (returns the moving average over a given duration)

The default value for the moving average period is 10 which means if averaging is enabled the getAverage() method will always return the average over last 10 measured values.
Because sometimes you are more interested in the average over the last 10 minutes or 60 seconds, I've decided to add a method that will calculate the average for a given duration.
Means if you call the getTimeBasedAverageOf(Duration.ofMinutes(10)) method it will calculate the average from the values that have been measured within the last 10 minutes. Please keep in mind that you have to know how often you measure/display data using the gauge to get proper results.
So it doesn't make sense to calculate the time based average of the last 10 seconds if the value was not changed within the last 10 seconds.
As a start I've implemented the new feature in the Gauge.skin and Lcd.skin class. In the Gauge.skin there is a new indicator which looks like the threshold indicator but with a different color (Magenta as default) and in the Lcd.skin it will show the average value instead of the lastMeasured value in the lower center text (if averageVisible == true).
Keep in mind that you have to enable averaging otherwise the value won't change.

On the following screenshot of the Lcd.skin you can see how it looks like:

This feature will be part of the next Medusa release which will be 6.1 so stay tuned.

And that's it for today...so keep coding... :)

No comments:

Post a Comment