Author: alexey Date: 2019-05-27 23:58:24 +0000 (Mon, 27 May 2019) New Revision: 2776 Modified: trunk/programs/us_com_project/us_com_project_gui.cpp trunk/programs/us_com_project/us_com_project_gui.h trunk/programs/us_convert/us_convert_gui.cpp trunk/programs/us_convert/us_experiment.cpp trunk/programs/us_convert/us_experiment.h trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.h Log: Autoflow development: * proper assignment of the saved exp. data owner - propagated down from us_experiment * when reattaching to LIVE UPDATE, dialog not shown if run has been launched from the Optima panel; showed otherwise Modified: trunk/programs/us_com_project/us_com_project_gui.cpp =================================================================== --- trunk/programs/us_com_project/us_com_project_gui.cpp 2019-05-22 03:37:32 UTC (rev 2775) +++ trunk/programs/us_com_project/us_com_project_gui.cpp 2019-05-27 23:58:24 UTC (rev 2776) @@ -402,6 +402,10 @@ qDebug() << "Autoflow record #: " << autoflow_records; + // //Temporary: delete ExperimentDefinition record ( ExpId = 306, 301 ) + // int ExpId = 285; + // delete_psql_record( ExpId ); + if ( autoflow_records < 1 ) return; @@ -496,7 +500,8 @@ QString ProtName = protocol_details[ "protocolName" ]; QString correctRadii = protocol_details[ "correctRadii" ]; QString expAborted = protocol_details[ "expAborted" ]; - + QString runID = protocol_details[ "runID" ]; + QDir directory( currDir ); qDebug() << "CURR DIRECTORY : " << currDir; @@ -536,6 +541,111 @@ } +//Slot to delete Postgres Optima ExperimentDefinition record +void US_ComProjectMain::delete_psql_record( int ExpId ) +{ + QString schname( "AUC_schema" ); + + QString tabname_expdef( "ExperimentDefinition" ); + QString tabname_fuge ( "CentrifugeRunProfile" ); + QString tabname_abs ( "AbsorbanceScanParameters" ); + + QString qrytab_expdef = "\"" + schname + "\".\"" + tabname_expdef + "\""; + QString qrytab_fuge = "\"" + schname + "\".\"" + tabname_fuge + "\""; + QString qrytab_abs = "\"" + schname + "\".\"" + tabname_abs + "\""; + + + QString dbhost = "demeler5.uleth.ca"; + int dbport = 5552; + QString dbname = "AUC_DATA_DB"; + QString dbuser = ""; + QString dbpasw = ""; + + QSqlDatabase dbxpn; + + dbxpn = QSqlDatabase::addDatabase( "QPSQL", "" ); + dbxpn.setDatabaseName( "XpnData" ); + dbxpn.setHostName ( dbhost ); + dbxpn.setPort ( dbport ); + dbxpn.setDatabaseName( dbname ); + dbxpn.setUserName ( dbuser ); + dbxpn.setPassword ( dbpasw ); + + qDebug() << "Opening Postgres Connection!!!"; + + if ( dbxpn.open() ) + { + qDebug() << "Connected !!!"; + + QSqlQuery query_expdef(dbxpn); + QSqlQuery query_fuge(dbxpn); + QSqlQuery query_abs_scan(dbxpn); + + /* + // AbsorbanceScanParameters + QString ScanId = "5996"; + if(! query_abs_scan.prepare(QString("DELETE FROM %1 WHERE \"ScanId\" = %2").arg(qrytab_abs).arg(ScanId) ) ) + qDebug() << query_abs_scan.lastError().text(); + + if (query_abs_scan.exec()) + { + qDebug() << "AbsorbanceScanParameters record # :" << ScanId << "deleted !"; + } + else + { + QString errmsg = "Delete record error: " + query_abs_scan.lastError().text(); + QMessageBox::critical( this, + tr( "*ERROR* in Deleting Absorbance Record" ), + tr( "An error occurred in the attempt to delete" + " AbsorbanceScanParameters from AUC DB\n %1 table\n %2 ." ).arg( qrytab_abs ).arg( errmsg ) ); + return; + } + + // Cell Parameters + + + // FugeProfile + int FugeId = 308; + if(! query_fuge.prepare(QString("DELETE FROM %1 WHERE \"FugeRunProfileId\" = %2").arg(qrytab_fuge).arg(FugeId) ) ) + qDebug() << query_fuge.lastError().text(); + + if (query_fuge.exec()) + { + qDebug() << "FugeProfile record # :" << FugeId << "deleted !"; + } + else + { + QString errmsg = "Delete record error: " + query_fuge.lastError().text();; + QMessageBox::critical( this, + tr( "*ERROR* in Deleting Fuge Profile" ), + tr( "An error occurred in the attempt to delete" + " FugeProfile from AUC DB\n %1 table\n %2 ." ).arg( qrytab_fuge ).arg( errmsg ) ); + return; + } + + */ + + // ExperimentalDefinition + if(! query_expdef.prepare(QString("DELETE FROM %1 WHERE \"ExperimentId\" = %2").arg(qrytab_expdef).arg(ExpId) ) ) + qDebug() << query_expdef.lastError().text(); + + if (query_expdef.exec()) + { + qDebug() << "ExperimentDefinition record # :" << ExpId << "deleted !"; + } + else + { + QString errmsg = "Delete record error: " + query_expdef.lastError().text();; + QMessageBox::critical( this, + tr( "*ERROR* in Deleting Experimental Method" ), + tr( "An error occurred in the attempt to delete" + " exp. method from AUC DB\n %1 table\n %2 ." ).arg( qrytab_expdef ).arg( errmsg ) ); + return; + } + + } +} + // Slot to read all Optima machines <------------------------------- // New void US_ComProjectMain::read_optima_machines( US_DB2* db ) { Modified: trunk/programs/us_com_project/us_com_project_gui.h =================================================================== --- trunk/programs/us_com_project/us_com_project_gui.h 2019-05-22 03:37:32 UTC (rev 2775) +++ trunk/programs/us_com_project/us_com_project_gui.h 2019-05-27 23:58:24 UTC (rev 2776) @@ -286,7 +286,9 @@ void to_autoflow_records( void ); - void define_new_experiment( QStringList & ); + void define_new_experiment( QStringList & ); + + void delete_psql_record( int ); signals: void pass_to_live_update( QMap < QString, QString > & protocol_details ); Modified: trunk/programs/us_convert/us_convert_gui.cpp =================================================================== --- trunk/programs/us_convert/us_convert_gui.cpp 2019-05-22 03:37:32 UTC (rev 2775) +++ trunk/programs/us_convert/us_convert_gui.cpp 2019-05-27 23:58:24 UTC (rev 2776) @@ -5376,7 +5376,12 @@ QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) ); le_status->setText( tr( "Saving Experiment to DB ..." ) ); qApp->processEvents(); - status = ExpData.saveToDB( ( saveStatus == BOTH ), &db, speedsteps ); + + if ( us_convert_auto_mode ) //ALEXEY: copy of the method with the ExpData.invID set as the owner (not US_Settings::us_inv_ID() )... + status = ExpData.saveToDB_auto( ( saveStatus == BOTH ), &db, speedsteps, ExpData.invID ); + else + status = ExpData.saveToDB( ( saveStatus == BOTH ), &db, speedsteps ); + QApplication::restoreOverrideCursor(); if ( status == US_DB2::NO_PROJECT ) Modified: trunk/programs/us_convert/us_experiment.cpp =================================================================== --- trunk/programs/us_convert/us_experiment.cpp 2019-05-22 03:37:32 UTC (rev 2775) +++ trunk/programs/us_convert/us_experiment.cpp 2019-05-27 23:58:24 UTC (rev 2776) @@ -178,6 +178,128 @@ return US_DB2::OK; } +//Same as above but for AutoFlow with ExpData.invID set as owner +int US_Experiment::saveToDB_auto( bool update, US_DB2* db, + QVector< SP_SPEEDPROFILE >& speedsteps, int invID_passed ) +{ +qDebug() << "Exp:svToDB: update" << update << "ss-count" << speedsteps.count(); + // Let's see if the project is in the db already + int status = project.saveToDB( db ); +qDebug() << "Exp:svToDB: projsv status(+NO_PR)" << status << US_DB2::NO_PROJECT + << "expID" << expID; + if ( status == US_DB2::NO_PROJECT ) + return status; + + else if ( status != US_DB2::OK ) + return status; + + // Get the RI information, if appropriate + QByteArray RIxml; + QByteArray RIxmlEscaped; + createRIXml( RIxml ); + //unsigned long length = db->mysqlEscapeString( RIxmlEscaped, RIxml, RIxml.size() ); + db->mysqlEscapeString( RIxmlEscaped, RIxml, RIxml.size() ); + + // Check for experiment runID in database + int saveStatus = 0; + QStringList q; + status = checkRunID( db ); + if ( status == US_DB2::OK && ! update ) + { + // Then the runID exists already, and we're not updating + return US_DB2::DUPFIELD; + } + + if ( status == US_DB2::OK ) + { + // It's ok to update the existing experiment entry + q.clear(); + q << "update_experiment" + << QString::number( expID ) + << QString( expGUID ) + << QString::number( project.projectID ) + << runID + << QString::number( labID ) + << QString::number( instrumentID ) + << QString::number( operatorID ) + << QString::number( rotorID ) + << QString::number( calibrationID ) + << expType + << opticalSystem + << RIxmlEscaped + << runTemp + << label + << comments + << protocolGUID; + + saveStatus = db->statusQuery( q ); + } + + else if ( status == US_DB2::NOROWS ) + { + // Create new experiment entry + q.clear(); + q << "new_experiment" + << expGUID + << QString::number( project.projectID ) + << runID + << QString::number( labID ) + << QString::number( instrumentID ) + << QString::number( operatorID ) + << QString::number( rotorID ) + << QString::number( calibrationID ) + << expType + << opticalSystem + << RIxml + << runTemp + << label + << comments + << protocolGUID + << QString::number( invID_passed ); //ALEXEY: passed invID, NOT the US_Settings ::us_inv_ID() + + saveStatus = db->statusQuery( q ); + expID = db->lastInsertID(); + } + + if ( expID == 0 ) // double check + { + qDebug() << "Error saving experiment: " << saveStatus + << " " << db->lastError(); + return saveStatus; + } + + // Let's get some info after db update + QString idExp = QString::number( expID ); + q.clear(); + q << "get_experiment_info" << idExp; + db->query( q ); + db->next(); + + date = db->value( 12 ).toString(); + + // If multispeed, add speed steps to the database + q.clear(); + q << "delete_speedsteps" << idExp; // Delete any records for experiment + saveStatus = db->statusQuery( q ); + if ( saveStatus != 0 ) + { + qDebug() << "Delete_SpeedSteps" << saveStatus << db->lastError(); + } +qDebug() << "Exp:svToDB: delss status" << saveStatus << db->lastError(); + +qDebug() << "Exp:svToDB: ss count" << speedsteps.count() << "expID" << expID; + for ( int jj = 0; jj < speedsteps.count(); jj++ ) + { +qDebug() << "Exp:svToDB: jj" << jj << "expID" << expID; +int ssstat= + US_SimulationParameters::speedstepToDB( db, expID, &speedsteps[ jj ] ); +qDebug() << "Exp:svToDB: ssstat=" << ssstat; + } + + return US_DB2::OK; +} + + // Function to read an experiment from DB int US_Experiment::readFromDB( QString runID, US_DB2* db, QVector< SP_SPEEDPROFILE >& speedsteps ) Modified: trunk/programs/us_convert/us_experiment.h =================================================================== --- trunk/programs/us_convert/us_experiment.h 2019-05-22 03:37:32 UTC (rev 2775) +++ trunk/programs/us_convert/us_experiment.h 2019-05-27 23:58:24 UTC (rev 2776) @@ -93,7 +93,8 @@ \param speedsteps Reference to vector of experiment speed steps */ int saveToDB( bool, US_DB2*, QVector< SP_SPEEDPROFILE >& ); - + int saveToDB_auto( bool, US_DB2*, QVector< SP_SPEEDPROFILE >&, int ); + /*! \brief Reads experiment information from the db \param runID The run ID of the experiment. Modified: trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp =================================================================== --- trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp 2019-05-22 03:37:32 UTC (rev 2775) +++ trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp 2019-05-27 23:58:24 UTC (rev 2776) @@ -2063,7 +2063,10 @@ invID_passed = protocol_details[ "invID_passed" ]; correctRadii = protocol_details[ "correctRadii" ]; expAborted = protocol_details[ "expAborted" ]; + runID_passed = protocol_details[ "runID" ]; + qDebug() << "RUNID_PASSED !!! " << runID_passed; + details_at_live_update = protocol_details; selectOptimaByName_auto( OptimaName ); //New @@ -2096,16 +2099,18 @@ // // .arg(RunName).arg(OptimaName) ); - msg_data_avail->exec(); - - if (msg_data_avail->clickedButton() == Close) + if ( runID_passed.isEmpty() || runID_passed == "NULL" ) { - timer_data_init->stop(); - disconnect(timer_data_init, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything - - emit close_program(); + msg_data_avail->exec(); + + if (msg_data_avail->clickedButton() == Close) + { + timer_data_init->stop(); + disconnect(timer_data_init, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything + + emit close_program(); + } } - } //void US_XpnDataViewer::retrieve_xpn_raw_auto( QString & RunID ) Modified: trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.h =================================================================== --- trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.h 2019-05-22 03:37:32 UTC (rev 2775) +++ trunk/programs/us_xpn_viewer/us_xpn_viewer_gui.h 2019-05-27 23:58:24 UTC (rev 2776) @@ -284,6 +284,7 @@ QString invID_passed; QString correctRadii; QString expAborted; + QString runID_passed; QMap < QString, QString > details_at_live_update;