check ascii line
This commit is contained in:
310
LoadCSVData.pl
310
LoadCSVData.pl
@@ -448,61 +448,82 @@ elsif ( $filecsvname =~ m/^G301_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) {
|
||||
}
|
||||
|
||||
while ( my $line = <FILE> ) {
|
||||
my ( $first, $NodeData ) = split( /;/, $line, 2 );
|
||||
if ( defined $first and ( $first ne '' ) ) {
|
||||
$first =~ s/;+$//;
|
||||
if ( !defined $NodeData or ( $NodeData =~ m/^;+/ ) ) {
|
||||
my @info = ( split( /[\/,\.]/, $first ) );
|
||||
if ( defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) {
|
||||
$tool = uc $info[3];
|
||||
$tooltype = uc $info[2];
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
if ( $line =~ m/\A [[:ascii:]]* \Z/xms ) {
|
||||
my ( $first, $NodeData ) = split( /;/, $line, 2 );
|
||||
if ( defined $first and ( $first ne '' ) ) {
|
||||
$first =~ s/;+$//;
|
||||
if ( !defined $NodeData or ( $NodeData =~ m/^;+/ ) ) {
|
||||
my @info = ( split( /[\/,\.]/, $first ) );
|
||||
if ( defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) {
|
||||
$tool = uc $info[3];
|
||||
$tooltype = uc $info[2];
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
}
|
||||
elsif ( defined $info[2] && $info[2] =~ m/^LOC\d*$/i ) {
|
||||
$tool = uc $info[2];
|
||||
$tooltype = 'LOC';
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
}
|
||||
elsif ( defined $info[3] && $info[3] =~ m/^GD\d*$/i ) {
|
||||
$tool = uc $info[3];
|
||||
$tooltype = 'GD';
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
}
|
||||
}
|
||||
elsif ( defined $info[2] && $info[2] =~ m/^LOC\d*$/i ) {
|
||||
$tool = uc $info[2];
|
||||
$tooltype = 'LOC';
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
}
|
||||
elsif ( defined $info[3] && $info[3] =~ m/^GD\d*$/i ) {
|
||||
$tool = uc $info[3];
|
||||
$tooltype = 'GD';
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$NodeData =~ s/\x0d{0,1}\x0a\Z//s;
|
||||
$NodeData =~ s/;+$//;
|
||||
else {
|
||||
$NodeData =~ s/\x0d{0,1}\x0a\Z//s;
|
||||
$NodeData =~ s/;+$//;
|
||||
|
||||
#$NodeData =~ s/\r\n\z//;
|
||||
if ( $unittype eq 'G201' and $G201_fcheck eq 0 ) {
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
$G201_fcheck = 1;
|
||||
}
|
||||
if ( $unittype eq 'D2W' and $D2W_fcheck eq 0 ) {
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
$D2W_fcheck = 1;
|
||||
}
|
||||
if ( $unittype eq 'G301' and $G301_fcheck eq 0 ) {
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
$G301_fcheck = 1;
|
||||
}
|
||||
#$NodeData =~ s/\r\n\z//;
|
||||
if ( $unittype eq 'G201' and $G201_fcheck eq 0 ) {
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
$G201_fcheck = 1;
|
||||
}
|
||||
if ( $unittype eq 'D2W' and $D2W_fcheck eq 0 ) {
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
$D2W_fcheck = 1;
|
||||
}
|
||||
if ( $unittype eq 'G301' and $G301_fcheck eq 0 ) {
|
||||
print getTimeStamp("log")
|
||||
. " - pid $$ >> Found $tooltype tool name: $tool\n";
|
||||
getNodesType();
|
||||
$G301_fcheck = 1;
|
||||
}
|
||||
|
||||
if ( $tooltype eq "MUX" or $tooltype eq "D2W" or $tooltype eq "G301" ) {
|
||||
if ( $tooltype eq "MUX"
|
||||
or $tooltype eq "D2W"
|
||||
or $tooltype eq "G301" )
|
||||
{
|
||||
|
||||
#$NodeData =~ s/Dis\./N\/A/g;
|
||||
@NewData = grep /\S/, split( /\||;/, $NodeData );
|
||||
if ( scalar(@NewData) != 0 ) {
|
||||
my $idx = 0;
|
||||
|
||||
$CSVData[ $idx++ ] =
|
||||
join( ';', splice( @NewData, 0, 2 ) );
|
||||
foreach my $ch (@channels) {
|
||||
$CSVData[ $idx++ ] =
|
||||
join( ';', splice( @NewData, 0, $ch ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ( $tooltype eq "MUSA" ) {
|
||||
|
||||
#$NodeData =~ s/Dis\./N\/A/g;
|
||||
my @tmpData = grep /\S/, split( /\||;/, $NodeData );
|
||||
my $tmpBatt = shift @tmpData;
|
||||
@NewData = ( $tmpBatt, $tmpData[0], @tmpData );
|
||||
|
||||
#$NodeData =~ s/Dis\./N\/A/g;
|
||||
@NewData = grep /\S/, split( /\||;/, $NodeData );
|
||||
if ( scalar(@NewData) != 0 ) {
|
||||
my $idx = 0;
|
||||
|
||||
$CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, 2 ) );
|
||||
@@ -510,120 +531,107 @@ while ( my $line = <FILE> ) {
|
||||
$CSVData[ $idx++ ] =
|
||||
join( ';', splice( @NewData, 0, $ch ) );
|
||||
}
|
||||
|
||||
#print Dumper \@CSVData;
|
||||
#print Dumper \@channels;
|
||||
#print Dumper \@din;
|
||||
|
||||
}
|
||||
}
|
||||
elsif ( $tooltype eq "MUSA" ) {
|
||||
elsif ( $tooltype eq "LOC" ) {
|
||||
my ( $Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2 ) =
|
||||
split( /;/, $NodeData );
|
||||
|
||||
#$NodeData =~ s/Dis\./N\/A/g;
|
||||
my @tmpData = grep /\S/, split( /\||;/, $NodeData );
|
||||
my $tmpBatt = shift @tmpData;
|
||||
@NewData = ( $tmpBatt, $tmpData[0], @tmpData );
|
||||
my $idx = 0;
|
||||
$CSVData[ $idx++ ] = $Vbat . ";" . $Tmod;
|
||||
|
||||
my $idx = 0;
|
||||
|
||||
$CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, 2 ) );
|
||||
foreach my $ch (@channels) {
|
||||
$CSVData[ $idx++ ] =
|
||||
join( ';', splice( @NewData, 0, $ch ) );
|
||||
}
|
||||
|
||||
#print Dumper \@CSVData;
|
||||
#print Dumper \@channels;
|
||||
#print Dumper \@din;
|
||||
|
||||
}
|
||||
elsif ( $tooltype eq "LOC" ) {
|
||||
my ( $Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2 ) =
|
||||
split( /;/, $NodeData );
|
||||
|
||||
my $idx = 0;
|
||||
$CSVData[ $idx++ ] = $Vbat . ";" . $Tmod;
|
||||
|
||||
my $used_din = 0;
|
||||
my $used_ain = 0;
|
||||
for my $i ( 0 .. $#din ) {
|
||||
if ( $din[$i] eq 1 ) {
|
||||
if ( $used_din eq 0 ) {
|
||||
$CSVData[ $idx++ ] = $Din1;
|
||||
$used_din = 1;
|
||||
my $used_din = 0;
|
||||
my $used_ain = 0;
|
||||
for my $i ( 0 .. $#din ) {
|
||||
if ( $din[$i] eq 1 ) {
|
||||
if ( $used_din eq 0 ) {
|
||||
$CSVData[ $idx++ ] = $Din1;
|
||||
$used_din = 1;
|
||||
}
|
||||
else {
|
||||
$CSVData[ $idx++ ] = $Din2;
|
||||
}
|
||||
}
|
||||
elsif ( $ain[$i] eq 1 ) {
|
||||
if ( $used_ain eq 0 ) {
|
||||
$CSVData[ $idx++ ] = $Ain1;
|
||||
$used_ain = 1;
|
||||
}
|
||||
else {
|
||||
$CSVData[ $idx++ ] = $Ain2;
|
||||
}
|
||||
}
|
||||
elsif ( $din[$i] eq 2 ) {
|
||||
$CSVData[ $idx++ ] = $Din1 . ";" . $Din2;
|
||||
}
|
||||
elsif ( $ain[$i] eq 2 ) {
|
||||
$CSVData[ $idx++ ] = $Ain1 . ";" . $Ain2;
|
||||
}
|
||||
else {
|
||||
$CSVData[ $idx++ ] = $Din2;
|
||||
$CSVData[ $idx++ ] = "N/A";
|
||||
}
|
||||
}
|
||||
elsif ( $ain[$i] eq 1 ) {
|
||||
if ( $used_ain eq 0 ) {
|
||||
$CSVData[ $idx++ ] = $Ain1;
|
||||
$used_ain = 1;
|
||||
}
|
||||
else {
|
||||
$CSVData[ $idx++ ] = $Ain2;
|
||||
}
|
||||
}
|
||||
elsif ( $din[$i] eq 2 ) {
|
||||
$CSVData[ $idx++ ] = $Din1 . ";" . $Din2;
|
||||
}
|
||||
elsif ( $ain[$i] eq 2 ) {
|
||||
$CSVData[ $idx++ ] = $Ain1 . ";" . $Ain2;
|
||||
}
|
||||
else {
|
||||
$CSVData[ $idx++ ] = "N/A";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
elsif ( $tooltype eq "GD" ) {
|
||||
my ( $div, $Vbat, $Tmod ) =
|
||||
split( /;/, $NodeData );
|
||||
$CSVData[0] = $Vbat . ";" . $Tmod;
|
||||
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
|
||||
my ( $h, $min, $sec ) = split( /:/, $t );
|
||||
$GDEventDate = $y . '-' . $m . '-' . $d;
|
||||
$CSVData[1] = "DT"
|
||||
. substr( $tool, 2, 4 ) . ';'
|
||||
. $h . ':'
|
||||
. ( $min - 1 ) . ';'
|
||||
. $h . ':'
|
||||
. ( $min + 1 );
|
||||
}
|
||||
else {
|
||||
@CSVData = split( /\|/, $NodeData );
|
||||
}
|
||||
|
||||
my $nodenum = 0;
|
||||
foreach (@CSVData) {
|
||||
$sql[ ( $outcount % $maxsqllines ) ] = "";
|
||||
my (@data) = grep { /\S/ } split( /\;/, $_ );
|
||||
if ( $nodenum eq 0 ) {
|
||||
$toolbatt = $data[0];
|
||||
$tooltemp = $data[1];
|
||||
elsif ( $tooltype eq "GD" ) {
|
||||
my ( $div, $Vbat, $Tmod ) =
|
||||
split( /;/, $NodeData );
|
||||
$CSVData[0] = $Vbat . ";" . $Tmod;
|
||||
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
|
||||
my ( $h, $min, $sec ) = split( /:/, $t );
|
||||
$GDEventDate = $y . '-' . $m . '-' . $d;
|
||||
$CSVData[1] = "DT"
|
||||
. substr( $tool, 2, 4 ) . ';'
|
||||
. $h . ':'
|
||||
. ( $min - 1 ) . ';'
|
||||
. $h . ':'
|
||||
. ( $min + 1 );
|
||||
}
|
||||
else {
|
||||
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
|
||||
if ( length($y) != 4 ) { # G201/G301 con la data invertita
|
||||
my $w = $y;
|
||||
$y = $d;
|
||||
$m = sprintf( '%02d', $m );
|
||||
$d = sprintf( '%02d', $w );
|
||||
}
|
||||
foreach (@data) {
|
||||
if ( $sql[ ( $outcount % $maxsqllines ) ] eq "" ) {
|
||||
$sql[ ( $outcount % $maxsqllines ) ] =
|
||||
"('$unit','$tool','$nodenum','$y-$m-$d','$t','$toolbatt','$tooltemp'";
|
||||
}
|
||||
$sql[ ( $outcount % $maxsqllines ) ] .= ",'" . $_ . "'";
|
||||
}
|
||||
my $InsCompl = ",NULL" x ( 15 - $#data );
|
||||
$sql[ ( $outcount % $maxsqllines ) ] .= $InsCompl . ")";
|
||||
if ( ++$outcount % $maxsqllines eq 0 ) {
|
||||
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ";\n";
|
||||
writeOutSql($tool);
|
||||
@CSVData = split( /\|/, $NodeData );
|
||||
}
|
||||
|
||||
my $nodenum = 0;
|
||||
foreach (@CSVData) {
|
||||
$sql[ ( $outcount % $maxsqllines ) ] = "";
|
||||
my (@data) = grep { /\S/ } split( /\;/, $_ );
|
||||
if ( $nodenum eq 0 ) {
|
||||
$toolbatt = $data[0];
|
||||
$tooltemp = $data[1];
|
||||
}
|
||||
else {
|
||||
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ",\n";
|
||||
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
|
||||
if ( length($y) != 4 )
|
||||
{ # G201/G301 con la data invertita
|
||||
my $w = $y;
|
||||
$y = $d;
|
||||
$m = sprintf( '%02d', $m );
|
||||
$d = sprintf( '%02d', $w );
|
||||
}
|
||||
foreach (@data) {
|
||||
if ( $sql[ ( $outcount % $maxsqllines ) ] eq "" ) {
|
||||
$sql[ ( $outcount % $maxsqllines ) ] =
|
||||
"('$unit','$tool','$nodenum','$y-$m-$d','$t','$toolbatt','$tooltemp'";
|
||||
}
|
||||
$sql[ ( $outcount % $maxsqllines ) ] .=
|
||||
",'" . $_ . "'";
|
||||
}
|
||||
my $InsCompl = ",NULL" x ( 15 - $#data );
|
||||
$sql[ ( $outcount % $maxsqllines ) ] .= $InsCompl . ")";
|
||||
if ( ++$outcount % $maxsqllines eq 0 ) {
|
||||
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ";\n";
|
||||
writeOutSql($tool);
|
||||
}
|
||||
else {
|
||||
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ",\n";
|
||||
}
|
||||
}
|
||||
$nodenum++;
|
||||
}
|
||||
$nodenum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user