Kernel::System::Stats

NAME

Kernel::System::Stats – stats lib

DESCRIPTION

All stats functions.

Explanation for the time zone parameter

The time zone parameter is available, if the statistic is a dynamic statistic. The selected periods in the frontend are time zone neutral and for the search parameters, the selection will be converted to the OTRS time zone, because the times are stored within this time zone in the database.

This means e.g. if an absolute period of time from 2015-08-01 00:00:00 to 2015-09-10 23:59:59 and a time zone with an offset of +6 hours has been selected, the period will be converted from the +6 time zone to the OTRS time zone for the search parameter, so that the right time will be used for searching the database. Given that the OTRS time zone is set to UTC, this would result in a period of 2015-07-31 18:00:00 to 2015-09-10 17:59:59 UTC.

For a relative time period, e. g. the last 10 full days, and a time zone with an offset of +10 hours, a DateTime object with the +10 time zone will be created for the current time. For the period end date, this date will be taken and extended to the end of the day. Then, 10 full days will be subtracted from this. This is the start of the period, which will be extended to 00:00:00. Start and end date will be converted to the time zone of OTRS to search the database.

Example for relative time period 'last 10 full days' with selected time zone offset +10 hours, current date/time within this time zone 2015-09-10 16:00:00, OTRS time zone is UTC: End date: 2015-09-10 16:00:00 -> extended to 2015-09-10 23:59:59 -> 2015-09-10 13:59:59 OTRS time zone (UTC) Start date: 2015-09-10 16:00:00 – 10 days -> 2015-08-31 16:00:00 -> extended to 00:00:00: 2015-09-01 00:00:00 -> 2015-08-31 14:00:00 OTRS time zone (UTC)

PUBLIC INTERFACE

BUILD()

Moose constructor method, that is executed on instantiation of the object.

StatsAdd()

add new empty stats

    my $StatID = $StatsObject->StatsAdd(
        UserID => $UserID,
    );

StatsGet()

get a hash ref of the stats you need

    my $HashRef = $StatsObject->StatsGet(
        StatID             => '123',
        NoObjectAttributes => 1,       # optional
        OnlySelectedObjectAttributes => 1, #optional

        # With this the check will be disabled, if a field is already used in one section.
        AllObjectAttributes => 1,      # optional
    );

StatsUpdate()

update a stat

    $StatsObject->StatsUpdate(
        StatID => '123',
        Hash   => \%Hash,
        UserID => $UserID,
    );

StatsDelete()

delete a stats

    $StatsObject->StatsDelete( StatID => '123' );

StatsListGet()

fetches all statistics that the current user may see

    my $StatsRef = $StatsObject->StatsListGet(
        AccessRw => 1, # Optional, indicates that user may see all statistics
        UserID   => $UserID,
    );

    Returns

    {
        6 => {
            Title => "Title of stat",
            ...
        }
    }

GetStatsList()

lists all stats id's

    my $ArrayRef = $StatsObject->GetStatsList(
        AccessRw  => 1, # Optional, indicates that user may see all statistics
        OrderBy   => 'StatisticID' || 'ID' || 'Title' || 'Object', # optional
        Direction => 'ASC' || 'DESC',             # optional
        UserID    => $UserID,
    );

SumBuild()

build sum in x or/and y axis

    $StatArray = $StatsObject->SumBuild(
        Array  => \@Result,
        SumRow => 1,
        SumCol => 0,
    );

GetStatsObjectAttributes()

Get all attributes from the object in dependence of the use

    my %ObjectAttributes = $StatsObject->GetStatsObjectAttributes(
        ObjectModule => 'Ticket',
        Use          => 'UseAsXvalue' || 'UseAsValueSeries' || 'UseAsRestriction',
    );

GetStaticFiles()

Get all static files

    my $FileHash = $StatsObject->GetStaticFiles(
        OnlyUnusedFiles => 1 | 0, # optional default 0
        UserID => $UserID,
    );

GetDynamicFiles()

Get all static objects

    my $FileHash = $StatsObject->GetDynamicFiles();

GetObjectName()

Get the name of a dynamic object

    my $ObjectName = $StatsObject->GetObjectName(
        ObjectModule => 'Kernel::System::Stats::Dynamic::TicketList',
    );

GetObjectType()

Get the type of the object: 'Static', 'DynamicMatrix', 'DynamicList'

    my $ObjectName = $StatsObject->GetObjectType(
        Type => '(static|dynamic)',
        ObjectModule => 'Kernel::System::Stats::Dynamic::TicketList',
    );

GetObjectBehaviours()

get behaviours that a statistic supports

    my $Behaviours = $StatsObject->GetObjectBehaviours(
        ObjectModule => 'Kernel::System::Stats::Dynamic::TicketList',
    );

    returns

    {
        ProvidesDashboardWidget => 1,
        ...
    }

ObjectFileCheck()

AT THE MOMENT NOT USED

check readable object file

    my $ObjectFileCheck = $StatsObject->ObjectFileCheck(
        Type => 'static',
        Name => 'NewTickets',
    );

ObjectModuleCheck()

Check the object module.

    my $ObjectModuleCheck = $StatsObject->ObjectModuleCheck(
        StatType                     => 'static',
        ObjectModule                 => 'Kernel::System::Stats::Static::StateAction',
        CheckAlreadyUsedStaticObject => 1,                                             # optional
        NoLog                        => 0|1,                                           # optional (default 0), hides log messages
    );

Returns true on success and false on error.

Export()

get content from stats for export

    my $ExportFile = $StatsObject->Export(
        StatID => '123',
        ExportStatNumber => 1 || 0, # optional, only useful move statistics from the test system to the productive system
    );

Import()

import a stats from xml file

    my $StatID = $StatsObject->Import(
        UserID  => $UserID,
        Content => $UploadStuff{Content},
    );

GetParams()

    get all edit params from stats for view

    my $Params = $StatsObject->GetParams( StatID => '123' );

StatsRun()

run a statistic.

    my $StatArray = $StatsObject->StatsRun(
        StatID     => '123',
        GetParam   => \%GetParam,
        Preview    => 1,        # optional, return fake data for preview (only for dynamic stats)
        UserID     => $UserID,
    );

StatsResultCacheCompute()

computes stats results and adds them to the cache. This can be used to precompute stats data e. g. for dashboard widgets in a cron job.

    my $StatArray = $StatsObject->StatsResultCacheCompute(
        StatisticID               => '123',
        ConfiguredExecutionParams => \%ConfiguredExecutionParams, # user settings of non-fixed fields
        PushEventIdentifier       => '<UUID>',
        NoLog                     => 0|1,                         # optional (default 0), hides log messages
        UserID                    => $UserID,                     # target UserID
    );

StatsResultCacheGet()

Gets cached statistic results. Will never run the statistic. This can be used to fetch cached stats data e. g. for stats widgets in the dashboard.

    my $StatArray = $StatsObject->StatsResultCacheGet(
        StatisticID               => '123',
        ConfiguredExecutionParams => \%ConfiguredExecutionParams,
        UserID                    => $UserID,                     # target UserID
    );

StringAndTimestamp2Filename()

builds a filename with a string and a timestamp. (space will be replaced with _ and – e.g. Title-of-File_2006-12-31_11-59)

    my $Filename = $StatsObject->StringAndTimestamp2Filename(
        String   => 'Title',
        TimeZone => 'Europe/Berlin',  # optional
    );

StatNumber2StatID()

insert the stat number get the stat id

    my $StatID = $StatsObject->StatNumber2StatID(
        StatNumber => 11212,
    );

StatsInstall()

installs stats

    my $Result = $StatsObject->StatsInstall(
        FilePrefix => 'FAQ',  # (optional)
        UserID     => $UserID,
    );

StatsUninstall()

uninstalls stats

    my $Result = $StatsObject->StatsUninstall(
        FilePrefix => 'FAQ',  # (optional)
        UserID     => $UserID,
    );

StatsCleanUp()

removed stats with not existing backend file

    my $Result = $StatsObject->StatsCleanUp(
        UserID => 1,

        ObjectNames => [ 'Ticket', 'TicketList' ],
        or
        CheckAllObjects => 1,
    );

StatsConfigurationValidate()

Validates the configuration of a given statistic.

    my $StatCorrectlyConfigured = $StatsObject->StatsConfigurationValidate(
        Stat => \%Stat,
    );

Returns a hash with error keys + texts (if any).

StatisticSearch()

Search for stored statistics. Given parameters could be scalars or arrays. Each keys which are stored into the XML structure are usable within the parameters.

    my $StatisticIDs = $StatisticObject->StatisticSearch(
        StatNumber => '1000*',      # Wildcard support
        StatType   => 'static',     # also possible: [ 'static', 'dynamic' ]
        Valid      => 0|1,
        ...
    );

Returns an array ref with statistic IDs.

Scroll to Top