#! usr/bin/perl -w
use strict;
use File::Copy;
my $summary_excel_file = "all_weeks_classified_per_hour.csv";
open my $OUTFILE, q{>}, $summary_excel_file;
print $OUTFILE "hour_position;before H-24;";
my @list = (1..24);
@list = reverse @list;
my $i;
foreach $i(@list){
my $j = $i - 1;
print $OUTFILE "between H-$i and H-$j;";
}
@list = (1..24);
foreach $i(@list){
my $j = $i - 1;
print $OUTFILE "between H+$j and H+$i;";
}
print $OUTFILE "\n";
print $OUTFILE "legend;";
my @Elements;
my @TXT = glob("*.txt");
print STDOUT "@TXT\n";
foreach my $txt (@TXT){
open my $TXT, q{<}, $txt or die;
while(<$TXT>){
my ($reg, $value, $anticipation) = (split /;/)[0,1,5];
my $relative_position = -$anticipation;
if ($relative_position <= -1440){
$Elements[0] = $value;
}
foreach my $k (-24..23){
### ] inf_limit ____________ pos in time ______________ sup_limit____________> time
my $inf_limit = 60*$k;
my $sup_limit = 60*($k+1);
my $l= $k + 25;
if (($relative_position > $inf_limit) && ($relative_position <= $sup_limit)){
$Elements[$l] = $anticipation;
}
}
if ($relative_position > 1440 ){
$Elements[49] = $value;
}
}
}
my $nb = @Elements;
foreach my $i(0..$nb){
if (defined $Elements[$i]){
$Elements[$i] =~ s/\s+//;
print $OUTFILE "$Elements[$i];";
}
else{
print $OUTFILE ";";
}
}
close $OUTFILE;
####
EGLLA22;0.1;380;01;22/10/2006;100
####
EGLLA22;0.1;380;01;22/10/2006;90
####
EGLLA22;0.1;380;01;22/10/2006;110