<commit_before>package LogBot::Web::Stats;
use local::lib;
use v5.10;
use strict;
use warnings;

use DateTime ();
use JSON::XS qw( decode_json );
use LogBot::Database qw( dbh );
use LogBot::Util qw( commify file_for pretty_size slurp time_to_datetimestr );
use LogBot::Web::Util qw( irc_host );
use Time::Duration qw( ago );

sub render {
    my ($c, $params) = @_;
    my $config = $c->stash('config');

    if (my $error = $params->{error}) {
        $c->stash(
            channel => '',
            error   => $error,
        );
    }

    $c->stash(
        is_stats => 1,
        url      => irc_host($config, channel => $c->stash('channel'), url => 1),
        now      => time_to_datetimestr(DateTime->now()->epoch),
    );

    return $c->render('stats');
}

sub event_time_to_str {
    my ($time) = @_;
    return ('no events', '-') unless $time;
    return (time_to_datetimestr(int($time)), ago(time() - $time));
}

sub meta {
    my ($c, $channel) = @_;
    my $config = $c->stash('config');

    my $dbh = dbh($config, cached => 1);

    my ($last_time, $last_ago) = event_time_to_str(
        $dbh->selectrow_array("SELECT time FROM logs WHERE channel = ? ORDER BY time DESC LIMIT 1", undef, $channel));
    my $event_count = commify($dbh->selectrow_array("SELECT COUNT(*) FROM logs WHERE channel = ?", undef, $channel));

    my ($first_time, $first_ago, $event_size, $activity);
    my $meta_file = file_for($config, 'meta', $channel, 'meta');
    if (-e $meta_file) {
        my $meta = decode_json(slurp($meta_file));

        ($first_time, $first_ago) = event_time_to_str($meta->{first_time});
        $event_size = pretty_size($meta->{event_size});

        $activity = $meta->{activity_days}
            ? $meta->{activity_count} / $meta->{activity_days}<commit_msg>perltidy<commit_after>package LogBot::Web::Stats;
use local::lib;
use v5.10;
use strict;
use warnings;

use DateTime ();
use JSON::XS qw( decode_json );
use LogBot::Database qw( dbh );
use LogBot::Util qw( commify file_for pretty_size slurp time_to_datetimestr );
use LogBot::Web::Util qw( irc_host );
use Time::Duration qw( ago );

sub render {
    my ($c, $params) = @_;
    my $config = $c->stash('config');

    if (my $error = $params->{error}) {
        $c->stash(
            channel => '',
            error   => $error,
        );
    }

    $c->stash(
        is_stats => 1,
        url      => irc_host($config, channel => $c->stash('channel'), url => 1),
        now      => time_to_datetimestr(DateTime->now()->epoch),
    );

    return $c->render('stats');
}

sub event_time_to_str {
    my ($time) = @_;
    return ('no events', '-') unless $time;
    return (time_to_datetimestr(int($time)), ago(time() - $time));
}

sub meta {
    my ($c, $channel) = @_;
    my $config = $c->stash('config');

    my $dbh = dbh($config, cached => 1);

    my ($last_time, $last_ago) = event_time_to_str(
        $dbh->selectrow_array("SELECT time FROM logs WHERE channel = ? ORDER BY time DESC LIMIT 1", undef, $channel));
    my $event_count = commify($dbh->selectrow_array("SELECT COUNT(*) FROM logs WHERE channel = ?", undef, $channel));

    my ($first_time, $first_ago, $event_size, $activity);
    my $meta_file = file_for($config, 'meta', $channel, 'meta');
    if (-e $meta_file) {
        my $meta = decode_json(slurp($meta_file));

        ($first_time, $first_ago) = event_time_to_str($meta->{first_time});
        $event_size = pretty_size($meta->{event_size});

        $activity =
              $meta->{activity_days}
            ? $meta->{activity_count} / $meta->{activity_days}
{'fraction_non_alphanumeric': 0.17862126709461346, 'fraction_numerical': 0.003907340217694669, 'mean_word_length': 3.1242807825086305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, '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': '6779119', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1251, 'n_words': 289}