1 #include <QApplication>
20 int main(
int argc,
char* argv[] )
22 QApplication application( argc, argv );
30 return application.exec();
35 setWindowTitle( tr(
"Fit Meniscus from 2DSA Data" ) );
40 QBoxLayout* mainLayout =
new QVBoxLayout(
this );
41 mainLayout->setSpacing ( 2 );
42 mainLayout->setContentsMargins ( 2, 2, 2, 2 );
45 QHBoxLayout* topLayout =
new QHBoxLayout;
46 QHBoxLayout* bottomLayout =
new QHBoxLayout;
47 QGridLayout* leftLayout =
new QGridLayout;
48 QGridLayout* rightLayout =
new QGridLayout;
49 QGridLayout* cntrlsLayout =
new QGridLayout;
53 "results/*-fm*.fit*dat;;*.dat;;*.*" );
54 connect(
te_data, SIGNAL( US_EditorLoadComplete( QString ) ),
57 QFontMetrics fm(
te_data->
e->font() );
59 te_data->setMinimumHeight( fm.height() * 20 );
60 te_data->setMinimumWidth ( fm.width(
"11 : 6.34567, 0.00567890 " ) );
61 te_data->
e->setToolTip( tr(
"Loaded, editable meniscus,rmsd table" ) );
63 leftLayout->addWidget(
te_data, 0, 0, 20, 1 );
68 tr(
"Radius" ), tr(
"2DSA Meniscus RMSD Value" ) );
72 pick->setRubberBand( QwtPicker::VLineRubberBand );
79 meniscus_plot->setToolTip( tr(
"Fitted meniscus,rmsd plot" ) );
81 rightLayout->addLayout( plot, 0, 1, 20, 1 );
84 QLabel* lb_status =
us_label( tr(
"Status:" ) );
88 tr(
"Results of the last action performed" ) );
90 QLabel* lb_order =
us_label( tr(
"Fit Order:" ) );
96 sb_order->setToolTip( tr(
"Order of fitting curve" ) );
99 QLabel* lb_fit =
us_label( tr(
"Meniscus selected:" ) );
103 tr(
"Selected-minimum/Editable meniscus radius value" ) );
105 QLabel* lb_rms_error =
us_label( tr(
"RMS Error:" ) );
109 tr(
"RMS error of curve to meniscus,rmsd points" ) );
120 tr(
"Update edit record with meniscus; remove non-chosen models" ) );
126 tr(
"Scan fit-meniscus models in DB; create local table files" ) );
132 tr(
"Pop up confirmation dialogs at each update step" ) );
134 tr(
"Apply the meniscus update to all wavelengths of"
135 " the current cell/channel" ) );
140 tr(
"Plot,analyze meniscus,rmsd from current text" ) );
145 tr(
"Clear text,plot and various other controls" ) );
148 connect( pb_help, SIGNAL( clicked() ), SLOT(
help() ) );
150 tr(
"Open a dialog with detailed documentation" ) );
153 connect( pb_accept, SIGNAL( clicked() ), SLOT( close() ) );
154 pb_accept->setToolTip(
155 tr(
"Close this dialog and exit the program" ) );
159 cntrlsLayout->addWidget( lb_status, row, 0, 1, 1 );
160 cntrlsLayout->addWidget(
le_status, row++, 1, 1, 15 );
161 cntrlsLayout->addWidget( lb_order, row, 0, 1, 2 );
162 cntrlsLayout->addWidget(
sb_order, row, 2, 1, 1 );
163 cntrlsLayout->addWidget( lb_fit, row, 3, 1, 5 );
164 cntrlsLayout->addWidget(
le_fit, row, 8, 1, 3 );
165 cntrlsLayout->addWidget( lb_rms_error, row, 11, 1, 2 );
166 cntrlsLayout->addWidget(
le_rms_error, row++, 13, 1, 3 );
167 cntrlsLayout->addLayout(
dkdb_cntrls, row, 0, 1, 6 );
168 cntrlsLayout->addWidget(
pb_update, row, 6, 1, 5 );
169 cntrlsLayout->addWidget(
pb_scandb, row++, 11, 1, 5 );
170 cntrlsLayout->addWidget(
ck_confirm, row, 0, 1, 8 );
171 cntrlsLayout->addWidget(
ck_applymwl, row++, 8, 1, 8 );
172 cntrlsLayout->addWidget(
pb_plot, row, 0, 1, 4 );
173 cntrlsLayout->addWidget(
pb_reset, row, 4, 1, 4 );
174 cntrlsLayout->addWidget( pb_help, row, 8, 1, 4 );
175 cntrlsLayout->addWidget( pb_accept, row, 12, 1, 4 );
178 topLayout ->addLayout( leftLayout );
179 topLayout ->addLayout( rightLayout );
180 topLayout ->setStretchFactor( leftLayout, 1 );
181 topLayout ->setStretchFactor( rightLayout, 2 );
182 bottomLayout->addLayout( cntrlsLayout );
184 mainLayout ->addLayout( topLayout );
185 mainLayout ->addLayout( bottomLayout );
186 mainLayout ->setStretchFactor( topLayout, 2 );
187 mainLayout ->setStretchFactor( bottomLayout, 0 );
213 QString contents =
te_data->
e->toPlainText();
214 contents.replace( QRegExp(
"[^0-9eE\\.\\n\\+\\-]+" ),
" " );
216 QStringList lines = contents.split(
"\n", QString::SkipEmptyParts );
219 QVector< double > vradi( lines.size() );
220 QVector< double > vrmsd( lines.size() );
221 double* radius_values = vradi.data();
222 double* rmsd_values = vrmsd.data();
233 for (
int ii = 0; ii < lines.size(); ii++ )
235 QStringList values = lines[ ii ].split(
' ', QString::SkipEmptyParts );
237 if ( values.size() > 1 )
239 if ( values.size() > 2 ) values.removeFirst();
241 double radius = values[ 0 ].toDouble();
242 if ( radius < 5.7 || radius > 7.3 )
continue;
244 radius_values[ count ] = radius;
245 rmsd_values [ count ] = values[ 1 ].toDouble();
248 minx =
min( minx, radius_values[ count ] );
249 maxx =
max( maxx, radius_values[ count ] );
251 miny =
min( miny, rmsd_values[ count ] );
252 maxy =
max( maxy, rmsd_values[ count ] );
257 parsed << QString().sprintf(
"%2d : ", ii + 1 ) +
258 QString::number( radius_values[ count ],
'f', 5 ) +
", " +
259 QString::number( rmsd_values [ count ],
'f', 8 );
265 if ( count < 3 )
return;
267 te_data->
e->setPlainText( parsed.join(
"\n" ) );
269 double overscan = ( maxx - minx ) * 0.10;
272 minx - overscan, maxx + overscan );
275 double dy = fabs( maxy - miny ) / 10.0;
277 meniscus_plot->setAxisScale( QwtPlot::yLeft, miny - dy, maxy + dy );
282 raw_curve->setData( radius_values, rmsd_values, count );
290 if ( !
US_Matrix::lsfit( c, radius_values, rmsd_values, count, order + 1 ) )
292 QMessageBox::warning(
this,
293 tr(
"Data Problem" ),
294 tr(
"The data is inadequate for this fit order" ) );
303 int fit_count = (int) ( ( maxx - minx + 2 * overscan ) / 0.001 );
305 QVector< double > vfitx( fit_count );
306 QVector< double > vfity( fit_count );
307 double* fit_x = vfitx.data();
308 double* fit_y = vfity.data();
309 double x = minx - overscan;
312 for (
int i = 0; i < fit_count; i++, x += 0.001 )
317 for (
int j = 1; j <= order; j++ )
318 fit_y[ i ] += c[ j ] * pow( x, j );
322 double rms_err = 0.0;
324 for (
int i = 0; i < count; i++ )
326 double x = radius_values[ i ];
327 double y = rmsd_values [ i ];
329 double y_calc = c[ 0 ];
331 for (
int j = 1; j <= order; j++ )
332 y_calc += c[ j ] * pow( x, j );
334 rms_err +=
sq ( fabs ( y_calc - y ) );
337 le_rms_error->setText( QString::number( sqrt( rms_err / count ),
'e', 5 ) );
344 minimum = - c[ 1 ] / ( 2.0 * c[ 2 ] );
353 for (
int i = 0; i < order; i++ )
354 dxdy[ i ] = c[ i + 1 ] * ( i + 1 );
357 for (
int i = 0; i < order - 1; i++ )
358 d2xdy2[ i ] = dxdy[ i + 1 ] * ( i + 1 );
363 minimum = - q[ 1 ] / ( 2.0 * q[ 2 ] );
374 for (
int i = 1; i < order; i++ ) f += dxdy[ i ] * pow( minimum, i );
377 f_prime = d2xdy2[ 0 ];
378 for (
int i = 1; i < order - 1; i++ )
379 f_prime += d2xdy2[ i ] * pow( minimum, i );
381 if ( fabs( f ) <
epsilon )
break;
382 if ( k++ > 10 )
break;
385 minimum -= f / f_prime;
392 fit_curve->setData( fit_x, fit_y, fit_count );
399 double radius_min[ 2 ];
400 double rmsd_min [ 2 ];
402 radius_min[ 0 ] = minimum;
403 radius_min[ 1 ] = minimum;
405 rmsd_min [ 0 ] = miny - 1.0 * dy;
406 rmsd_min [ 1 ] = miny + 2.0 * dy;
411 le_fit->setText( QString::number( minimum,
'f', 5 ) );
414 QPen markerPen( QBrush( Qt::white ), 3.0 );
415 markerPen.setWidth( 3 );
417 QwtPlotMarker* pm =
new QwtPlotMarker();
418 QwtText label( QString::number( minimum,
'f', 5 ) );
419 QFont font( pm->label().font() );
421 font.setBold(
true );
422 font.setPointSize( font.pointSize() + 1 );
423 label.setFont( font );
425 pm->setValue( minimum, miny + 3.0 * dy );
426 pm->setSymbol( QwtSymbol( QwtSymbol::Cross,
427 QBrush( Qt::white ), markerPen, QSize( 9, 9 ) ) );
428 pm->setLabel( label );
429 pm->setLabelAlignment( Qt::AlignTop );
445 if ( ! filei.open( QIODevice::ReadOnly | QIODevice::Text ) )
452 bool rmv_mdls =
true;
469 QTextStream ts( &filei );
470 while ( !ts.atEnd() )
471 edtext += ts.readLine() +
"\n";
474 menv =
le_fit->text().toDouble();
475 mlsx = edtext.indexOf(
"<meniscus radius=" );
476 if ( mlsx < 0 )
return;
477 meqx = edtext.indexOf(
"=\"", mlsx );
479 mvcn = edtext.indexOf(
"\"", mvsx + 1 ) - mvsx;
480 llsx = edtext.indexOf(
"<data_range left=" );
481 if ( llsx < 0 )
return;
482 leqx = edtext.indexOf(
"=\"", llsx );
484 lvcn = edtext.indexOf(
"\"", lvsx + 1 ) - lvsx;
485 lefv = edtext.mid( lvsx, lvcn ).toDouble();
486 DbgLv(1) <<
" eupd: menv" << menv <<
"lefv" << lefv;
490 QMessageBox::warning(
this, tr(
"Meniscus within Data Range" ),
491 tr(
"The selected Meniscus value, %1 , extends into the data"
492 " range whose left-side value is %2 . This Edit update"
493 " cannot be performed!" ).arg( menv ).arg( lefv ) );
497 edtext = edtext.replace( mvsx, mvcn,
le_fit->text() );
498 mlnn = edtext.indexOf(
">", mlsx ) - mlsx + 1;
502 if ( ! fileo.open( QIODevice::WriteOnly | QIODevice::Text ) )
507 QTextStream tso( &fileo );
511 mmsg = tr(
"In file directory\n " ) +
filedir +
" ,\n" +
512 tr(
"file\n " ) + fname_edit +
"\n" +
513 tr(
"has been modified with the line:\n " ) +
514 edtext.mid( mlsx, mlnn );
525 mmsg += tr(
"\n\nDo you want to remove all fit-meniscus models"
526 " (and associated noises) except for the one"
527 " associated with the nearest meniscus value?" );
529 int response = QMessageBox::question(
this, tr(
"Edit File Updated" ),
530 mmsg, QMessageBox::Yes, QMessageBox::Cancel );
531 rmv_mdls = ( response == QMessageBox::Yes );
538 menv =
le_fit->text().toDouble();
540 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
542 for (
int jj = 0; jj <
nedtfs; jj++ )
545 DbgLv(1) <<
" eupd: jj" << jj <<
"fn" << fn;
548 if ( ! filei.open( QIODevice::ReadOnly | QIODevice::Text ) )
551 QTextStream ts( &filei );
553 while ( !ts.atEnd() )
554 edtext += ts.readLine() +
"\n";
557 mlsx = edtext.indexOf(
"<meniscus radius=" );
558 if ( mlsx < 0 )
continue;
559 meqx = edtext.indexOf(
"=\"", mlsx );
561 mvcn = edtext.indexOf(
"\"", mvsx + 1 ) - mvsx;
562 llsx = edtext.indexOf(
"<data_range left=" );
563 if ( llsx < 0 )
continue;
564 leqx = edtext.indexOf(
"=\"", llsx );
566 lvcn = edtext.indexOf(
"\"", lvsx + 1 ) - lvsx;
567 lefv = edtext.mid( lvsx, lvcn ).toDouble();
571 QMessageBox::warning(
this, tr(
"Meniscus within Data Range" ),
572 tr(
"The selected Meniscus value, %1 , extends into the data"
573 " range whose left-side value is %2 . This Edit update"
574 " cannot be performed!" ).arg( menv ).arg( lefv ) );
578 edtext = edtext.replace( mvsx, mvcn,
le_fit->text() );
579 mlnn = edtext.indexOf(
">", mlsx ) - mlsx + 1;
581 DbgLv(1) <<
" eupd: mlsx mlnn" << mlsx << mlnn;
584 if ( ! fileo.open( QIODevice::WriteOnly | QIODevice::Text ) )
587 QTextStream tso( &fileo );
600 QApplication::restoreOverrideCursor();
601 QApplication::restoreOverrideCursor();
602 mmsg = tr(
"In file directory\n " ) +
filedir +
" ,\n" +
603 tr(
"file\n " ) + fname_edit +
"\n" +
604 tr(
"has been modified with the line:\n " ) +
605 edtext.mid( mlsx, mlnn ) +
606 tr(
"\n\n%1 other cell/channel files were"
607 " similarly modified." ).arg( nedtfs - 1 ) + dmsg;
611 mmsg += tr(
"\n\nDo you want to remove all fit-meniscus models"
612 " (and associated noises) except for the one"
613 " associated with the nearest meniscus value?" );
615 int response = QMessageBox::question(
this, tr(
"Edit File Updated" ),
616 mmsg, QMessageBox::Yes, QMessageBox::Cancel );
618 rmv_mdls = ( response == QMessageBox::Yes );
626 DbgLv(1) <<
" call Remove Models";
632 mmsg += tr(
"\n\nAll fit-meniscus models (and associated noises),"
633 " except for the one set associated with the nearest"
634 " meniscus value, were removed." );
636 QMessageBox::information(
this, tr(
"Edit File Updated" ), mmsg );
643 filedir = fn.section(
"/", 0, -2 );
646 QString edittrip =
fname_load.section(
".", -3, -3 );
647 QString editID = edittrip.section(
"-", 0, -2 ).mid( 1 );
648 QString tripnode = edittrip.section(
"-", -1, -1 );
649 QString runID =
filedir.section(
"/", -1, -1 );
650 QString celchn = tripnode.left( 1 ) +
"." +
651 tripnode.mid( 1, 1 );
652 QString tripl = tripnode.left( 1 ) +
"." +
653 tripnode.mid( 1, 1 ) +
"." +
656 edtfilt << runID +
"." + editID +
".*." + celchn +
".*.xml";
659 edtfiles = QDir(
filedir ).entryList( edtfilt, QDir::Files, QDir::Name );
660 DbgLv(1) <<
"EDITFILT" << edtfilt;
665 for (
int jj = 0; jj <
nedtfs; jj++ )
667 if (
edtfiles.at( jj ).contains( tripl ) )
680 QMessageBox::warning(
this,
681 tr(
"Missing Local Edit" ),
682 tr(
"Update Edit is not possible\n"
683 "without a local copy of the Edit file\n"
684 "corresponding to the FM models.\n"
685 "Use\n Convert Legacy Data\nand\n Manage Data\n"
686 "to create a local copy of an Edit file for\n " )
698 QList< ModelDesc > mDescrs;
716 QRegExp fmIter = QRegExp(
"i\?\?-m*",
717 Qt::CaseSensitive, QRegExp::Wildcard );
719 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
724 tr(
"Scanning DB fit-meniscus models ..." ) );
725 query <<
"get_model_desc" << invID;
731 QString modelID = db.value( 0 ).toString();
732 QString modelGUID = db.value( 1 ).toString();
733 QString descript = db.value( 2 ).toString();
734 QString editGUID = db.value( 5 ).toString();
735 QString editID = db.value( 6 ).toString();
737 if ( descript.length() == 80 )
746 double variance = db.value( 3 ).toString().toDouble();
747 double meniscus = db.value( 4 ).toString().toDouble();
748 QDateTime lmtime = db.value( 7 ).toDateTime();
749 lmtime.setTimeSpec( Qt::UTC );
750 QString ansysID = descript.section(
'.', -2, -2 );
751 QString iterID = ansysID .section(
'_', -1, -1 );
752 DbgLv(1) <<
"DbSc: modelID vari meni" << modelID << variance << meniscus
753 <<
"ansysID" << ansysID <<
"iterID" << iterID;
755 if ( ansysID.contains(
"2DSA-FM" ) || iterID.contains( fmIter ) )
757 DbgLv(1) <<
"DbSc: *FIT* " << descript;
760 QString runID = descript.section(
'.', 0, -4 );
761 QString tripleID = descript.section(
'.', -3, -3 );
762 QString editLabel = ansysID .section(
'_', 0, -5 );
763 QString ftfname = runID +
"/2dsa-fm." + editLabel +
764 "-" + tripleID +
".fitmen.dat";
766 mdescr.
baseDescr = runID +
"." + tripleID +
"."
767 + ansysID.section(
"-", 0, 3 );
775 mdescr.
antime = descript.section(
'.', -2, -2 )
776 .section(
'_', 1, 1 ).mid( 1 );
782 DbgLv(1) <<
"DbSc: tmodels size" << tmodels.size() <<
"ted sizes"
783 << tedGIDs.size() << tedIDs.size();
785 for (
int ii = 0; ii < tmodels.size(); ii++ )
787 QString modelID = tmodels[ ii ];
789 query <<
"get_model_info" << modelID;
796 QString modelGUID = db.value( 0 ).toString();
797 QString descript1 = db.value( 1 ).toString();
798 QString contents = db.value( 2 ).toString();
799 int jdx = contents.indexOf(
"description=" );
803 if ( jdx < 1 )
continue;
806 QString descript = contents.mid( jdx ).section(
'"', 1, 1 );
807 double variance = db.value( 3 ).toString().toDouble();
808 double meniscus = db.value( 4 ).toString().toDouble();
809 QString editGUID = tedGIDs[ ii ];
810 QString editID = tedIDs [ ii ];
812 QDateTime lmtime = db.value( 6 ).toDateTime();
813 lmtime.setTimeSpec( Qt::UTC );
814 QString ansysID = descript.section(
'.', -2, -2 );
815 QString iterID = ansysID .section(
'_', -1, -1 );
818 if ( ansysID.contains(
"2DSA-FM" ) || iterID.contains( fmIter ) )
820 DbgLv(1) <<
"DbSc: *FIT* " << descript;
824 QString runID = descript.section(
'.', 0, -4 );
825 QString tripleID = descript.section(
'.', -3, -3 );
826 QString editLabel = ansysID .section(
'_', 0, -5 );
827 QString ftfname = runID +
"/2dsa-fm." + editLabel +
828 "-" + tripleID +
".fitmen.dat";
830 mdescr.
baseDescr = runID +
"." + tripleID +
"."
831 + ansysID.section(
"-", 0, 3 );
839 mdescr.
antime = descript.section(
'.', -2, -2 )
840 .section(
'_', 1, 1 ).mid( 1 );
847 nfmods = mDescrs.size();
848 DbgLv(1) <<
"Number of FM models found: " << nfmods;
850 DbgLv(1) <<
" pre:D0" << mDescrs[0].description;
851 DbgLv(1) <<
" pre:Dn" << mDescrs[nfmods-1].description; }
854 DbgLv(1) <<
" sorted:D0" << mDescrs[0].description;
855 DbgLv(1) <<
" sorted:Dn" << mDescrs[nfmods-1].description; }
860 tr(
"Comparing to existing local meniscus,rmsd table files ..." ) );
865 for (
int ii = 0; ii < nfmods; ii++ )
867 QString ftfname = mDescrs[ ii ].fitfname;
868 QString antime = mDescrs[ ii ].antime;
870 if ( ! ufnams.contains( ftfname ) )
876 else if ( ! uantms.contains( antime ) )
881 mfnams << mDescrs[ ii ].fitfname;
884 nfsets = ufnams.size();
885 int nantm = uantms.size();
886 int ndupl = nantm - nfsets;
887 DbgLv(1) <<
"Number of FM analysis sets: " << nfsets;
888 DbgLv(1) <<
"Number of FM analysis set duplicates: " << ndupl;
893 for (
int ii = 0; ii < kfsets; ii++ )
895 QString ftfname = ufnams.at( ii );
897 if ( mfnams.count( ftfname ) == 1 )
903 QString ftfpath = rdir + ftfname;
904 QFile ftfile( ftfpath );
906 if ( ftfile.exists() )
908 QString ftfpath = rdir + ftfname;
909 QDateTime fdate = QFileInfo( ftfile ).lastModified().toUTC();
910 int jj = mfnams.lastIndexOf( ftfname );
911 QDateTime rdate = mDescrs[ jj ].lmtime;
912 DbgLv(1) <<
" ii rdate fdate" << ii << rdate << fdate <<
" ftfname"
913 << ftfname <<
" fdate.msecsTo(rdate)" << fdate.msecsTo(rdate);
914 DbgLv(1) <<
" jj desc" << jj << mDescrs[jj].description
915 <<
"antime meniscus" << mDescrs[jj].antime << mDescrs[jj].meniscus;
917 if ( fdate.msecsTo( rdate ) > 0 )
933 QString ftfpath = QString( rdir + ftfname ).section(
"/", 0, -2 );
934 QDir().mkpath( ftfpath );
937 if ( ! ftfile.open( QIODevice::WriteOnly | QIODevice::Text ) )
939 qDebug() <<
"*ERROR* Unable to open file" << ftfname;
944 int jfirst = mfnams.indexOf( ftfname );
945 int jlast = mfnams.lastIndexOf( ftfname ) + 1;
946 QString antiml = mDescrs[ jlast - 1 ].antime;
949 DbgLv(1) <<
" Creating" << ftfname <<
"jf,jl" << jfirst << jlast;
950 for (
int jj = jfirst; jj < jlast; jj++ )
952 double meniscus = mDescrs[ jj ].meniscus;
953 double variance = mDescrs[ jj ].variance;
954 double rmsd = sqrt( variance );
955 QString antime = mDescrs[ jj ].antime;
956 DbgLv(1) <<
" jj desc" << jj << mDescrs[jj].description;
957 if ( antime == antiml )
958 mrpairs << QString::number( meniscus,
'f', 6 ) +
" "
959 + QString::number( rmsd,
'e', 6 );
963 QTextStream ts( &ftfile );
966 for (
int jj = 0; jj < mrpairs.size(); jj++ )
967 ts << mrpairs.at( jj ) +
"\n";
971 fnamesv = fnamesv.isEmpty() ? ftfname : fnamesv;
974 DbgLv(1) <<
"Number of FM REPLACE sets: " << nfrpls;
975 DbgLv(1) <<
"Number of FM ADD sets: " << nfadds;
976 DbgLv(1) <<
"Number of FM EXISTING sets: " << nfexss;
979 QString msg = tr(
"File" );
980 int nftota = nfadds + nfrpls;
982 if ( nfadds == 1 && nfrpls == 0 )
983 msg += tr(
" added: " );
985 else if ( nfadds == 0 && nfrpls == 1 )
986 msg += tr(
" updated: " );
988 else if ( nfadds == 0 && nfrpls == 0 )
989 msg = tr(
"No new fit files were created." );
992 msg = tr(
"Last of %1 added/updated: " ).arg( nftota );
998 QApplication::restoreOverrideCursor();
999 QApplication::restoreOverrideCursor();
1012 int elnx = edtext.indexOf(
"<editGUID " );
1013 int esvx = edtext.indexOf(
"\"", elnx ) + 1;
1014 int nvch = edtext.indexOf(
"\"", esvx ) - esvx;
1015 QString edGUID = edtext.mid( esvx, nvch );
1016 DbgLv(1) <<
"updDbEd: edGUID" << edGUID;
1021 query <<
"get_editID" << edGUID;
1024 idEdit = db.value( 0 ).toString().toInt();
1026 db.writeBlobToDB( efilepath,
"upload_editData",
idEdit );
1030 msg += tr(
"\n\nThe meniscus value was also updated for the"
1031 " corresponding edit record in the database." );
1036 QString fn = efilepath.section(
"/", -1, -1 );
1040 msg += tr(
"\n\nThe meniscus value was also updated for the"
1041 " corresponding edit records in the database." );
1051 QString srchRun =
filedir.section(
"/", -1, -1 );
1052 QString srchEdit =
fname_load.section(
".", -3, -3 );
1053 QString srchTrip = srchEdit.section(
"-", -1, -1 );
1054 srchEdit = srchEdit.section(
"-", 0, -2 );
1055 DbgLv(1) <<
"RmvMod: scn1 srchRun srchEdit srchTrip"
1056 << srchRun << srchEdit << srchTrip;
1059 QStringList modfilt;
1060 modfilt <<
"M*.xml";
1062 QStringList modfiles = QDir( moddir ).entryList(
1063 modfilt, QDir::Files, QDir::Name );
1064 moddir = moddir +
"/";
1065 double cmeniscus =
le_fit->text().toDouble();
1067 QList< ModelDesc > lMDescrs;
1068 QList< ModelDesc > dMDescrs;
1070 QStringList lmodFnams;
1071 QStringList lmodGUIDs;
1072 QList< double > lmodVaris;
1073 QList< double > lmodMenis;
1074 QStringList lmodDescs;
1076 QStringList dmodIDs;
1077 QStringList dmodGUIDs;
1078 QList< double > dmodVaris;
1079 QList< double > dmodMenis;
1080 QStringList dmodDescs;
1091 for (
int ii = 0; ii < modfiles.size(); ii++ )
1094 QString modfname = modfiles.at( ii );
1095 QString modpath = moddir + modfname;
1102 QString runID = descript.section(
'.', 0, -4 );
1103 QString tripID = descript.section(
'.', -3, -3 );
1104 QString anRunID = descript.section(
'.', -2, -2 );
1105 QString editLabl = anRunID .section(
'_', 0, -5 );
1109 if ( runID != srchRun || editLabl != srchEdit || tripID != srchTrip )
1112 QString iterID = anRunID .section(
'_', -1, -1 );
1115 if ( iterID.length() != 10 || ! iterID.contains(
"-m" ) )
1119 int arTime = anRunID .section(
'_', -4, -4 ).mid( 1 ).toInt();
1120 DbgLv(1) <<
"RmvMod: arTime lArTime" << arTime << lArTime;
1122 if ( arTime > lArTime )
1133 else if ( arTime < lArTime )
1138 lmodFnams << modpath;
1152 nlmods = lMDescrs.size();
1154 DbgLv(1) <<
"RmvMod: nlmods" << nlmods;
1155 double minMdif = 99e+10;
1157 for (
int ii = 0; ii < nlmods; ii++ )
1160 double diffMen = qAbs( lmodd.
meniscus - cmeniscus );
1161 DbgLv(1) <<
"low Mdif scan: ii vari meni desc" << ii << lmodd.
variance
1164 if ( diffMen < minMdif )
1171 DbgLv(1) <<
"RmvMod: minMdif lkModx" << minMdif << lkModx;
1172 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1179 QString edtID = QString::number(
idEdit );
1186 query <<
"get_model_desc_by_editID" << invID << edtID;
1189 query <<
"get_model_desc" << invID;
1191 DbgLv(1) <<
"RmvMod: idEdit" <<
idEdit <<
"query" << query;
1196 QString modelID = db.value( 0 ).toString();
1197 QString descript = db.value( 2 ).toString();
1198 QString runID = descript.section(
'.', 0, 0 );
1199 if ( runID == srchRun )
1205 for (
int ii = 0; ii < modIDs.size(); ii++ )
1207 QString modelID = modIDs.at( ii );
1209 query <<
"get_model_info" << modelID;
1212 if ( db.lastErrno() !=
US_DB2::OK )
continue;
1216 QString modelGUID = db.value( 0 ).toString();
1217 QString descript1 = db.value( 1 ).toString();
1218 QString contents = db.value( 2 ).toString();
1219 int jdtx = contents.indexOf(
"description=" );
1221 if ( jdtx < 1 )
continue;
1223 int jdx = contents.indexOf(
"\"", jdtx ) + 1;
1224 int lend = contents.indexOf(
"\"", jdx ) - jdx;
1225 QString descript = contents.mid( jdx, lend );
1226 double variance = db.value( 3 ).toString().toDouble();
1227 double meniscus = db.value( 4 ).toString().toDouble();
1228 QString runID = descript.section(
'.', 0, -4 );
1229 QString tripID = descript.section(
'.', -3, -3 );
1230 QString anRunID = descript.section(
'.', -2, -2 );
1231 QString editLabl = anRunID .section(
'_', 0, -5 );
1235 if ( runID != srchRun || editLabl != srchEdit
1236 || tripID != srchTrip )
1239 QString iterID = anRunID .section(
'_', -1, -1 );
1242 if ( iterID.length() != 10 || ! iterID.contains(
"-m" ) )
1246 int arTime = anRunID .section(
'_', -4, -4 ).mid( 1 ).toInt();
1248 if ( arTime > dArTime )
1259 else if ( arTime < dArTime )
1265 dmodGUIDs << modelGUID;
1266 dmodVaris << variance;
1267 dmodMenis << meniscus;
1268 dmodDescs << descript;
1276 DbgLv(1) <<
"RmvMod: scn2 ii dmodDesc" << descript;
1279 ndmods = dMDescrs.size();
1282 if ( dArTime > lArTime )
1284 else if ( lArTime > dArTime )
1287 DbgLv(1) <<
"RmvMod: ndmods" << ndmods;
1288 double minMdif = 99e+10;
1290 for (
int ii = 0; ii < ndmods; ii++ )
1293 double diffMen = qAbs( dmodd.
meniscus - cmeniscus );
1294 DbgLv(1) <<
"low Mdif scan: ii vari meni desc" << ii << dmodd.
variance
1297 if ( diffMen < minMdif )
1301 DbgLv(1) <<
"low Mdif scan: minMdif dkModx" << minMdif << dkModx;
1306 if ( nlmods == ndmods || ( ndmods > 0 && nlmods == 0 ) )
1310 for (
int jj = 0; jj < nlmods; jj++ )
1325 for (
int jj = 0; jj < ndmods; jj++ )
1328 dmodIDs [ jj ] = dmodd.
modelID;
1335 if ( nmatch == nlmods )
1337 DbgLv(1) <<
"++local/dbase match, or local only";
1342 DbgLv(1) <<
"**local/dbase DO NOT MATCH";
1343 DbgLv(1) <<
" nmatch ndmods nlmods" << nmatch << ndmods << nlmods;
1348 else if ( nlmods == 0 )
1350 DbgLv(1) <<
"++only dbase records exist";
1353 else if ( ndmods == 0 )
1355 DbgLv(1) <<
"++only local records exist";
1360 DbgLv(1) <<
"**local/dbase DO NOT MATCH in count";
1361 DbgLv(1) <<
" nlmods ndmods" << nlmods << ndmods;
1366 DbgLv(1) <<
" nlmods ndmods" << nlmods << ndmods;
1367 if ( ndmods > 0 || nlmods > 0 )
1371 QStringList rmodIDs;
1372 QStringList rmodDescs;
1373 QStringList rmodFnams;
1374 QStringList rnoiIDs;
1375 QStringList rnoiFnams;
1376 QStringList rnoiDescs;
1377 QStringList nieDescs;
1379 QStringList nieFnams;
1384 int ntmods = ( ndmods > 0 ) ? ndmods : nlmods;
1385 int ikModx = ( ndmods > 0 ) ? dkModx : lkModx;
1386 DbgLv(1) <<
" ntmods ikModx" << ntmods << ikModx;
1388 QString modDesc =
"";
1390 for (
int jj = 0; jj < ntmods; jj++ )
1406 fname = lmodFnams[ jj ];
1407 mDesc = lmodDescs[ jj ];
1415 mID = dmodIDs [ jj ];
1416 mDesc = dmodDescs[ jj ];
1425 if ( modDesc.isEmpty() )
1428 DbgLv(1) <<
"RmvMod: 1st rmv-mod: jj modDesc" << jj << modDesc;
1433 tiDesc = QString( mDesc ).replace(
".model",
".ti_noise" );
1434 riDesc = QString( mDesc ).replace(
".model",
".ri_noise" );
1435 itix = nieDescs.indexOf( tiDesc );
1436 irix = nieDescs.indexOf( riDesc );
1440 noiID = nieIDs [ itix ];
1441 noiFname = nieFnams[ itix ];
1443 if ( noiID !=
"-1" )
1446 if ( ! noiFname.isEmpty() )
1452 rnoiFnams << noiFname;
1453 rnoiDescs << tiDesc;
1458 noiID = nieIDs [ irix ];
1459 noiFname = nieFnams[ irix ];
1461 if ( noiID !=
"-1" )
1464 if ( ! noiFname.isEmpty() )
1470 rnoiFnams << noiFname;
1471 rnoiDescs << riDesc;
1475 QApplication::restoreOverrideCursor();
1476 QApplication::restoreOverrideCursor();
1478 nlnois = nlrnoi + ( nlrnoi > nlrmod ? 2 : 1 );
1479 ndnois = ndrnoi + ( ndrnoi > ndrmod ? 2 : 1 );
1480 bool rmv_mdls =
true;
1481 DbgLv(1) <<
"RmvMod: nlrmod ndrmod nlrnoi ndrnoi nlnois ndnois"
1482 << nlrmod << ndrmod << nlrnoi << ndrnoi << nlnois << ndnois;
1485 QString msg = tr(
"%1 local model files;\n"
1486 "%2 database model files;\n"
1487 "%3 local noise files;\n"
1488 "%4 database noise files;\n"
1489 "have been identified for removal.\n\n"
1490 "Do you really want to delete them?" )
1491 .arg( nlrmod ).arg( ndrmod ).arg( nlrnoi ).arg( ndrnoi );
1493 int response = QMessageBox::question(
this,
1494 tr(
"Remove Models and Noises?" ),
1495 msg, QMessageBox::Yes, QMessageBox::Cancel );
1496 rmv_mdls = ( response == QMessageBox::Yes );
1508 DbgLv(1) <<
" Remove Models and Noises";
1509 for (
int ii = 0; ii < rmodIDs.size(); ii++ )
1511 recID = rmodIDs [ ii ];
1512 recDesc = rmodDescs[ ii ];
1513 recFname = rmodFnams[ ii ];
1514 DbgLv(1) <<
" Delete: " << recID << recFname.section(
"/",-1,-1) << recDesc;
1516 if ( ! recFname.isEmpty() )
1518 QFile recf( recFname );
1519 if ( recf.exists() )
1521 if ( recf.remove() )
1522 {
DbgLv(1) <<
" local file removed"; }
1523 else { qDebug() <<
"*ERROR* removing" << recFname; }
1525 else { qDebug() <<
"*ERROR* does not exist:" << recFname; }
1528 if ( recID !=
"-1" && dbP != NULL )
1531 query <<
"delete_model" << recID;
1534 qDebug() <<
"delete_model error" << stat;
1535 else DbgLv(1) <<
" DB record deleted";
1545 for (
int ii = 0; ii < rnoiIDs.size(); ii++ )
1547 recID = rnoiIDs [ ii ];
1548 recDesc = rnoiDescs[ ii ];
1549 recFname = rnoiFnams[ ii ];
1550 DbgLv(1) <<
" Delete: " << recID << recFname.section(
"/",-1,-1) << recDesc;
1552 if ( ! recFname.isEmpty() )
1554 QFile recf( recFname );
1555 if ( recf.exists() )
1557 if ( recf.remove() )
1558 {
DbgLv(1) <<
" local file removed"; }
1559 else { qDebug() <<
"*ERROR* removing" << recFname; }
1561 else { qDebug() <<
"*ERROR* does not exist:" << recFname; }
1571 DbgLv(1) <<
"**NO local/dbase models-to-remove were found!!!!";
1574 QApplication::restoreOverrideCursor();
1580 QStringList& nieIDs, QStringList& nieFnams )
1582 QString msetBase = modDesc.section(
".", 0, -3 ) +
"." +
1583 modDesc.section(
".", -2, -2 ).section(
"_", 0, 3 );
1584 QString srchTlab = msetBase.section(
".", -2, -2 );
1585 QString srchTrip = srchTlab.left( 1 ) +
"." + srchTlab.mid( 1, 1 ) +
"." +
1586 srchTlab.mid( 2 ) +
".xml";
1587 QString srchRun = msetBase.section(
".", 0, -3 ) +
"." +
1588 msetBase.section(
".", -1, -1 )
1589 .section(
"_", 0, 0 ).mid( 1 );
1590 DbgLv(1) <<
"NIE: msetBase" << msetBase;
1597 QStringList noifilt;
1598 noifilt <<
"N*.xml";
1600 QStringList noifiles = QDir( noidir ).entryList(
1601 noifilt, QDir::Files, QDir::Name );
1602 noidir = noidir +
"/";
1603 DbgLv(1) <<
"NIE: noise-files-size" << noifiles.size();
1605 for (
int ii = 0; ii < noifiles.size(); ii++ )
1607 QString noiFname = noifiles.at( ii );
1608 QString noiPath = noidir + noiFname;
1615 DbgLv(1) <<
"NIE: ii noiDesc" << ii << noiDesc;
1617 if ( ! noiDesc.startsWith( msetBase ) )
1622 nieDescs << noiDesc;
1623 nieFnams << noiPath;
1624 DbgLv(1) <<
"NIE: noiFname" << noiFname;
1638 QStringList edtNams;
1641 query <<
"all_editedDataIDs" << invID;
1646 QString edtID = db.value( 0 ).toString();
1647 QString edtName = db.value( 2 ).toString();
1649 if ( edtName.startsWith( srchRun ) &&
1650 edtName.endsWith( srchTrip ) )
1654 DbgLv(1) <<
"NIE: edtID edtName" << edtID << edtName;
1657 DbgLv(1) <<
"NIE: edtIDs-size" << edtIDs.size();
1658 if ( edtIDs.size() > 0 )
DbgLv(1) <<
"NIE: edtName0" << edtNams[0];
1662 if ( edtIDs.size() == 1 )
1663 query <<
"get_noise_desc_by_editID" << invID << edtIDs[ 0 ];
1666 query <<
"get_noise_desc" << invID;
1672 QString noiID = db.value( 0 ).toString();
1673 QString edtID = db.value( 2 ).toString();
1674 DbgLv(1) <<
"NIE: noiID edtID" << noiID << edtID;
1676 if ( edtIDs.contains( edtID ) )
1679 DbgLv(1) <<
"NIE: nIDs-size" << nIDs.size() <<
"msetBase" << msetBase;
1681 for (
int ii = 0; ii < nIDs.size(); ii++ )
1683 QString noiID = nIDs[ ii ];
1690 DbgLv(1) <<
"NIE: ii noiID noiDesc" << ii << noiID << noiDesc;
1692 if ( ! noiDesc.startsWith( msetBase ) )
1700 nieDescs << noiDesc;
1704 DbgLv(1) <<
"NIE: usesDB" << usesDB <<
"nlnois" << nlnois
1705 <<
"nieDescs-size" << nieDescs.size() <<
"nieIDs-size" << nieIDs.size();