KE::Statistics perl module
The KE::Statistics
perl module provides a set of objects to make the creation of tasks easier. The module is located in the utils/KE directory on the

KE::Statistics
- A set of objects usable by periodic scripts.

use KE::Statistics;
my %Title =
(
"0" => "Records by Table", # English title
"1" => "Enregistrements par table", # French title
);
sub
Periodic
{
my $session = shift;
my $date = shift;
my $period = shift;
my $users = $session->users();
my $tables = $session->tables();
my $operations = $session->operations("eregistry");
my $query = "Select all from eregistry where Key1 = " .
$session->quote() . "User" . $session->quote();
my $results = $session->search($query);
while ($results->next())
{
my $key = $results->text("Key1");
...
}
$results->close();
my $stats = $session->statistics();
my $yesterday = $date->yesterday();
$stats->setDate($yesterday);
$stats->setDateFrom($yesterday);
$stats->setDateTo($yesterday);
$stats->setKey1("Records By Table");
or
$stats->setTitle($period, \%Title);
$stats->setValue("3");
$stats->write();
}

The KE::Statistics
module provides a set of objects to facilitate the generation of records for the estatistics table. The Periodic Tasks subsystem provides a plug-in mechanism that allows new tasks to be added to the existing framework. Each task is contained within a perl library (.pl file) and must contain at least one function, the Periodic($session, $date, $period) method.
The arguments are:
|
A |
|
A |
|
A string that contains the name of the time period for the task being run. Typical periods include |
The Periodic()
function is called by the Periodic Tasks subsystem at a scheduled time (e.g. hourly, daily, weekly, monthly, etc.) to create records in the estatistics table.
The following objects are provided within the module:

A KE::Statistics::Session
object is used to gather information from the back-end server. The object may query any table or set of tables to allow statistical information to be generated. A set of methods allows information about the server environment to be gathered (e.g. list of registered users, list of tables, etc.).
As a Session
object is provided as an argument to the Periodic() function, it is not necessary to create the object yourself, rather the supplied object should be used (which is efficient as only one Session object is used by all tasks invoked in the current execution). As the Session object is shared, you must not close() it in your task.

|
|
|
Creates a connection to the server environment. As the Periodic Tasks subsystem provides a |
|
|
|
Executes a TexQL query statement on the server. The |
|
|
|
After your tasks have generated statistical information, it is necessary to write the data into estatistics records. The |
|
|
|
When building TexQL statements, non-numeric values must be enclosed within quotes. The quote character is configurable and is set to avoid escaping characters within values. The default quote character is |
|
|
|
Once all communication with the server environment is complete, the connection needs to be closed so that system resources can be returned to other users. The |
|
|
|
The |
|
|
|
The |
|
|
|
The |

A KE::Statistics::ResultSet
object is returned by the KE::Statistics::Session->search($texql) method. The object provides access to the records returned as a result of the specified query. Once you have finished dealing with the ResultSet object, it is necessary to close() it so that system resources can be returned to other users.

|
|
|
A |
|
|
|
When a |
|
|
|
The |
|
|
|
Once you have finished with the records in the |

In order to make the manipulation of dates easier, the KE::Statistics::Date
object is provided. The object contains a breakdown of a date ({year}, {month}, {day}, {hour}, {minute} and {second}). A number of methods are provided that allow the date/time to be manipulated.
To help with arithmetic manipulation of dates the julianNumber() method is provided to return the Julian date (see http://en.wikipedia.org/wiki/Julian_day for details). The integer part of the floating point number returned represents the day number, while the fractional part encodes the time within the day. Normal arithmetic may be applied to the number. The julianDate() method is used to convert a Julian date to a Dateobject. For example, the following code could be used to find the date three days back from today:
$now = KE::Statistics::Date->new();
$then = KE::Statistics::Date->julianDate($new->julianNumber() - 3);
Subtracting two Julian dates will result in the number of days, hours, minutes and seconds between them:
$diff = $now - $then;
When using dates with TexQL query statements, always specify the date in ODBC format (yyyy-mm-dd). The dateText() method provides the value in the correct format. Similarly, time values should be specified using a 24 hour clock (HH:MM:SS). The timeText() method provides the value formatted correctly.

Encoding dates as a Julian number with the time as the fractional component can lead to issues when subtracting dates, as the result represents the number of days, hours, minutes and seconds between the two dates. If you need to find the number of days between two dates, it is necessary to clear the time component before applying the subtraction:
$date1->set(undef, undef, undef, 0, 0, 0);
$date2->set(undef, undef, undef, 0, 0, 0);
$days = abs($date2->julianNumber() - $date1->julianNumber());
While this not a bug, it is something to keep in mind when manipulating Julian date numbers.

|
|
|
The |
|
|
|
The clone() method creates a copy of a |
|
|
|
Returns a new Date object initialised with yesterday's date. The value is 24 hours before the calling Date object; that is, the time component is not changed. |
|
|
|
Returns a new Date object initialised with the date/time one hour before the date/time of the calling Date object. |
|
|
|
Returns a new |
|
|
|
Returns a new |
|
|
|
Returns a new |
|
|
|
The |
|
|
|
The
|
|
|
|
The
|
|
|
|
The
|
|
|
|
The |
|
|
|
The |
|
|
|
The return value of
returns the Julian day number. See http://en.wikipedia.org/wiki/Julian_day for details. |
|
|
|
A |
|
|
|
Returns the numeric day of the week for the given |

The KE::Statistics::Statistics
object is designed to provide easy insertions into the estatistics table. A Statistics object allows the columns within a record to be set and the record written. A check is made to see if the record already exists in the table and if so an update is performed rather than an insertion. This allows periodic tasks to be re-run to refresh data without duplicate records being created.
An estatistics record consists of four main components:
Keys |
A hierarchy of up to ten Keys may be specified. The Keys are used to define the variables used to arrive at the statistical value. The first Key should contain a title defining what the statistical value is. For example:
allows you to determine from |
Date |
Three date fields exist in estatistics: DateExact, DateFrom and DateTo. The DateExact field is filled if the statistical value represents a period of a day or less (that is daily or hourly), otherwise it is left empty. The DateFrom and DateTo fields should always be filled with the commencement and completion dates respectively. |
Time |
Three time fields exist in estatistics: TimeExact, TimeFrom and TimeTo. The TimeExact field is filled if the statistical value represents a single point of time in a day, otherwise it is left empty. If the period is a range of time in a day, the TimeFrom and TimeTo fields should be filled with the commencement and completion times respectively. |
value |
The value is the statistical datum associated with the set of defined Keys for the given date and / or time. For example, a value of 10 with the above Keys would indicate user |
When completing an estastitics record, the appropriate fields should be filled based on the period the value covers.

|
|
|
A new instance of a |
|
|
|
Sets the DateExact column in estatistics to the value of the |
|
|
|
Sets the DateFrom column in estatistics to the value of the |
|
|
|
Sets the DateTo column in estatistics to the value of the |
|
|
|
Sets the TimeExact column in estatistics to the value of the |
|
|
|
Sets the TimeFrom column in estatistics to the value of the |
|
|
|
Sets the TimeTo column in estatistics to the value of the |
|
|
|
Returns the value for the server environment Registry entry:
|
|
|
|
Returns the value for the server environment language delimiter by first checking the environment variable
|
|
|
|
$stats->setTitle($period, %title); Multiple language alternative to set the |
|
|
|
Sets the Key1 column in estatistics to the value supplied. |
|
|
|
Sets the Key2 column in estatistics to the value supplied. |
|
|
|
Sets the Key3 column in estatistics to the value supplied. |
|
|
|
Sets the Key4 column in estatistics to the value supplied. |
|
|
|
Sets the Key5 column in estatistics to the value supplied. |
|
|
|
Sets the Key6 column in estatistics to the value supplied. |
|
|
|
Sets the Key7 column in estatistics to the value supplied. |
|
|
|
Sets the Key8 column in estatistics to the value supplied. |
|
|
|
Sets the Key9 column in estatistics to the value supplied. |
|
|
|
Sets the Key10 column in estatistics to the value supplied. |
|
|
|
Sets the value column in estatistics to the value supplied. The statistical value is a floating point number. |
|
|
|
The |