<commit_before>package Tapper::Reports::Web::Controller::Tapper::Overview;

use parent 'Tapper::Reports::Web::Controller::Base';
use DateTime;

use common::sense;
## no critic (RequireUseStrict)

sub auto :Private
{
        my ( $self, $c ) = @_;
        $c->forward('/tapper/overview/prepare_navi');
}


# Filter suite list so that only recently used suites are given.
# 
# @param suite result set - unfiltered suites
# @param int/string       - duration
#
# @return suite result set - filtered suites
#
sub recently_used_suites
{
        my ($self, $suite_rs, $duration) = @_;
        my $timeframe;
        if ($duration) {
                return $suite_rs if lc($duration) eq 'all';
                $timeframe = DateTime->now->subtract(weeks => $duration);
        } else {
                $timeframe = DateTime->now->subtract(weeks => 12);
        }
        $suite_rs  = $suite_rs->search({'reports.created_at' => {'>=' => $timeframe}});
        return $suite_rs;
}


sub index :Path :Args()
{
        my ( $self, $c, $type, $options ) = @_;
        my $overviews : Stash;
        given ($type){
                when ('suite') {
                        my %search_options = ();
                        %search_options = ( prefetch => ['reports'] ) unless lc($options) eq "all";
                        my $suite_rs = $c->model('ReportsDB')->resultset('Suite')->search({}, { %search_options } );
                        $suite_rs = $self->recently_used_suites($suite_rs, $options) unless lc($options) eq "all";
                        $overviews = {};
                        while ( my $suite = $suite_rs->next ) {
                                $overviews->{$suite->name} = '/tapper/reports/suite/'.$suite->id;
                        }
                        $c->stash->{title} = "Tapper report suites";
                }
                when ('host')  {
                        my $reports = $c->model('ReportsDB')->resultset('Report')->search({},
                                                                                          { columns => [ qw/machine_name/ ],
                                                                                            distinct => 1});
                        $overviews = { map{$_->machine_name, '/tapper/reports/host/'.$_->machine_name} $reports->all };
                        $c->stash->{title} = "Tapper report hosts";
                }
        }
}

sub prepare_navi : Private
{
        my ( $self, $c ) = @_;

        my $navi : Stash = [{
                            title => 'Overview of',
                            subnavi => [
                                        {
                                         title => 'Suites',
                                         href  => "/tapper/overview/suite",
                                        },
                                        {
                                         title => 'Hosts',
                                         href  => "/tapper/overview/host",
                                        },
                                       ],
                            
                           },<commit_msg>suite overview urls use names<commit_after>package Tapper::Reports::Web::Controller::Tapper::Overview;

use parent 'Tapper::Reports::Web::Controller::Base';
use DateTime;

use common::sense;
## no critic (RequireUseStrict)

sub auto :Private
{
        my ( $self, $c ) = @_;
        $c->forward('/tapper/overview/prepare_navi');
}


# Filter suite list so that only recently used suites are given.
# 
# @param suite result set - unfiltered suites
# @param int/string       - duration
#
# @return suite result set - filtered suites
#
sub recently_used_suites
{
        my ($self, $suite_rs, $duration) = @_;
        my $timeframe;
        if ($duration) {
                return $suite_rs if lc($duration) eq 'all';
                $timeframe = DateTime->now->subtract(weeks => $duration);
        } else {
                $timeframe = DateTime->now->subtract(weeks => 12);
        }
        $suite_rs  = $suite_rs->search({'reports.created_at' => {'>=' => $timeframe}});
        return $suite_rs;
}


sub index :Path :Args()
{
        my ( $self, $c, $type, $options ) = @_;
        my $overviews : Stash;
        given ($type){
                when ('suite') {
                        my %search_options = ();
                        %search_options = ( prefetch => ['reports'] ) unless lc($options) eq "all";
                        my $suite_rs = $c->model('ReportsDB')->resultset('Suite')->search({}, { %search_options } );
                        $suite_rs = $self->recently_used_suites($suite_rs, $options) unless lc($options) eq "all";
                        $overviews = {};
                        while ( my $suite = $suite_rs->next ) {
                                $overviews->{$suite->name} = '/tapper/reports/suite/'.($suite->name =~ /[^\w\d_.-]/ ? $suite->id : $suite->name);
                        }
                        $c->stash->{title} = "Tapper report suites";
                }
                when ('host')  {
                        my $reports = $c->model('ReportsDB')->resultset('Report')->search({},
                                                                                          { columns => [ qw/machine_name/ ],
                                                                                            distinct => 1});
                        $overviews = { map{$_->machine_name, '/tapper/reports/host/'.$_->machine_name} $reports->all };
                        $c->stash->{title} = "Tapper report hosts";
                }
        }
}

sub prepare_navi : Private
{
        my ( $self, $c ) = @_;

        my $navi : Stash = [{
                            title => 'Overview of',
                            subnavi => [
                                        {
                                         title => 'Suites',
                                         href  => "/tapper/overview/suite",
                                        },
                                        {
                                         title => 'Hosts',
                                         href  => "/tapper/overview/host",
                                        },
                                       ],
                            
                           },
{'fraction_non_alphanumeric': 0.13573450770682605, 'fraction_numerical': 0.0009436929852154766, 'mean_word_length': 1.0924646265218823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623533', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1518, 'n_words': 323}