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