<commit_before># --
# Kernel/System/Stats/StateAction.pm - stats module
# Copyright (C) 2001-2004 <NAME> <<EMAIL>>
# --
# $Id: StateAction.pm,v 1.1 2004-06-29 10:42:23 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --

package Kernel::System::Stats::StateAction;

use strict;
use Date::Pcalc qw(Today_and_Now Days_in_Month Day_of_Week Day_of_Week_Abbreviation);

use vars qw($VERSION);
$VERSION = '$Revision: 1.1 $ ';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

# --
sub new {
    my $Type = shift;
    my %Param = @_;

    # allocate new hash for object
    my $Self = {}; 
    bless ($Self, $Type);

    # get common opjects
    foreach (keys %Param) {
        $Self->{$_} = $Param{$_};
    }

    # check all needed objects
    foreach (qw(DBObject ConfigObject LogObject)) {
        die "Got no $_" if (!$Self->{$_});
    }

    return $Self;
}
# --
sub Param {
    my $Self = shift;
    my @Params = ();
    # get current time
    my ($s,$m,$h, $D,$M,$Y, $wd,$yd,$dst) = localtime(time());
    $Y = $Y+1900;
    $M++;
    # get one month bevore
    if ($M == 1) {
        $M = 12;
        $Y = $Y - 1;
    }
    else {
        $M = $M -1;
    }
    # create possible time selections 
    my %Year = ();
    foreach ($Y-10..$Y+1) {
        $Year{$_} = $_;
    }
    my %Month = ();
    foreach (1..12) {
        my $Tmp = sprintf("%02d", $_);
        $Month{$_} = $Tmp;
    }
 
    push (@Params, {
            Frontend => 'Year',
            Name => 'Year',
            Multiple => 0,
            Size => 0,
            SelectedID => $Y,
            Data => {
                %Year,
            },
        },
    );
    push (@Params, {
            Frontend => 'Month',
            Name => 'Month',
            Multiple => 0,
            Size => 0,
            SelectedID => $M,
            Data => {
                %Month,
            },
        },
    );
    push (@Params, {
            Frontend => 'Graph Size',
            Name => 'GraphSize',
            Multiple => 0,
            Size => 0,
            SelectedID => '550x350',
            Data => {
                '550x350' => ' 550x350',
                '800x600' => ' 800x600',
                '1200x800' => '1200x800',
            },
        },
    );
    return @Params;
}
# --
sub Run {
    my $Self = shift;
    my %Param = @_;
    my $Title = "$Param{Year}-$Param{Month}";
    my $Year = $Param{Year};
    my $Month = $Param{Month};
    my $Day = Days_in_Month($Year,$Month);

    my %States = $Self->_GetHistoryTypes();
    my @PossibleStates;
    foreach (sort {$States{$a} cmp $States{$b}} keys %States) {
        $States{$_} =~ s/^(.{18}).*$/$1\.\.\./;
        push (@PossibleStates, $States{$_});
    }
    # build x_lable
    my $DayCounter = 1;
    my @Data;
    my @Days = ();
    my %StateDate = ();
    while ($Day >= $DayCounter) {
      my $Dow = Day_of_Week($Year, $Month, $DayCounter);
      $Dow = Day_of_Week_Abbreviation($Dow);
      my $Text = $DayCounter;
      $Text = "$Dow $DayCounter";
      $DayCounter++;
      push (@Days, $Text);
      my @Row = ();
      foreach (sort {$States{$a} cmp $States{$b}} keys %States) {
        my $Count = $Self->_GetDBDataPerDay(Year => $Year, Month=> $Month, Day => $DayCounter, StateID => $_);
        push (@Row,  $Count);
#        $StateDate{}->$States{$_}} = $StateDate{$States{$_}}+$Count;
          $StateDate{$Text}->{$_} = ($StateDate{$Text}->{$_} || 0) + $Count;
      }
    }
    foreach my $StateID (sort {$States{$a} cmp $States{$b}} keys %States) {
        my @Row = ($States{$StateID});
        foreach my $Day (@Days) {
            my %Hash = %{$StateDate{$Day}};
            push (@Row, $Hash{$StateID});
        }
        push (@Data, \@Row);
    }
    return ([$Title],['Days',@Days], @Data);
#    return ([$Title],[@PossibleStates], [4,1,2,8], [4,1,2,6], [24,11,7,2], [1,23,4,6]);
}
# --
sub _GetHistoryTypes {
    my $Self = shift;
    my %Param = @_;
    my %Stats;
    my $SQL = "SELECT id, name FROM ticket_history_type ".<commit_msg>fixed bug 570 - Stat generation script fails under postgres<commit_after># --
# Kernel/System/Stats/StateAction.pm - stats module
# Copyright (C) 2001-2004 <NAME> <<EMAIL>>
# --
# $Id: StateAction.pm,v 1.2 2004-10-18 07:27:11 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --

package Kernel::System::Stats::StateAction;

use strict;
use Date::Pcalc qw(Today_and_Now Days_in_Month Day_of_Week Day_of_Week_Abbreviation);

use vars qw($VERSION);
$VERSION = '$Revision: 1.2 $ ';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

# --
sub new {
    my $Type = shift;
    my %Param = @_;

    # allocate new hash for object
    my $Self = {}; 
    bless ($Self, $Type);

    # get common opjects
    foreach (keys %Param) {
        $Self->{$_} = $Param{$_};
    }

    # check all needed objects
    foreach (qw(DBObject ConfigObject LogObject)) {
        die "Got no $_" if (!$Self->{$_});
    }

    return $Self;
}
# --
sub Param {
    my $Self = shift;
    my @Params = ();
    # get current time
    my ($s,$m,$h, $D,$M,$Y, $wd,$yd,$dst) = localtime(time());
    $Y = $Y+1900;
    $M++;
    # get one month bevore
    if ($M == 1) {
        $M = 12;
        $Y = $Y - 1;
    }
    else {
        $M = $M -1;
    }
    # create possible time selections 
    my %Year = ();
    foreach ($Y-10..$Y+1) {
        $Year{$_} = $_;
    }
    my %Month = ();
    foreach (1..12) {
        my $Tmp = sprintf("%02d", $_);
        $Month{$_} = $Tmp;
    }
 
    push (@Params, {
            Frontend => 'Year',
            Name => 'Year',
            Multiple => 0,
            Size => 0,
            SelectedID => $Y,
            Data => {
                %Year,
            },
        },
    );
    push (@Params, {
            Frontend => 'Month',
            Name => 'Month',
            Multiple => 0,
            Size => 0,
            SelectedID => $M,
            Data => {
                %Month,
            },
        },
    );
    push (@Params, {
            Frontend => 'Graph Size',
            Name => 'GraphSize',
            Multiple => 0,
            Size => 0,
            SelectedID => '550x350',
            Data => {
                '550x350' => ' 550x350',
                '800x600' => ' 800x600',
                '1200x800' => '1200x800',
            },
        },
    );
    return @Params;
}
# --
sub Run {
    my $Self = shift;
    my %Param = @_;
    my $Title = "$Param{Year}-$Param{Month}";
    my $Year = $Param{Year};
    my $Month = $Param{Month};
    my $Day = Days_in_Month($Year,$Month);

    my %States = $Self->_GetHistoryTypes();
    my @PossibleStates;
    foreach (sort {$States{$a} cmp $States{$b}} keys %States) {
        $States{$_} =~ s/^(.{18}).*$/$1\.\.\./;
        push (@PossibleStates, $States{$_});
    }
    # build x_lable
    my $DayCounter = 0;
    my @Data;
    my @Days = ();
    my %StateDate = ();
    while ($Day >= $DayCounter+1) {
      $DayCounter++;
      my $Dow = Day_of_Week($Year, $Month, $DayCounter);
      $Dow = Day_of_Week_Abbreviation($Dow);
      my $Text = $DayCounter;
      $Text = "$Dow $DayCounter";
      push (@Days, $Text);
      my @Row = ();
      foreach (sort {$States{$a} cmp $States{$b}} keys %States) {
        my $Count = $Self->_GetDBDataPerDay(Year => $Year, Month=> $Month, Day => $DayCounter, StateID => $_);
        push (@Row,  $Count);
#        $StateDate{}->$States{$_}} = $StateDate{$States{$_}}+$Count;
          $StateDate{$Text}->{$_} = ($StateDate{$Text}->{$_} || 0) + $Count;
      }
    }
    foreach my $StateID (sort {$States{$a} cmp $States{$b}} keys %States) {
        my @Row = ($States{$StateID});
        foreach my $Day (@Days) {
            my %Hash = %{$StateDate{$Day}};
            push (@Row, $Hash{$StateID});
        }
        push (@Data, \@Row);
    }
    return ([$Title],['Days',@Days], @Data);
#    return ([$Title],[@PossibleStates], [4,1,2,8], [4,1,2,6], [24,11,7,2], [1,23,4,6]);
}
# --
sub _GetHistoryTypes {
    my $Self = shift;
    my %Param = @_;
    my %Stats;
    my $SQL = "SELECT id, name FROM ticket_history_type ".
{'fraction_non_alphanumeric': 0.19402628434886499, 'fraction_numerical': 0.02867383512544803, 'mean_word_length': 1.9238560950052392, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2995012', 'n_tokens_mistral': 3122, 'n_tokens_neox': 2892, 'n_words': 702}