my $i = 0;
my $out;
$out->{$_} = $i++ foreach @c;
- warn "# col2nr ", dump( $out );
+ #warn "## col2nr ", dump( $out );
return $out;
}
while(<$fh>) {
chomp;
+ next if m/^\s*$/; # FIXME corrput data
my @v = split(/\t/, $_);
- #warn "#[ $_ ]\n";
+ warn "#[ $_ ]\n";
if ( ! $last_id || $last_id ne $v[0] ) {
- $file2 = glob $v[0] . '*.txt';
+ $file2 = glob 'originals_2023-07-07/' . $v[0] . '*.csv';
next unless $file2; # FIXME
warn "# file2 $file2 [$v[0]]";
open($fh2, '<', $file2);
$last_id = $v[0];
+warn "---0000 v=",dump( \@v ), " FROM >>>$_<<<\n";
}
sub col_v {
my $start = col_v 'Start (s)';
my $stop = col_v 'Stop (s)';
+ warn "# start: $start - stop: $stop\n";
my @sum;
my $count = 0;
while(<$fh2>) {
chomp;
- warn "##[ $_ ]\n";
- my @v2 = map { s/^\s+//; $_ } split(/\t/,$_);
+ warn "## fh2 [ $_ ]\n";
+ #my @v2 = map { s/^\s+//; $_ } split(/\t/,$_);
+ my @v2 = map { s/^\s+//; $_ } split(/,\s+/,$_);
if ( ! @h2 ) {
@h2 = @v2;
$h2nr = col2nr @h2;
#my $timestamp = $v2[ $h2nr->{'timestamp'} ] || die;
#my $timestamp = col_v2 'timestamp';
my $timestamp = $v2[2];
-warn "XXX ",dump( $timestamp ); #$h2nr, \@v2 );
+
+ $timestamp /= 1000 if $timestamp =~ m/^\d+$/; # FIXME fix corrputed input data
+ #warn "XXX filter $start - $stop from ",dump( $timestamp ); #$h2nr, \@v2 );
if ( $timestamp < $start ) {
- warn "# $start > @v2";
+ #warn "## $start > @v2";
} elsif ( $timestamp < $stop ) {
$tell2 = tell($fh2);
foreach my $n ( $h2nr->{'AU01_r'} .. $h2nr->{'AU45_c'} ) {
- $sum[$n] += $v[$n];
+ $sum[$n] += $v2[$n];
+ #warn "sum $n $sum[$n] $v2[$n]\n";
}
$count++;
+ warn "XXX $count sum = ",dump( \@sum );
} else {
warn "# seek $tell2";
seek $fh2, $tell2, 0;
+ die "count is 0" if $count == 0;
+
+ warn "XXX count=$count XXX ", $h2nr->{'AU01_r'},' - ', $h2nr->{'AU45_r'} , " YYY ", $h2nr->{'AU01_c'}, ' - ', $h2nr->{'AU45_c'}, ' sum=', dump( \@sum );
+warn "--- v=",dump( \@v );
print join("\t", @v,
map { $sum[$_] / $count } ( $h2nr->{'AU01_r'} .. $h2nr->{'AU45_r'} ),
map { $sum[$_] } ( $h2nr->{'AU01_c'} .. $h2nr->{'AU45_c'} ),
- );
+ ), "\n";
+
+ @sum = ();
+ $count = 0;
}
}
}