From affdad496d3c94dcc781d91abaccf74672ea06af Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 7 Jul 2023 20:00:59 +0200 Subject: [PATCH] fixes --- p.pl | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/p.pl b/p.pl index 0a85b1e..7693e59 100755 --- a/p.pl +++ b/p.pl @@ -6,6 +6,8 @@ use Data::Dump qw(dump); my $filename = 'Intervali_Openface_novi_rad_Boris_export.txt'; +my $debug = $ENV{DEBUG} || 0; + sub col2nr { my @c = @_; my $i = 0; @@ -34,17 +36,22 @@ while(<$fh>) { chomp; next if m/^\s*$/; # FIXME corrput data my @v = split(/\t/, $_); - warn "#[ $_ ]\n", dump( \@v ); + warn "#[ $_ ]\n" if $debug; if ( ! $last_id || $last_id ne $v[0] ) { $file2 = glob 'originals_2023-07-07/' . $v[0] . '*.csv'; next unless $file2; # FIXME - warn "# file2 $file2 [$v[0]]"; + if ( ! -e $file2 ) { + warn "ERROR: $file2 doesn't exist, SKIPPING"; + next; + } + + warn "# file2 $file2 [$v[0]]" if $debug; open($fh2, '<', $file2); $last_id = $v[0]; -warn "---0000 v=",dump( \@v ), " FROM >>>$_<<<\n"; + @h2 = (); } sub col_v { @@ -53,33 +60,33 @@ warn "---0000 v=",dump( \@v ), " FROM >>>$_<<<\n"; die "can't find $name" unless defined $i; my $v = $v[$i]; die "can't find $i : $name in ",dump( \@v ) unless defined $v; - warn "## col_v $name -> $i -> $v",dump( \@v ); + warn "## col_v $name -> $i -> $v",dump( \@v ) if $debug > 1; return $v; } #my $start = $v[ $col2nr->{'Start (s)'} ]; #my $stop = $v[ $col2nr->{'Stop (s)'} ]; - my $start = col_v 'Start (s)'; - my $stop = col_v 'Stop (s)'; + #my $start = col_v 'Start (s)'; + #my $stop = col_v 'Stop (s)'; my $start = $v[10]; my $stop = $v[11]; - warn "# start: $start - stop: $stop\n"; + warn "# start: $start - stop: $stop\n" if $debug; my @sum; my $count = 0; while(<$fh2>) { chomp; s/\r+$//; - warn "## fh2 [ $_ ]\n"; + warn "## fh2 [ $_ ]\n" if $debug; #my @v2 = map { s/^\s+//; $_ } split(/\t/,$_); - my @v2 = map { s/^\s+//; $_ } split(/,\s+/,$_); + my @v2 = map { s/^\s+//; $_ } split(/[;,]\s*/,$_); if ( ! @h2 ) { @h2 = @v2; $h2nr = col2nr @h2; $tell2 = tell($fh2); - warn "# h2nr ",dump( $h2nr ); + warn "# h2nr ",dump( $h2nr ) if $debug; next; } @@ -98,9 +105,16 @@ warn "---0000 v=",dump( \@v ), " FROM >>>$_<<<\n"; #my $timestamp = col_v2 'timestamp'; my $timestamp = $v2[2]; - $timestamp /= 1000 if $timestamp =~ m/^\d+$/; # FIXME fix corrputed input data + #$timestamp /= 1000 if $timestamp =~ m/^\d+$/; # FIXME fix corrputed input data #warn "XXX filter $start - $stop from ",dump( $timestamp ); #$h2nr, \@v2 ); + # Argument "1.324.400" isn't numeric + $timestamp =~ s/^(\d+)\.(\d\d\d)\.(\d\d\d)$/$1$2.$3/; + + if ( $timestamp !~ m/^\d+(\.\d+)$/ ) { + warn "timestamp [$timestamp] from $file2 not numeric [$_]"; + } + if ( $timestamp < $start ) { #warn "## $start > @v2"; } elsif ( $timestamp < $stop ) { @@ -112,7 +126,7 @@ warn "---0000 v=",dump( \@v ), " FROM >>>$_<<<\n"; $count++; #warn "XXX $count sum $h2nr->{'AU01_r'} .. $h2nr->{'AU45_c'} = ",dump( \@sum ); } else { - warn "# seek $tell2"; + warn "# seek $tell2" if $debug; seek $fh2, $tell2, 0; die "count is 0" if $count == 0; @@ -121,13 +135,13 @@ warn "---0000 v=",dump( \@v ), " FROM >>>$_<<<\n"; my @add_cols; push @add_cols, map { $sum[$_] / $count } ( $h2nr->{'AU01_r'} .. $h2nr->{'AU45_r'} ); push @add_cols, map { $sum[$_] } ( $h2nr->{'AU01_c'} .. $h2nr->{'AU45_c'} ); - warn "# add_cols = ",dump( \@add_cols ); + warn "# add_cols = ",dump( \@add_cols ) if $debug; print join("\t", @v, @add_cols ), "\n"; @sum = (); $count = 0; - warn "# last"; + warn "# last" if $debug; last; } } -- 2.20.1