This commit is contained in:
2017-11-01 01:36:15 +01:00
parent 9463ca4dcd
commit f8e0b803e2

View File

@@ -1,476 +1,481 @@
#!/usr/bin/perl #!/usr/bin/perl
use warnings; use warnings;
use strict; use strict;
use DBI; use DBI;
use Getopt::Long; use Getopt::Long;
use Net::FTP; use Net::FTP;
use List::Util qw( max ); use List::Util qw( max );
use Data::Dumper qw(Dumper); use Data::Dumper qw(Dumper);
$|++; # Autoflush $|++; # Autoflush
my ( $filename, $sqlout ); my ( $filename, $sqlout );
my $username = 'ase_lar'; my $username = 'ase_lar';
my $password = 'laravel'; my $password = 'laravel';
my $db_lar = 'ase_lar'; my $db_lar = 'ase_lar';
my $db_sp = 'ase_lar'; my $db_sp = 'ase_lar';
my $server = 'localhost'; my $server = 'localhost';
my $db_name = "ase_mums"; my $db_name = "ase_mums";
my $table = "RAWDATA"; my $table = "RAWDATA";
my ( @CSVData, @sql ); my ( @CSVData, @sql );
my $outcount = 0; my $outcount = 0;
my $outfilenum = 0; my $outfilenum = 0;
my $maxsqllines = 10000; my $maxsqllines = 10000;
my ( my (
$tool, $toolbatt, $tooltemp, $tooltype, @channels, $tool, $toolbatt, $tooltemp, $tooltype, @channels,
@NewData, @din, @nodetype, $GDEventDate @NewData, @din, @nodetype, $GDEventDate
); );
my $matlab_ip = "160.78.21.71"; my $matlab_ip = "160.78.21.71";
my $matlab_cmd = "matlab.cmd"; my $matlab_cmd = "matlab.cmd";
my $matlab_timestamp = ""; my $matlab_timestamp = "";
my $ftp_send = 1; my $ftp_send = 1;
my $ftp_addrs; my $ftp_addrs;
my $ftp_user; my $ftp_user;
my $ftp_passwd; my $ftp_passwd;
my $ftp_parm; my $ftp_parm;
my $ftp_filename; my $ftp_filename;
my $ftp_target; my $ftp_target;
my $unit_id; my $unit_id;
sub getTimeStamp sub getTimeStamp
{ # parm [ts] => timestamp for filename; log => timestamp for log { # parm [ts] => timestamp for filename; log => timestamp for log
my $format = "%04d%02d%02d%02d%02d%02d"; my $format = "%04d%02d%02d%02d%02d%02d";
my ($p1) = @_; my ($p1) = @_;
if ( defined $p1 and $p1 eq "log" ) { if ( defined $p1 and $p1 eq "log" ) {
$format = "%04d%02d%02d %02d:%02d:%02d"; $format = "%04d%02d%02d %02d:%02d:%02d";
} }
if ( defined $p1 and $p1 eq "db_ts" ) { if ( defined $p1 and $p1 eq "db_ts" ) {
$format = "%04d-%02d-%02d %02d:%02d:%02d"; $format = "%04d-%02d-%02d %02d:%02d:%02d";
} }
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
localtime(time); localtime(time);
my $timestamp = my $timestamp =
sprintf( $format, $year + 1900, $mon + 1, $mday, $hour, $min, $sec ); sprintf( $format, $year + 1900, $mon + 1, $mday, $hour, $min, $sec );
return $timestamp; return $timestamp;
} }
sub writeOutSql { sub writeOutSql {
my ($tn) = @_; my ($tn) = @_;
my $outfile = $sqlout . "_" . $outfilenum++; my $outfile = $sqlout . "_" . $outfilenum++;
open SQLOUT, ">", $outfile open SQLOUT, ">", $outfile
or die( getTimeStamp("log") or die( getTimeStamp("log")
. " - pid $$ >> Error: opening output file " . " - pid $$ >> Error: opening output file "
. $outfile . $outfile
. ":$!\n" ); . ":$!\n" );
print getTimeStamp("log") . " - pid $$ >> file $outfile created\n"; print getTimeStamp("log") . " - pid $$ >> file $outfile created\n";
print SQLOUT "/* lock " print SQLOUT "/* lock "
. $db_name . $db_name
. ".$table table */\nLOCK TABLES " . ".$table table */\nLOCK TABLES "
. $db_name . $db_name
. ".$table WRITE;\n"; . ".$table WRITE;\n";
print SQLOUT "INSERT IGNORE INTO " . $db_name . ".$table\n"; print SQLOUT "INSERT IGNORE INTO " . $db_name . ".$table\n";
print SQLOUT print SQLOUT
"(`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,\n"; "(`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,\n";
print SQLOUT print SQLOUT
"`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`)\n"; "`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`)\n";
print SQLOUT "VALUES\n"; print SQLOUT "VALUES\n";
print SQLOUT @sql; print SQLOUT @sql;
@sql = (); @sql = ();
print SQLOUT "/* unlock table */\nUNLOCK TABLES;\n"; print SQLOUT "/* unlock table */\nUNLOCK TABLES;\n";
if ( $table eq 'RAWDATA' ) { if ( $table eq 'RAWDATA' ) {
print SQLOUT "/* call stored procedure to copy in " print SQLOUT "/* call stored procedure to copy in "
. $db_sp . $db_sp
. "*/\ncall " . "*/\ncall "
. $db_sp . $db_sp
. ".CopyAndFill('$tn');\n"; . ".CopyAndFill('$tn');\n";
} }
close SQLOUT close SQLOUT
or die( getTimeStamp("log") or die( getTimeStamp("log")
. " - pid $$ >> Error in closing file " . " - pid $$ >> Error in closing file "
. $outfile . $outfile
. "\n" ); . "\n" );
my @args = ( "mysql", "--login-path=asepath", "-e source " . $outfile ); my @args = ( "mysql", "--login-path=asepath", "-e source " . $outfile );
system(@args) == 0 system(@args) == 0
or die( getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n" ); or die( getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n" );
print getTimeStamp("log") . " - pid $$ >> file $outfile loaded into DB\n"; print getTimeStamp("log") . " - pid $$ >> file $outfile loaded into DB\n";
unlink $outfile; unlink $outfile;
return; return;
} }
sub matlabCalc { sub matlabCalc {
getMatlabCmd(); getMatlabCmd();
$matlab_timestamp = getTimeStamp("db_ts"); $matlab_timestamp = getTimeStamp("db_ts");
print getTimeStamp("log") . " - pid $$ >> $tool MatLab calc started...\n"; print getTimeStamp("log") . " - pid $$ >> $tool MatLab calc started...\n";
my @out_matlab = `ssh1 $matlab_ip 'cmd /c $matlab_cmd ' $tool`; my @out_matlab = `ssh1 $matlab_ip 'cmd /c $matlab_cmd ' $tool`;
print getTimeStamp("log") print getTimeStamp("log")
. " - pid $$ >> $tool MatLab calc executed: $out_matlab[-1]"; . " - pid $$ >> $tool MatLab calc executed: $out_matlab[-1]";
#print getTimeStamp("log") . " - @out_matlab"; #print getTimeStamp("log") . " - @out_matlab";
#print getTimeStamp("log") . " - pid $$ >> $out_matlab[-1]"; #print getTimeStamp("log") . " - pid $$ >> $out_matlab[-1]";
return; return;
} }
sub trxelab { sub trxelab {
my $dbh = my $dbh =
DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password )
or die getTimeStamp("log") or die getTimeStamp("log")
. " - pid $$ >> Could not connect to database: $DBI::errstr"; . " - pid $$ >> Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare( my $sth = $dbh->prepare(
'select ftp_addrs, ftp_user, ftp_passwd, ftp_parm, ftp_filename, ftp_target from units 'select ftp_addrs, ftp_user, ftp_passwd, ftp_parm, ftp_filename, ftp_target from units
where id = ' . $unit_id . ';' where id = ' . $unit_id . ';'
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$sth->execute(); $sth->execute();
if ( $sth->rows < 0 ) { if ( $sth->rows < 0 ) {
die getTimeStamp("log") . " - pid $$ >> No unit ftp params selected.\n"; die getTimeStamp("log") . " - pid $$ >> No unit ftp params selected.\n";
} }
else { else {
while ( my $results = $sth->fetchrow_hashref ) { while ( my $results = $sth->fetchrow_hashref ) {
$ftp_addrs = $results->{'ftp_addrs'}; $ftp_addrs = $results->{'ftp_addrs'};
$ftp_user = $results->{'ftp_user'}; $ftp_user = $results->{'ftp_user'};
$ftp_passwd = $results->{'ftp_passwd'}; $ftp_passwd = $results->{'ftp_passwd'};
$ftp_parm = $results->{'ftp_parm'}; $ftp_parm = $results->{'ftp_parm'};
$ftp_filename = $results->{'ftp_filename'}; $ftp_filename = $results->{'ftp_filename'};
$ftp_target = $results->{'ftp_target'}; $ftp_target = $results->{'ftp_target'};
} }
} }
$sth->finish; $sth->finish;
# Disconnect # Disconnect
my $fileelab; my $fileelab;
if ( $ftp_filename eq "" ) { if ( $ftp_filename eq "" ) {
$fileelab = $fileelab =
'/var/lib/mysql-files/' '/var/lib/mysql-files/'
. $tool . '_' . $tool . '_'
. getTimeStamp() . getTimeStamp()
. '.csv'; #mettere quello che si prende da query . '.csv'; #mettere quello che si prende da query
} }
else { else {
$ftp_filename =~ s/(\$\w+)/$1/eeg; $ftp_filename =~ s/(\$\w+)/$1/eeg;
$ftp_filename =~ s/\s/_/g; $ftp_filename =~ s/\s/_/g;
$fileelab = $fileelab =
'/var/lib/mysql-files/' '/var/lib/mysql-files/'
. $ftp_filename . '_' . $ftp_filename . '_'
. getTimeStamp() . '.csv'; . getTimeStamp() . '.csv';
} }
my $sthdo = $dbh->do( my $sthdo = $dbh->do(
qq{ qq{
select * from ( select * from (
select 'ToolNameID', 'EventDate', 'EventTime', 'NodeNum', 'NodeType', 'NodeDepth', select 'ToolNameID', 'EventDate', 'EventTime', 'NodeNum', 'NodeType', 'NodeDepth',
'XShift', 'YShift', 'ZShift' , 'X', 'Y', 'Z', 'HShift', 'HShiftDir', 'HShift_local', 'XShift', 'YShift', 'ZShift' , 'X', 'Y', 'Z', 'HShift', 'HShiftDir', 'HShift_local',
'week_shift', 'week_shift_x', 'week_shift_y', 'week_shift_z', 'T_node', 'water_level', 'pressure', 'load_value' 'week_shift', 'week_shift_x', 'week_shift_y', 'week_shift_z', 'T_node', 'water_level', 'pressure', 'load_value'
union all union all
select ToolNameID, EventDate, EventTime, NodeNum, NodeType, NodeDepth, select ToolNameID, EventDate, EventTime, NodeNum, NodeType, NodeDepth,
XShift, YShift, ZShift , X, Y, Z, HShift, HShiftDir, HShift_local, XShift, YShift, ZShift , X, Y, Z, HShift, HShiftDir, HShift_local,
week_shift, week_shift_x, week_shift_y, week_shift_z, T_node, water_level, pressure, load_value week_shift, week_shift_x, week_shift_y, week_shift_z, T_node, water_level, pressure, load_value
from ElabDataView from ElabDataView
where ToolNameID = '$tool' and created_at > '$matlab_timestamp' where ToolNameID = '$tool' and created_at > '$matlab_timestamp'
order by ToolNameID DESC, EventDate, EventTime, convert(`NodeNum`, decimal) DESC order by ToolNameID DESC, EventDate, EventTime, convert(`NodeNum`, decimal) DESC
) resulting_set ) resulting_set
into outfile '$fileelab' into outfile '$fileelab'
fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'} fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'}
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$dbh->disconnect; $dbh->disconnect;
$ftp_parm //= ""; $ftp_parm //= "";
$ftp_parm =~ s/\s//g; $ftp_parm =~ s/\s//g;
my %ftp_parms = ( my %ftp_parms = (
'Host' => $ftp_addrs, 'Host' => $ftp_addrs,
); );
foreach my $parm (split(/,/, $ftp_parm)) foreach my $parm (split(/,/, $ftp_parm))
{ {
my ($key, $val) = split(/=>/, $parm); my ($key, $val) = split(/=>/, $parm);
$ftp_parms{$key} = $val; $ftp_parms{$key} = $val;
} }
print getTimeStamp("log") . " - pid $$ >> $tool: ftp parm = " . Dumper(%ftp_parms) . "\n"; print getTimeStamp("log") . " - pid $$ >> $tool: ftp parm \n" . Dumper(%ftp_parms);
my $ftp = Net::FTP->new( %ftp_parms ) my $ftp = Net::FTP->new( %ftp_parms )
or die getTimeStamp("log") or die getTimeStamp("log")
. " - pid $$ >> Cannot connect to $ftp_addrs: $@ \n"; . " - pid $$ >> Cannot connect to $ftp_addrs: $@ \n";
$ftp->login( $ftp_user, $ftp_passwd ) $ftp->login( $ftp_user, $ftp_passwd )
or die getTimeStamp("log") or die getTimeStamp("log")
. " - pid $$ >> Cannot login " . " - pid $$ >> Cannot login "
. $ftp->message . "\n"; . $ftp->message . "\n";
$ftp_target //= ""; $ftp_target //= "";
if ( $ftp_target ne "" ) { if ( $ftp_target ne "" ) {
$ftp->cwd($ftp_target) $ftp->cwd($ftp_target)
or die getTimeStamp("log") or die getTimeStamp("log")
. " - pid $$ >> Change remote dir failed " . " - pid $$ >> Change remote dir failed "
. $ftp->message . "\n"; . $ftp->message . "\n";
} }
print getTimeStamp("log") print getTimeStamp("log")
. " - pid $$ >> ftp target: " . " - pid $$ >> ftp target: "
. $ftp->pwd() . ".\n"; . $ftp->pwd() . ".\n";
$ftp->put($fileelab) $ftp->put($fileelab)
or die getTimeStamp("log") or die getTimeStamp("log")
. " - pid $$ >> Put failed " . " - pid $$ >> Put failed "
. $ftp->message . "\n"; . $ftp->message . "\n";
$ftp->quit;
print getTimeStamp("log") print getTimeStamp("log")
. " - pid $$ >> $tool: $fileelab ftp put executed.\n"; . " - pid $$ >> ftp target files list:\n"
return; . Dumper($ftp->ls());
}
$ftp->quit;
sub getNodesType { print getTimeStamp("log")
my $dbh = . " - pid $$ >> $tool: $fileelab ftp put executed.\n";
DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) return;
or die getTimeStamp("log") }
. " - pid $$ >> Could not connect to database: $DBI::errstr";
sub getNodesType {
my $sth = $dbh->prepare( my $dbh =
'select t.name as name, n.seq as seq, n.num as num, n.channels as channels, y.type as type, n.din as din DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password )
from nodes as n or die getTimeStamp("log")
inner join tools as t on t.id = n.tool_id . " - pid $$ >> Could not connect to database: $DBI::errstr";
inner join nodetypes as y on n.nodetype_id = y.id
where t.name = "' . $tool . '" order by 3;' my $sth = $dbh->prepare(
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; 'select t.name as name, n.seq as seq, n.num as num, n.channels as channels, y.type as type, n.din as din
from nodes as n
$sth->execute(); inner join tools as t on t.id = n.tool_id
if ( $sth->rows < 0 ) { inner join nodetypes as y on n.nodetype_id = y.id
die getTimeStamp("log") . " - pid $$ >> No node channels selected.\n"; where t.name = "' . $tool . '" order by 3;'
} ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
else {
my $row = 0; $sth->execute();
while ( my $results = $sth->fetchrow_hashref ) { if ( $sth->rows < 0 ) {
$channels[$row] = $results->{'channels'}; die getTimeStamp("log") . " - pid $$ >> No node channels selected.\n";
$nodetype[$row] = $results->{'type'}; }
$din[ $row++ ] = $results->{'din'}; else {
} my $row = 0;
} while ( my $results = $sth->fetchrow_hashref ) {
$channels[$row] = $results->{'channels'};
$sth->finish; $nodetype[$row] = $results->{'type'};
$din[ $row++ ] = $results->{'din'};
# Disconnect }
$dbh->disconnect; }
return;
} $sth->finish;
sub getUdbPwd { # Disconnect
my $dbh = $dbh->disconnect;
DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) return;
or die getTimeStamp("log") }
. " - pid $$ >> Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare( sub getUdbPwd {
"SELECT db_user, db_pwd FROM ase_lar.companies where db_name = '" my $dbh =
. $db_name DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password )
. "';" ) or die getTimeStamp("log")
or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; . " - pid $$ >> Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare(
$sth->execute(); "SELECT db_user, db_pwd FROM ase_lar.companies where db_name = '"
if ( $sth->rows < 0 ) { . $db_name
die getTimeStamp("log") . " - pid $$ >> No password selected.\n"; . "';" )
} or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
else {
my $results = $sth->fetchrow_hashref; $sth->execute();
$password = $results->{'db_pwd'}; if ( $sth->rows < 0 ) {
$username = $results->{'db_user'}; die getTimeStamp("log") . " - pid $$ >> No password selected.\n";
}
} else {
my $results = $sth->fetchrow_hashref;
$sth->finish; $password = $results->{'db_pwd'};
$username = $results->{'db_user'};
# Disconnect
$dbh->disconnect; }
return;
} $sth->finish;
sub getMatlabCmd { # Disconnect
my $dbh = $dbh->disconnect;
DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) return;
or die getTimeStamp("log") }
. " - pid $$ >> Could not connect to database: $DBI::errstr";
sub getMatlabCmd {
my $sth = $dbh->prepare( my $dbh =
'select m.matcall, t.ftp_send , t.unit_id from matfuncs as m DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password )
inner join tools as t on t.matfunc = m.id or die getTimeStamp("log")
where t.name = "' . $tool . '" ;' . " - pid $$ >> Could not connect to database: $DBI::errstr";
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
my $sth = $dbh->prepare(
$sth->execute(); 'select m.matcall, t.ftp_send , t.unit_id from matfuncs as m
if ( $sth->rows < 0 ) { inner join tools as t on t.matfunc = m.id
die getTimeStamp("log") where t.name = "' . $tool . '" ;'
. " - pid $$ >> No tool's matlab function selected.\n"; ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
}
else { $sth->execute();
my $mfunc; if ( $sth->rows < 0 ) {
while ( my $results = $sth->fetchrow_hashref ) { die getTimeStamp("log")
$mfunc = uc $results->{'matcall'}; . " - pid $$ >> No tool's matlab function selected.\n";
$ftp_send = $results->{'ftp_send'}; }
$unit_id = $results->{'unit_id'}; else {
} my $mfunc;
$matlab_cmd = 'matlab_' . $mfunc . '.cmd'; while ( my $results = $sth->fetchrow_hashref ) {
} $mfunc = uc $results->{'matcall'};
$ftp_send = $results->{'ftp_send'};
$sth->finish; $unit_id = $results->{'unit_id'};
}
# Disconnect $matlab_cmd = 'matlab_' . $mfunc . '.cmd';
$dbh->disconnect; }
return;
} $sth->finish;
my $starttime = getTimeStamp("log"); # Disconnect
print "$starttime - pid $$ >> Start execution.\n"; $dbh->disconnect;
return;
GetOptions( }
"filename=s" => \$filename,
"sqlout=s" => \$sqlout, my $starttime = getTimeStamp("log");
"dbname=s" => \$db_name print "$starttime - pid $$ >> Start execution.\n";
) or die("Error in command line arguments\n");
open FILE, $filename GetOptions(
or die( "Error: opening input file " . $filename . "\n" ); "filename=s" => \$filename,
"sqlout=s" => \$sqlout,
if ( $db_name ne 'asega' ) { "dbname=s" => \$db_name
$db_name =~ s/aseu/dbn/; ) or die("Error in command line arguments\n");
$db_sp = $db_name; open FILE, $filename
getUdbPwd(); or die( "Error: opening input file " . $filename . "\n" );
$db_lar = $db_name;
$table = "RAWDATACOR"; if ( $db_name ne 'asega' ) {
} $db_name =~ s/aseu/dbn/;
else { $db_sp = $db_name;
$db_name = 'ase_mums'; getUdbPwd();
} $db_lar = $db_name;
$table = "RAWDATACOR";
my ( $fileDate, $fileTime ) = split( /\s/, <FILE> ); }
my ( $unittype, $unit ) = split( /\s/, uc <FILE> ); else {
$unit =~ s/;+$//; $db_name = 'ase_mums';
}
while ( my $line = <FILE> ) {
my ( $first, $NodeData ) = split( /;/, $line, 2 ); my ( $fileDate, $fileTime ) = split( /\s/, <FILE> );
if ( defined $first and ( $first ne '' ) ) { my ( $unittype, $unit ) = split( /\s/, uc <FILE> );
$first =~ s/;+$//; $unit =~ s/;+$//;
if ( !defined $NodeData or ( $NodeData =~ m/^;+/ ) ) {
my @info = ( split( /[\/,\.]/, $first ) ); while ( my $line = <FILE> ) {
if ( defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) { my ( $first, $NodeData ) = split( /;/, $line, 2 );
$tool = uc $info[3]; if ( defined $first and ( $first ne '' ) ) {
$tooltype = uc $info[2]; $first =~ s/;+$//;
print getTimeStamp("log") if ( !defined $NodeData or ( $NodeData =~ m/^;+/ ) ) {
. " - pid $$ >> Found $tooltype tool name: $tool\n"; my @info = ( split( /[\/,\.]/, $first ) );
getNodesType(); if ( defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) {
} $tool = uc $info[3];
elsif ( defined $info[2] && $info[2] =~ m/^LOC\d*$/i ) { $tooltype = uc $info[2];
$tool = uc $info[2]; print getTimeStamp("log")
$tooltype = 'LOC'; . " - 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];
elsif ( defined $info[3] && $info[3] =~ m/^GD\d*$/i ) { $tooltype = 'LOC';
$tool = uc $info[3]; print getTimeStamp("log")
$tooltype = 'GD'; . " - pid $$ >> Found $tooltype tool name: $tool\n";
print getTimeStamp("log") getNodesType();
. " - pid $$ >> Found $tooltype tool name: $tool\n"; }
} elsif ( defined $info[3] && $info[3] =~ m/^GD\d*$/i ) {
} $tool = uc $info[3];
else { $tooltype = 'GD';
$NodeData =~ s/\x0d{0,1}\x0a\Z//s; print getTimeStamp("log")
$NodeData =~ s/;+$//; . " - pid $$ >> Found $tooltype tool name: $tool\n";
}
#$NodeData =~ s/\r\n\z//; }
else {
if ( $tooltype eq "MUX" ) { $NodeData =~ s/\x0d{0,1}\x0a\Z//s;
$NodeData =~ s/;+$//;
#$NodeData =~ s/Dis\./N\/A/g;
@NewData = grep /\S/, split( /\||;/, $NodeData ); #$NodeData =~ s/\r\n\z//;
my $idx = 0;
$CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, 2 ) ); if ( $tooltype eq "MUX" ) {
foreach my $ch (@channels) {
$CSVData[ $idx++ ] = #$NodeData =~ s/Dis\./N\/A/g;
join( ';', splice( @NewData, 0, $ch ) ); @NewData = grep /\S/, split( /\||;/, $NodeData );
} my $idx = 0;
$CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, 2 ) );
#print Dumper \@NewData; foreach my $ch (@channels) {
#print Dumper \@din; $CSVData[ $idx++ ] =
} join( ';', splice( @NewData, 0, $ch ) );
elsif ( $tooltype eq "LOC" ) { }
if ( !defined $din[0] ) {
print getTimeStamp("log") #print Dumper \@NewData;
. " - pid $$ >> Din not defined.\n"; #print Dumper \@din;
print getTimeStamp("log") }
. " - pid $$ >> Execution ended.\n"; elsif ( $tooltype eq "LOC" ) {
exit; if ( !defined $din[0] ) {
} print getTimeStamp("log")
my ( $Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2 ) = . " - pid $$ >> Din not defined.\n";
split( /;/, $NodeData ); print getTimeStamp("log")
$CSVData[0] = $Vbat . ";" . $Tmod; . " - pid $$ >> Execution ended.\n";
$CSVData[1] = $Din1; exit;
} }
elsif ( $tooltype eq "GD" ) { my ( $Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2 ) =
my ( $div, $Vbat, $Tmod ) = split( /;/, $NodeData );
split( /;/, $NodeData ); $CSVData[0] = $Vbat . ";" . $Tmod;
$CSVData[0] = $Vbat . ";" . $Tmod; $CSVData[1] = $Din1;
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first ); }
my ( $h, $min, $sec ) = split( /:/, $t ); elsif ( $tooltype eq "GD" ) {
$GDEventDate = $y . '-' . $m . '-' . $d; my ( $div, $Vbat, $Tmod ) =
$CSVData[1] = "DT" split( /;/, $NodeData );
. substr( $tool, 2, 4 ) . ';' $CSVData[0] = $Vbat . ";" . $Tmod;
. $h . ':' my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
. ( $min - 1 ) . ';' my ( $h, $min, $sec ) = split( /:/, $t );
. $h . ':' $GDEventDate = $y . '-' . $m . '-' . $d;
. ( $min + 1 ); $CSVData[1] = "DT"
} . substr( $tool, 2, 4 ) . ';'
else { . $h . ':'
@CSVData = split( /\|/, $NodeData ); . ( $min - 1 ) . ';'
} . $h . ':'
. ( $min + 1 );
my $nodenum = 0; }
foreach (@CSVData) { else {
$sql[ ( $outcount % $maxsqllines ) ] = ""; @CSVData = split( /\|/, $NodeData );
my (@data) = grep { /\S/ } split( /\;/, $_ ); }
if ( $nodenum eq 0 ) {
$toolbatt = $data[0]; my $nodenum = 0;
$tooltemp = $data[1]; foreach (@CSVData) {
} $sql[ ( $outcount % $maxsqllines ) ] = "";
else { my (@data) = grep { /\S/ } split( /\;/, $_ );
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first ); if ( $nodenum eq 0 ) {
foreach (@data) { $toolbatt = $data[0];
if ( $sql[ ( $outcount % $maxsqllines ) ] eq "" ) { $tooltemp = $data[1];
$sql[ ( $outcount % $maxsqllines ) ] = }
"('$unit','$tool','$nodenum','$y-$m-$d','$t','$toolbatt','$tooltemp'"; else {
} my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
$sql[ ( $outcount % $maxsqllines ) ] .= ",'" . $_ . "'"; foreach (@data) {
} if ( $sql[ ( $outcount % $maxsqllines ) ] eq "" ) {
my $InsCompl = ",NULL" x ( 15 - $#data ); $sql[ ( $outcount % $maxsqllines ) ] =
$sql[ ( $outcount % $maxsqllines ) ] .= $InsCompl . ")"; "('$unit','$tool','$nodenum','$y-$m-$d','$t','$toolbatt','$tooltemp'";
if ( ++$outcount % $maxsqllines eq 0 ) { }
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ";\n"; $sql[ ( $outcount % $maxsqllines ) ] .= ",'" . $_ . "'";
writeOutSql($tool); }
} my $InsCompl = ",NULL" x ( 15 - $#data );
else { $sql[ ( $outcount % $maxsqllines ) ] .= $InsCompl . ")";
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ",\n"; if ( ++$outcount % $maxsqllines eq 0 ) {
} $sql[ ( $outcount % $maxsqllines ) - 1 ] .= ";\n";
} writeOutSql($tool);
$nodenum++; }
} else {
} $sql[ ( $outcount % $maxsqllines ) - 1 ] .= ",\n";
} }
} }
close FILE; $nodenum++;
$sql[ ( $outcount % $maxsqllines ) - 1 ] =~ s/,$/;/g; }
writeOutSql($tool); }
if ( $tooltype eq "GD" ) { }
print getTimeStamp("log") . " - pid $$ >> tool GD: nothing to do.\n"; }
} close FILE;
else { $sql[ ( $outcount % $maxsqllines ) - 1 ] =~ s/,$/;/g;
matlabCalc(); writeOutSql($tool);
if ($ftp_send) { if ( $tooltype eq "GD" ) {
if ( $tool eq 'DT0076' ) { print getTimeStamp("log") . " - pid $$ >> tool GD: nothing to do.\n";
sleep(600); }
} else {
trxelab(); matlabCalc();
} if ($ftp_send) {
} if ( $tool eq 'DT0076' ) {
sleep(600);
print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; }
exit; trxelab();
}
}
print getTimeStamp("log") . " - pid $$ >> Execution ended.\n";
exit;