Data Loggers
Data loggers allow to gather, process and visualize statistical data on the variations of a data set.
They can be used to automatically generate periodic charts of its trend and/or to log data as CSV files.
Data loggers collect data and group them in order to visualize the trends for each hour (or group of hours) of the current and past day, each day of the current and past month, and each month of the current and past year.
Further, they allows for the logging of every processed value.
There are two types of data logger:
- counter: suitable for the creation of statistics of an incremental value (e.g. energy consumption or production). It calculates the variation (delta) of the value for each time interval with respect to the previous one. Further, it is possible to specify time slots and the relative rates to calculate for instance the costs for energy consumption.
- range: aimed at the computation of the maximum, minimum, and average of a fluctuating value (e.g. a measured temperature or humidity) for each time interval.
Once a data logger is defined in hsyco.ini, you can easily pass data to it using a simple action in EVENTS, a JavaScript function or Java method, and display statistical data using the (datalogger) graphic object.
HSYCO will also optionally (charts are automatically updated if DataLoggers.<id>.UseCharts = true) update a set of generic charts, allowing you greater control on the graphic representation of your data than the standard (datalogger) object. The available charts depend on the type of the defined data logger.
Counter Data Loggers
The first step to create a counter data logger is to define it in the HSYCO configuration.
Refer to the Data Loggers section in the configuration chapter for a complete description of all the available parameters and options.
In the following examples we have defined a counter data logger named “energy” with default parameters.
Now, we need to provide the data logger with the incremental value we want to process.
Assuming we have an I/O server named “elektro” which provides the energy consumption value, we write the following lines in events.txt:
IO elektro : DATALOGGER energy = IO elektro, DATALOGGER energy = FILE LOG energy.csv
Whenever the I/O server will provide a new value, the data logger will be updated and a log entry will be added to the file “energy.csv”.
Finally, in order to display the data logger’s charts, we should use the (datalogger) object, for example:
(datalogger energy; x80y60; 820; 500; kWh;)
For a complete reference of all the available actions on data loggers refer to the relative section in the Events programming chapter.
The same actions can be performed using JavaScript or Java code.
We could also create a data logger to monitor the expenses relative to energy consumption, initializing a new counter data logger and declaring the time slot rates in the file dataloggers.ini.
In hsyco.ini we declare our new data logger:
DataLoggers = cost DataLoggers.cost.Type = counter
Then, we set the elektro I/O server to update the data logger. In events.txt we add this line:
IO elektro OR TIME : DATALOGGER cost = IO elektro
Note that this time we are updating the data logger not only when a new value is available, but also every minute. This is necessary to have an accurate calculation of the expenses.
Now we need to declare our time slots in the file dataloggers.ini, for instance:
cost; 0; 00:00-11:59; *; *; 0.3 cost; 1; 12:00-16:59; *; *; 1.4 cost; 2; 17:00-23:59; *; *; 0.8
These rules state that every day from midnight to 11:59:59 we are in slot 0 and the rate to be applied is 0.3, from 12:00:00 until 16:59:59 we are in slot 1 and the applicable rate is 1.4, later on slot 2 applies with a rate of 0.8.
We can include some exceptions by adding some lines before these rules:
cost; 0; *; *; 2000/12/10-2000/12/31; 0.3 cost; 2; *; 67; *; 0.8 cost; 0; 00:00-11:59; *; *; 0.3 cost; 1; 12:00-16:59; *; *; 1.4 cost; 2; 17:00-23:59; *; *; 0.8
The previous rules will still apply, except on Saturdays (6) and Sundays (7) when during all day slot 2 will apply.
Further, during the period between December 10th and December 31st of 2000, slot 0 will always apply despite the day of the week or the time.
Refer to the section about the dataloggers.ini file for a complete reference on how to write time slots rules.
At this point we should add the (datalogger) object to the Web interface to display the charts and totals. The user interface also allows you to filter data by rate.
Further, we can have a detailed report of all the processed data by specifying the path of a log file in hsyco.ini:
DataLoggers = cost DataLoggers.cost.Type = counter DataLoggers.cost.RatesLogFile = counterRates/log.csv
This will create a CSV file listing a row for each update of the data logger divided in the following columns:
data_logger_name, update_time, provided_value, calculated_cost, slot_id, applied_rate