<commit_before>package App::Netdisco::Web::Plugin::Report::ApClients;

use Dancer ':syntax';
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;

use App::Netdisco::Web::Plugin;

register_report(
    {   category     => 'Wireless',
        tag          => 'apclients',
        label        => 'Access Point Client Count',
        provides_csv => 1,
    }
);

get '/ajax/content/report/apclients' => require_login sub {
    my @results = schema('netdisco')->resultset('Device')->search(
        { 'nodes.time_last' => { '>=', \'me.last_macsuck' } },
        {   result_class => 'DBIx::Class::ResultClass::HashRefInflator',
            select       => [ 'ip', 'dns', 'name', 'model', 'location' ],
            join       => { 'ports' => { 'wireless' => 'nodes' } },
            '+columns' => [
                { 'port'        => 'ports.port' },
                { 'description' => 'ports.name' },
                { 'mac_count'   => { count => 'nodes.mac' } },
            ],
            group_by => [
                'me.ip',       'me.dns',     'me.name',     'me.model',
                'me.location', 'ports.port', 'ports.descr', 'ports.name'
            ],
            order_by => { -desc => [qw/count/] },
        }
    )->all;

    return unless scalar @results;

    if ( request->is_ajax ) {
        template 'ajax/report/portmultinodes.tt', { results => \@results, },
            { layout => undef };
    }
    else {
        header( 'Content-Type' => 'text/comma-separated-values' );
        template 'ajax/report/portmultinodes_csv.tt',
            { results => \@results, },
            { layout  => undef };
    }
};

1;<commit_msg>DataTables for access point client count report<commit_after>package App::Netdisco::Web::Plugin::Report::ApClients;

use Dancer ':syntax';
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;

use App::Netdisco::Web::Plugin;

register_report(
    {   category     => 'Wireless',
        tag          => 'apclients',
        label        => 'Access Point Client Count',
        provides_csv => 1,
    }
);

get '/ajax/content/report/apclients' => require_login sub {
    my @results = schema('netdisco')->resultset('Device')->search(
        { 'nodes.time_last' => { '>=', \'me.last_macsuck' } },
        {   select => [ 'ip', 'dns', 'name', 'model', 'location' ],
            join       => { 'ports' => { 'wireless' => 'nodes' } },
            '+columns' => [
                { 'port'        => 'ports.port' },
                { 'description' => 'ports.name' },
                { 'mac_count'   => { count => 'nodes.mac' } },
            ],
            group_by => [
                'me.ip',       'me.dns',     'me.name',     'me.model',
                'me.location', 'ports.port', 'ports.descr', 'ports.name'
            ],
            order_by => { -desc => [qw/count/] },
        }
    )->hri->all;

    return unless scalar @results;

    if ( request->is_ajax ) {
        my $json = to_json( \@results );
        template 'ajax/report/portmultinodes.tt', { results => $json },
            { layout => undef };
    }
    else {
        header( 'Content-Type' => 'text/comma-separated-values' );
        template 'ajax/report/portmultinodes_csv.tt',
            { results => \@results },
            { layout  => undef };
    }
};

1;
{'fraction_non_alphanumeric': 0.18619436875567666, 'fraction_numerical': 0.0012110202845897668, 'mean_word_length': 1.8906386701662292, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5932945', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1028, 'n_words': 183}