new files
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 7 Jul 2023 16:12:37 +0000 (18:12 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 7 Jul 2023 16:12:37 +0000 (18:12 +0200)
p.pl

diff --git a/p.pl b/p.pl
index d61c5e4..b296ec5 100755 (executable)
--- a/p.pl
+++ b/p.pl
@@ -11,7 +11,7 @@ sub col2nr {
        my $i = 0;
        my $out;
        $out->{$_} = $i++ foreach @c;
-       warn "# col2nr ", dump( $out );
+       #warn "## col2nr ", dump( $out );
        return $out;
 }
 
@@ -32,17 +32,19 @@ my $tell2;
 
 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 {
@@ -59,14 +61,16 @@ while(<$fh>) {
 
        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;
@@ -89,24 +93,35 @@ while(<$fh>) {
                #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;
                }
        }
 }