<commit_before>#!/usr/bin/perl
use strict;
use warnings;
use Calendar::Simple;
use CGI::Carp qw(fatalsToBrowser);
use CGI;
use Config::File;
use HTML::Template;
use Cache::FileCache;
use lib 'lib';
use IrcLog qw(get_dbh gmt_today);

# test_calendar();
go();

sub go {
    my $q = new CGI;
    my $channel = $q->url_param('channel');
    print "Content-Type: text/html; charset=utf-8\n\n";

    my $cache_name = $channel . '|' . gmt_today();
    my $cache      = new Cache::FileCache({ namespace => 'irclog' });
    my $data       = $cache->get($cache_name);

    if (! defined $data) {
        $data = get_channel_index($channel);
        $cache->set($data, '2 hours');
    }

    print $data;
}

sub test_calendar {
    my $channel  = '#parrotsketch';
    my $base_url = '/irclog/';
    my $dates    = [qw( 2009-09-28 2009-09-30
                        2009-10-01 2009-10-02 2009-10-05 2009-10-12 )];

    print calendar_for_channel($channel, $dates, $base_url);
}

sub get_channel_index {
    my $channel  = shift;
    my $conf     = Config::File::read_config_file('cgi.conf');
    my $base_url = $conf->{BASE_URL} || q{/};

    my $t = HTML::Template->new(
            filename            => 'template/channel-index.tmpl',
            die_on_bad_params   => 0,
    );

    # we are evil and create a calendar entry for month between the first
    # and last date
    my $dbh       = get_dbh();
    my $get_dates = 'SELECT DISTINCT day FROM irclog WHERE channel = ? ORDER BY day';
    my $dates     = $dbh->selectcol_arrayref($get_dates, undef, $channel);

    $t->param(CHANNEL  => $channel);
    $t->param(BASE_URL => $base_url);
    $t->param(CALENDAR => calendar_for_channel($channel, $dates, $base_url));
    return $t->output;
}

sub calendar_for_channel {<commit_msg>[irclog] channel names begin with '#'<commit_after>#!/usr/bin/perl
use strict;
use warnings;
use Calendar::Simple;
use CGI::Carp qw(fatalsToBrowser);
use CGI;
use Config::File;
use HTML::Template;
use Cache::FileCache;
use lib 'lib';
use IrcLog qw(get_dbh gmt_today);

# test_calendar();
go();

sub go {
    my $q = new CGI;
    my $channel = $q->url_param('channel');
    print "Content-Type: text/html; charset=utf-8\n\n";

    my $cache_name = $channel . '|' . gmt_today();
    my $cache      = new Cache::FileCache({ namespace => 'irclog' });
    my $data       = $cache->get($cache_name);

    if (! defined $data) {
        $data = get_channel_index($channel);
        $cache->set($data, '2 hours');
    }

    print $data;
}

sub test_calendar {
    my $channel  = '#parrotsketch';
    my $base_url = '/irclog/';
    my $dates    = [qw( 2009-09-28 2009-09-30
                        2009-10-01 2009-10-02 2009-10-05 2009-10-12 )];

    print calendar_for_channel($channel, $dates, $base_url);
}

sub get_channel_index {
    my $channel  = shift;
    my $conf     = Config::File::read_config_file('cgi.conf');
    my $base_url = $conf->{BASE_URL} || q{/};

    my $t = HTML::Template->new(
            filename            => 'template/channel-index.tmpl',
            die_on_bad_params   => 0,
    );

    # we are evil and create a calendar entry for month between the first
    # and last date
    my $dbh       = get_dbh();
    my $get_dates = 'SELECT DISTINCT day FROM irclog WHERE channel = ? ORDER BY day';
    my $dates     = $dbh->selectcol_arrayref($get_dates, undef, '#' . $channel);

    $t->param(CHANNEL  => $channel);
    $t->param(BASE_URL => $base_url);
    $t->param(CALENDAR => calendar_for_channel($channel, $dates, $base_url));
    return $t->output;
}

sub calendar_for_channel {
{'fraction_non_alphanumeric': 0.1588498045784478, 'fraction_numerical': 0.02847571189279732, 'mean_word_length': 2.848549946294307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '469902', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1252, 'n_words': 307}