<commit_before>#!/usr/bin/perl -w
# Parse CSV and simply push each line into a database for future processing and presentation.

use strict;
use warnings;
use DBI;
use POSIX qw(strftime);
use Time::Local;
# For execution performance measurements:
use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);

my $configuration = 'configuration.pl';
my $localconfiguration = 'configuration.local.pl';

if (-f $configuration) { require "$configuration"; }
else { print "ERROR: Configuration file not found. Quitting.\n"; exit 1; }
if (-f $localconfiguration) { require "$localconfiguration"; }
else { print "INFO: Local configuration file not found. Trying anyway.\n"; }
# import the settings from config into this (main) namespace/package:
our ($do_period_calc, $dirpath, $database_name, $database_user, $database_password, $database_host, $database_table, $perflogfilename);

# Database handle object:
my $dbh;
my $sth;

my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
# my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
# hash index for looking up month number by month name:
my %imonths;
@imonths{@months} = (1..($#months+1));
# print "test $imonths{\"Jan\"} $imonths{\"Dec\"} \n"; exit;

my $curryear = strftime "%Y", localtime;
my $currmonth = strftime "%m", localtime;
my $currday = strftime "%d", localtime;
my $currdate = $curryear.$currmonth.$currday;
my $prevyear = strftime "%Y", localtime(time() - 86400);
my $prevmonth = strftime "%m", localtime(time() - 86400);
my $prevday = strftime "%d", localtime(time() - 86400);
my $prevdate = $prevyear.$prevmonth.$prevday;
# my $currtime = strftime "%H:%M:%S", localtime;<commit_msg>Experimenting with setting timezone. However, it is not behaving as I expected. If local time is CEST, enforcing TZ=CEST gives correct time -2 hours, probably because CEST is +0200 (ISO offset). On the other hand enforcing TZ=CET gives the correct time. Other TZs like UTC/GMT works as expected. It seems one have to be careful not to enforce the same timezone as the local time or end up with strange results. (if TZ = local TZ then break)<commit_after>#!/usr/bin/perl -w
# Parse CSV and simply push each line into a database for future processing and presentation.

use strict;
use warnings;
use DBI;
use POSIX qw(strftime tzset);
# For "reversed" date conversion, from string to timestamp, with timelocal() and timegm():
use Time::Local;
# For execution performance measurements:
use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);

my $configuration = 'configuration.pl';
my $localconfiguration = 'configuration.local.pl';

if (-f $configuration) { require "$configuration"; }
else { print "ERROR: Configuration file not found. Quitting.\n"; exit 1; }
if (-f $localconfiguration) { require "$localconfiguration"; }
else { print "INFO: Local configuration file not found. Trying anyway.\n"; }
# import the settings from config into this (main) namespace/package:
our ($do_period_calc, $dirpath, $database_name, $database_user, $database_password, $database_host, $database_table, $perflogfilename);

# Database handle object:
my $dbh;
my $sth;

my $systemtimezone = 'CEST';
my $localtimezone = strftime "%Z", localtime;
my $localtzoffset = strftime "%z", localtime;

my $was = scalar localtime;
print "It was      $was (TZ: $localtimezone offset: $localtzoffset) ($ENV{TZ})\n";
$ENV{TZ} = 'CEST'; #$systemtimezone;
# foreach my $key (sort keys(%ENV)) {
# 	print "$key = $ENV{$key}\n";
# }
$was = scalar localtime;
print "It is still $was  ($ENV{TZ})\n";
tzset;
my $now = localtime;
print "It is now   $now\n";


my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
# my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
# hash index for looking up month number by month name:
my %imonths;
@imonths{@months} = (1..($#months+1));
# print "test $imonths{\"Jan\"} $imonths{\"Dec\"} \n"; exit;

my $curryear = strftime "%Y", localtime;
my $currmonth = strftime "%m", localtime;
my $currday = strftime "%d", localtime;
my $currdate = $curryear.$currmonth.$currday;
my $prevyear = strftime "%Y", localtime(time() - 86400);
my $prevmonth = strftime "%m", localtime(time() - 86400);
my $prevday = strftime "%d", localtime(time() - 86400);
my $prevdate = $prevyear.$prevmonth.$prevday;
# my $currtime = strftime "%H:%M:%S", localtime;
{'fraction_non_alphanumeric': 0.14096301465457084, 'fraction_numerical': 0.009537101651546871, 'mean_word_length': 5.142857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4766314', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1381, 'n_words': 519}