more G-Labs products

Author Topic: Statistic option for custom paramter  (Read 2689 times)

December 05, 2015, 09:30:21 PM
Read 2689 times

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi,

I would like to add some custom property to the statistics db, for example, I've made a program that Raise Event for update 3 custom property :
System.CPU
System.Memory
System.Disk

I would like to show these properties on the statistics db in order to make graphics on it.

Thanks

December 06, 2015, 12:54:59 AM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I'm using the CPU Load APP and it does show up in the statistics plots.
« Last Edit: December 06, 2015, 12:57:57 AM by bkenobi »

December 06, 2015, 05:21:22 PM
Reply #2

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi,

I've made some test and properties which stat with "Sensor." seems to be added in the statisctics database and could be display in the chart.

But I would like to display some other properties (for exemple "Status.Level" in order to see when a switch is on or off during the day, to check when my boiler is on) it's not possible.

It would be very usefull if we could select which property we want to see in the statistics database or not.
Il could be for exemple Sensor.* or System.* (in my case of CPU, Memory and Disk) or Status.Level (if we set Status.* then battery info will be store in the statistics db too), Weather.Precipitation (don't know if it exist but it's an example)

Note @bkenobi : the last version of the SystemChecker Program use properties System.* instead of Sensor.System.*. In the past I've use Sensor.System.* because I was using the Sensor widget and it only display Sensor.* values

Thanks

December 06, 2015, 08:11:42 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Perhaps adding Program.StatisticsOn("<field_name>") / Program.StatisticsOff("<field_name>") helper functions could help.
Any other solution/suggestion is welcome.

Cheers,
g.

December 06, 2015, 11:44:12 PM
Reply #4

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi,

I'm not sure how it works actually, I've check the ModuleParameter.cs and find that if the value of a module parameter is a numeric value, then it should be added to the statistic db?
So I don't understand why some value I update with a Raise Event doesn't appear in the list of available value on statistics page. Where is the filter which allow or not a value to be show in the statistics page? (I will check if these values were in the statistic database).

For the new feature I proposed, If all the numeric value was save in the statistics db, the goal is to allow the end user to select which one should be showable on the chart (to limit the list in the combobox).
If not all the value was save in the database, the goal is to allow the end user to select which one should be save in the database and allow him to display them in the statistic chart.
Theses choices could be made in the maintenance page on the statistics section for example.

About your proposal, I'm not sure it's a developper role to know which property has to be in the statistics db or not. It should be a user choice (in my case I need to have the Status.Level History on a chart in order to check when my boiler is On or Off during the day to see If I could optimize my home heating management but it's not necessary the case for other users)

Thanks
« Last Edit: December 06, 2015, 11:51:14 PM by DavZero »

December 15, 2015, 09:41:14 PM
Reply #5

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi,

So I've check on the statistic_db and find that only parameter name like Sensor.* or Meter.Watts were store in it.

My "demand" is to enable user to store other parameter (to check when a switch is on or off, store a custom property which not start with Sensor, ..., store a wether.precipitation if it's needed, ....)

Thanks.

December 15, 2015, 11:15:31 PM
Reply #6

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Do you need to plot the state over time?  If not, you can access the state of modules with the Status.Level parameter.
Code: [Select]
module.Parameter("Status.Level").ValueAlso, if you want to see a history of the module's state, you can use the history array which stores the last 10 states by default but can be changed to whatever you prefer in code.

December 16, 2015, 07:58:52 PM
Reply #7

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi,

Yes I need to check it over the time.

For my example, the switch I want to monitor is my boiler switch, in order to monitor my "home heating managment".

But it's an example and I don't see why we should not store all the values in a database in order to check the history (I know that it will use more space but what is a 1 or 2 Go on a raspberry sd card today?).

The best way to do it for me is to let the user select which property should be store. It could be done on the statistic page, user can select from a listbox, which list all the propertie existing in is HG configuration, which value he want to see in the statistic_db and pass it to another listbox which list all the properties already store in the statistic_db.
An other way to do that is to add a parameter to all the widget in order to let the user check if the properties of this widget should be store in the statistic or not.

Thanks

December 16, 2015, 08:19:55 PM
Reply #8

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
http://<hg_address>/api/HomeAutomation.HomeGenie/Config/Modules.StatisticsGet/<module_domain>/<module_address>/<parameter_name>

this will give last 24 hours detailed history of a module parameter. This is currently used in the android app and could be used in hg widgets as well.

HG statistics implementation isn't updated since long, but I'll take your suggestions into consideration for the future if hg deserve it :)

Cheers,
g.
« Last Edit: December 16, 2015, 08:56:50 PM by Gene »

December 16, 2015, 08:52:22 PM
Reply #9

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
OK thanks,

I've just test and the address should start with http://<hg_address>/api/  (like all other WEB API command) and it works.

It's a "on memory" history, that mean if I restart, I lose all the history.

Thanks for watching what could be done on the statistics.

Bye

December 21, 2015, 01:17:54 AM
Reply #10

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
While going through HG code, I realized it is already possible to decide what parameters will be stored in the stats db.
Code: [Select]
var statFields = HomeGenie.Service.Logging.StatisticsLogger.StatisticsFields;
this is a List<string> containing the list of fields that will be stored in the db and it is currently defined as follow:
Code: [Select]
       List<string> StatisticsFields = new List<string>() {
            "Sensor.",
            "Meter.",
            "PowerMonitor.",
            "Statistics."
       };
so for adding a field:
Code: [Select]
string myField = "MySensor."; // log anything that start with "MySensor."
if (!statFields.Contains(myField))
   statFields.Add(myField);
this is a standard C# List<string> so removing/clearing is also possible.

Cheers,
g.

December 30, 2015, 01:33:41 AM
Reply #11

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Can I assume that if I run this once it will permanently be retained?  Or, do I have to run it on every boot?  Or every version update?