Author: alexey Date: 2019-04-28 17:43:16 +0000 (Sun, 28 Apr 2019) New Revision: 2742 Modified: trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.h trunk/sql/us3_autoflow_procs.sql Log: Updates on job reattachement in autoflow... Modified: trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp =================================================================== --- trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp 2019-04-27 09:50:16 UTC (rev 2741) +++ trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp 2019-04-28 17:43:16 UTC (rev 2742) @@ -242,6 +242,8 @@ in_reload_data_init = false; in_reload_check_sysdata = false; + ElapsedTimeOffset = 0; + //ALEXEY: new way US_Passwd pw; US_DB2* dbP = new US_DB2( pw.getPasswd() ); @@ -1436,6 +1438,11 @@ RunID_to_retrieve = QString::number(xpn_data->get_runid( ExpID_to_use )); qDebug() << "RunID_to_retrieve 1: " << RunID_to_retrieve; + + // ElapsedTimeOffset = read_timeElapsed_offset(); + // qDebug() << "Elapsed Time Offset: " << ElapsedTimeOffset; + + // runInfo.clear(); //xpn_data->scan_runs( runInfo ); // ALEXEY initial query (for us_comproject needs to be based on ExpId ) @@ -1473,8 +1480,13 @@ disconnect(timer_data_init, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything msg_data_avail->close(); - //ALEXEY: need to update 'autoflow' table with the unique RunID_to_retrieve && Start Run Time fields !!! - + //ALEXEY: need to update 'autoflow' table with the unique RunID_to_retrieve && Start Run Time fields !!! + //Conditional: Do it ONLY once !!! + update_autoflow_runId_timeStarted(); + + //ALEXEY: retrieve startTime from autoflow table: + ElapsedTimeOffset = read_timeElapsed_offset(); + //ALEXEY: elapsed timer start elapsed_timer = new QElapsedTimer; elapsed_timer->start(); @@ -1529,6 +1541,129 @@ } +// When Optima run started & runID aqcuried, update 'autoflow' table +void US_XpnDataViewer::update_autoflow_runId_timeStarted( void ) +{ + // Check DB connection + US_Passwd pw; + QString masterpw = pw.getPasswd(); + US_DB2* db = new US_DB2( masterpw ); + + if ( db->lastErrno() != US_DB2::OK ) + { + QMessageBox::warning( this, tr( "Connection Problem" ), + tr( "Read protocol: Could not connect to database \n" ) + db->lastError() ); + return; + } + + QStringList qry; + qry << "update_autoflow_runid_starttime" + << ExpID_to_use + << RunID_to_retrieve; + + db->query( qry ); + //ALEXEY: Updates with runID && timeStarted only once, when runID && runStarttime IS NULL +} + +// Read diffference btw started tiem and NOW() as an offset for Elapsed time +int US_XpnDataViewer::read_timeElapsed_offset( void ) +{ + // Check DB connection + US_Passwd pw; + QString masterpw = pw.getPasswd(); + US_DB2* db = new US_DB2( masterpw ); + + int time_offset = 0; + + if ( db->lastErrno() != US_DB2::OK ) + { + QMessageBox::warning( this, tr( "Connection Problem" ), + tr( "Read protocol: Could not connect to database \n" ) + db->lastError() ); + return time_offset; + } + + QStringList qry; + qry << "read_autoflow_times" + << RunID_to_retrieve; + + time_offset = db->functionQuery( qry ); + + return time_offset; +} + +//Delete autoflow record upon Run abortion +void US_XpnDataViewer::delete_autoflow_record( void ) +{ + // Check DB connection + US_Passwd pw; + QString masterpw = pw.getPasswd(); + US_DB2* db = new US_DB2( masterpw ); + + if ( db->lastErrno() != US_DB2::OK ) + { + QMessageBox::warning( this, tr( "Connection Problem" ), + tr( "Read protocol: Could not connect to database \n" ) + db->lastError() ); + return; + } + + QStringList qry; + qry << "delete_autoflow_record" + << RunID_to_retrieve; + + //db->query( qry ); + + // OR + + int status = db->statusQuery( qry ); + + if ( status == US_DB2::NO_AUTOFLOW_RECORD ) + { + QMessageBox::warning( this, + tr( "Autoflow Record Not Deleted" ), + tr( "No autoflow record\n" + "associated with this experiment." ) ); + return; + } +} + + +//Delete autoflow record upon Run abortion +void US_XpnDataViewer::updateautoflow_record_atLiveUpdate( void ) +{ + // Check DB connection + US_Passwd pw; + QString masterpw = pw.getPasswd(); + US_DB2* db = new US_DB2( masterpw ); + + if ( db->lastErrno() != US_DB2::OK ) + { + QMessageBox::warning( this, tr( "Connection Problem" ), + tr( "Read protocol: Could not connect to database \n" ) + db->lastError() ); + return; + } + + QStringList qry; + qry << "update_autoflow_at_live_update" + << RunID_to_retrieve + << currentDir; + + //db->query( qry ); + + // OR + + int status = db->statusQuery( qry ); + + if ( status == US_DB2::NO_AUTOFLOW_RECORD ) + { + QMessageBox::warning( this, + tr( "Autoflow Record Not Updated" ), + tr( "No autoflow record\n" + "associated with this experiment." ) ); + return; + } +} + + // Check periodically for SysData void US_XpnDataViewer::check_for_sysdata( void ) { @@ -1581,10 +1716,9 @@ le_running->setText( running_time_text ); qApp->processEvents(); - //Elapsed Time QList< int > dhms_e; - int elapsed_time = int( elapsed_timer->elapsed() / 1000 ); + int elapsed_time = int( elapsed_timer->elapsed() / 1000 ) + ElapsedTimeOffset; int elapsed_time_1 = elapsed_time; timeToList( elapsed_time, dhms_e ); QString elapsed_time_text; @@ -1705,6 +1839,7 @@ QString message_done = tr( "Experiment was completed. Optima data saved..." ); QMessageBox::information( this, mtitle_complete, message_done ); + updateautoflow_record_atLiveUpdate(); emit experiment_complete_auto( currentDir, ProtocolName, invID_passed ); // Updtade later: what should be passed with signal ?? return; @@ -1746,6 +1881,8 @@ QString mtitle_complete = tr( "Complete!" ); QString message_done = tr( "Experiment was completed. Optima data saved..." ); QMessageBox::information( this, mtitle_complete, message_done ); + + updateautoflow_record_atLiveUpdate(); emit experiment_complete_auto( currentDir, ProtocolName, invID_passed ); // Updtade later: what should be passed with signal ?? return; } @@ -1753,6 +1890,7 @@ else if (msgBox.clickedButton() == Ignore) { reset(); + delete_autoflow_record(); emit return_to_experiment( ProtocolName ); return; } @@ -1790,6 +1928,7 @@ xpn_data->setEtimOffZero(); //ALEXEY: intialize etimoff to zero for the first time counter_mins = 0; + ElapsedTimeOffset = 0; ExpID_to_use = protocol_details["experimentId"]; ProtocolName = protocol_details["protocolName"]; @@ -3430,6 +3569,8 @@ QString mtitle_complete = tr( "Complete!" ); QString message_done = tr( "Experiment was completed. Optima data saved..." ); QMessageBox::information( this, mtitle_complete, message_done ); + + updateautoflow_record_atLiveUpdate(); emit experiment_complete_auto( currentDir, ProtocolName, invID_passed ); // Updtade later: what should be passed with signal ?? //QString temp_protname("DemchukA_exosomes40K_111418"); @@ -3462,10 +3603,12 @@ if (msgBox.clickedButton() == Save) { export_auc_auto(); - + QString mtitle_complete = tr( "Complete!" ); QString message_done = tr( "Experiment was completed. Optima data saved..." ); QMessageBox::information( this, mtitle_complete, message_done ); + + updateautoflow_record_atLiveUpdate(); emit experiment_complete_auto( currentDir, ProtocolName, invID_passed ); // Updtade later: what should be passed with signal ?? return; } @@ -3473,6 +3616,7 @@ else if (msgBox.clickedButton() == Ignore) { reset(); + delete_autoflow_record(); emit return_to_experiment( ProtocolName ); return; } Modified: trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.h =================================================================== --- trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.h 2019-04-27 09:50:16 UTC (rev 2741) +++ trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.h 2019-04-28 17:43:16 UTC (rev 2742) @@ -279,7 +279,8 @@ QString TripleNumber; QString OptimaName; //New QString TotalDuration; //New - QString invID_passed; + QString invID_passed; + int ElapsedTimeOffset; void timeToList( int&, QList< int >& ); @@ -296,6 +297,10 @@ void retrieve_xpn_raw_auto ( void ); void reloadData_auto ( void ); int CheckExpComplete_auto( QString & ); + void update_autoflow_runId_timeStarted( void ); + int read_timeElapsed_offset( void ); + void delete_autoflow_record( void ); + void updateautoflow_record_atLiveUpdate( void ); void expStatFive( void ); void expStatTwo( void ); Modified: trunk/sql/us3_autoflow_procs.sql =================================================================== --- trunk/sql/us3_autoflow_procs.sql 2019-04-27 09:50:16 UTC (rev 2741) +++ trunk/sql/us3_autoflow_procs.sql 2019-04-28 17:43:16 UTC (rev 2742) @@ -217,23 +217,20 @@ MODIFIES SQL DATA BEGIN - DECLARE count_records INT; + DECLARE curr_runid INT; CALL config(); SET @US3_LAST_ERRNO = @OK; SET @US3_LAST_ERROR = ''; -SELECT COUNT(*) - INTO count_records + SELECT runID + INTO curr_runid FROM autoflow WHERE expID = p_expID; + IF ( verify_user( p_personGUID, p_password ) = @OK ) THEN - IF ( count_records = 0 ) THEN - SET @US3_LAST_ERRNO = @NO_AUTOFLOW_RECORD; - SET @US3_LAST_ERROR = 'MySQL: no rows returned'; - - ELSE + IF ( curr_runid IS NULL ) THEN UPDATE autoflow SET runID = p_runid, runStarted = NOW() WHERE expID = p_expID; @@ -242,7 +239,7 @@ END IF; - SELECT @US3_LAST_ERRNO AS status; + -- SELECT @US3_LAST_ERRNO AS status; END$$ @@ -262,7 +259,7 @@ SET @US3_LAST_ERRNO = @OK; SET @US3_LAST_ERROR = ''; -SELECT COUNT(*) + SELECT COUNT(*) INTO count_records FROM autoflow WHERE runID = p_runID AND status = 'LIVE_UPDATE';