Skip to content

Commit

Permalink
Mods for 1.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rklasky committed Oct 3, 2022
1 parent 4e768e7 commit 977eed3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 102 deletions.
20 changes: 8 additions & 12 deletions MSSPM_GuiDiagnostic/nmfDiagnosticTab01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ nmfDiagnostic_Tab1::callback_RunPB()
}

for (QString parameterName : vectorParameterNames) {
//qDebug() << "\nprocessing parameterName: " << parameterName;
nmfUtilsQt::updateProgressDlg(m_Logger,progressDlg,"Processing parameter: "+parameterName.toStdString(),pInc);

EstParameter.clear();
Expand All @@ -571,8 +570,8 @@ nmfDiagnostic_Tab1::callback_RunPB()
m_Diagnostic_Tabs->setCursor(Qt::ArrowCursor);
return;
}
//qDebug() << "loaded name: " << parameterName;
//qDebug() << EstParameter;
qDebug() << "loaded name: " << parameterName;
qDebug() << EstParameter;
if (parameterName == surfaceParameter1Name) {
surfaceParameter1 = EstParameter;
} else if (parameterName == surfaceParameter2Name) {
Expand All @@ -591,23 +590,20 @@ nmfDiagnostic_Tab1::callback_RunPB()
// for certain species.
if (1) { // ((estParameter != 0) && (startVal != 0)) { // RSK revisit this logic
for (int j=0; j<=totalNumPoints; ++j) {
//if (i == 9 && parameterName == "SurveyQ") {
// qDebug() << "\nparameter name: " << parameterName << estParameter << startVal << inc << diagnosticParameterValue; // << fitness;
//}
if ((i == 8 or i == 9) && parameterName == "SurveyQ") {
qDebug() << "\nparameter name: " << i << parameterName << estParameter << startVal << inc << diagnosticParameterValue; // << fitness;
}

if ((estParameter == 0) || (startVal == 0)) {
aDiagnosticTuple = std::make_tuple(SpeciesOrGuildNames[i],j,0,0);
DiagnosticTupleVector.push_back(aDiagnosticTuple);
} else {
try {
parameterItem = std::make_pair(parameterName,diagnosticParameterValue);
//if (i == 9 && parameterName == "SurveyQ") {
// qDebug() << "before calculateFitness call";
//}
fitness = calculateFitness(i,{parameterItem});
//if (i == 9 && parameterName == "SurveyQ") {
//qDebug() << "after calculateFitness call, fitness: " << fitness;
//}
if ((i == 8 or i == 9) && parameterName == "SurveyQ") {
qDebug() << "after calculateFitness call, fitness: " << fitness;
}
} catch (...) {
msg = "Warning (2): Please run an Estimation prior to running this Diagnostic.";
m_Logger->logMsg(nmfConstants::Warning,msg.toStdString());
Expand Down
64 changes: 33 additions & 31 deletions MSSPM_GuiEstimation/nmfEstimationTab04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,6 @@ nmfEstimation_Tab4::nmfEstimation_Tab4(QTabWidget* tabs,
m_TableViewsTypeI.push_back(Estimation_Tab3_CompetitionAlphaMinTV);
m_TableViewsTypeI.push_back(Estimation_Tab3_CompetitionAlphaMaxTV);

m_TableViewsTypeII.clear();
m_TableViewsTypeII.push_back(Estimation_Tab4_HandlingTV);
m_TableViewsTypeII.push_back(Estimation_Tab4_HandlingMinTV);
m_TableViewsTypeII.push_back(Estimation_Tab4_HandlingMaxTV);

m_TableViewsTypeIII.clear();
m_TableViewsTypeIII.push_back(Estimation_Tab4_ExponentTV);
m_TableViewsTypeIII.push_back(Estimation_Tab4_ExponentMinTV);
m_TableViewsTypeIII.push_back(Estimation_Tab4_ExponentMaxTV);

m_TableNamesTypeI.clear();
m_TableNamesTypeI.push_back(nmfConstantsMSSPM::TablePredationRho);
m_TableNamesTypeI.push_back(nmfConstantsMSSPM::TablePredationRhoMin);
Expand All @@ -151,17 +141,27 @@ nmfEstimation_Tab4::nmfEstimation_Tab4(QTabWidget* tabs,
m_TableNamesTypeI.push_back(nmfConstantsMSSPM::TableCompetitionAlphaMin);
m_TableNamesTypeI.push_back(nmfConstantsMSSPM::TableCompetitionAlphaMax);

m_TableViewsTypeII.clear();
m_TableViewsTypeII.push_back(Estimation_Tab4_HandlingTV);
m_TableViewsTypeII.push_back(Estimation_Tab4_HandlingMinTV);
m_TableViewsTypeII.push_back(Estimation_Tab4_HandlingMaxTV);

m_TableNamesTypeII.clear();
m_TableNamesTypeII.push_back(nmfConstantsMSSPM::TablePredationHandling);
m_TableNamesTypeII.push_back(nmfConstantsMSSPM::TablePredationHandlingMin);
m_TableNamesTypeII.push_back(nmfConstantsMSSPM::TablePredationHandlingMax);
m_TableNamesTypeII.push_back("");
// m_TableNamesTypeII.push_back("");

m_TableViewsTypeIII.clear();
m_TableViewsTypeIII.push_back(Estimation_Tab4_ExponentTV);
m_TableViewsTypeIII.push_back(Estimation_Tab4_ExponentMinTV);
m_TableViewsTypeIII.push_back(Estimation_Tab4_ExponentMaxTV);

m_TableNamesTypeIII.clear();
m_TableNamesTypeIII.push_back(nmfConstantsMSSPM::TablePredationExponent);
m_TableNamesTypeIII.push_back(nmfConstantsMSSPM::TablePredationExponentMin);
m_TableNamesTypeIII.push_back(nmfConstantsMSSPM::TablePredationExponentMax);
m_TableNamesTypeIII.push_back("");
// m_TableNamesTypeIII.push_back("");

// Create models and attach to view
int NumSpecies = getNumSpecies();
Expand Down Expand Up @@ -398,7 +398,7 @@ nmfEstimation_Tab4::callback_SavePB()
return;
}

Estimation_Tabs->setCursor(Qt::WaitCursor);
QApplication::setOverrideCursor(Qt::WaitCursor);

// Get Species names
for (int j=0; j<m_smodels2d[0]->columnCount(); ++ j) {
Expand All @@ -408,32 +408,34 @@ nmfEstimation_Tab4::callback_SavePB()
if (isTypeI() || isTypeII() || isTypeIII()) { // save rho
if (! saveTables(isNotTypeIIITable, SpeNames,
m_TableViewsTypeI, m_TableNamesTypeI)) {
QApplication::restoreOverrideCursor();
return;
}
}

if (isTypeII() || isTypeIII()) { // save h
if (! saveTables(isNotTypeIIITable, SpeNames,
m_TableViewsTypeII, m_TableNamesTypeII)) {
QApplication::restoreOverrideCursor();
return;
}
}

if (isTypeIII()) { // save b
if (! saveTables(isTypeIIITable, SpeNames,
m_TableViewsTypeIII, m_TableNamesTypeIII)) {
QApplication::restoreOverrideCursor();
return;
}
}
QApplication::restoreOverrideCursor();

QMessageBox::information(Estimation_Tabs, "Predation Updated",
"\nPredation tables have been successfully updated.\n",
QMessageBox::Ok);

// Reload so that columns resize appropriately
loadWidgets();

Estimation_Tabs->setCursor(Qt::ArrowCursor);
}


Expand All @@ -444,28 +446,26 @@ nmfEstimation_Tab4::saveTables(const bool& isTypeIII,
const std::vector<QTableView*>& tableViews,
const std::vector<std::string>& tableNames)
{
bool tableChecksOK;
std::string cmd;
std::string errorMsg;
std::string value;
QModelIndex index;
QStandardItemModel* smodel;

// Check each of the 3 tableviews
if (! isTypeI() || (tableViews.size() != m_TableViewsTypeI.size()) ||
! nmfUtilsQt::runAllTableChecks(m_Logger,Estimation_Tabs,
tableViews[0],
tableViews[1],
tableViews[2],
tableViews[3],
tableViews[4],
tableViews[5])) {
return false;
if (isTypeI()) {
tableChecksOK = nmfUtilsQt::runAllTableChecks(
m_Logger,Estimation_Tabs,
tableViews[0], tableViews[1], tableViews[2],
tableViews[3], tableViews[4], tableViews[5]);
} else {
tableChecksOK = nmfUtilsQt::runAllTableChecks(
m_Logger,Estimation_Tabs,
tableViews[0], tableViews[1], tableViews[2]);
}
// else {
// m_Logger->logMsg(nmfConstants::Warning,"Number of Predation tables should be 6. Found instead: " + std::to_string(tableViews.size()));
// }

for (unsigned int k=0; k<tableViews.size(); ++k) {
cmd.clear();
smodel = qobject_cast<QStandardItemModel*>(tableViews[k]->model());
// Necessary if the user doesn't have any Competition
if ((smodel->rowCount() == 0) || (smodel->columnCount() == 0)) {
Expand All @@ -483,7 +483,6 @@ nmfEstimation_Tab4::saveTables(const bool& isTypeIII,
"\nError in Save command. Couldn't delete all records from " +
QString::fromStdString(tableNames[k]) + " table.\n",
QMessageBox::Ok);
Estimation_Tabs->setCursor(Qt::ArrowCursor);
return false;
}

Expand Down Expand Up @@ -518,6 +517,7 @@ nmfEstimation_Tab4::saveTables(const bool& isTypeIII,
}
}
}

cmd = cmd.substr(0,cmd.size()-1);
errorMsg = m_DatabasePtr->nmfUpdateDatabase(cmd);
if (nmfUtilsQt::isAnError(errorMsg)) {
Expand All @@ -526,7 +526,6 @@ nmfEstimation_Tab4::saveTables(const bool& isTypeIII,
QMessageBox::warning(Estimation_Tabs, "Error",
"\nError in Save command. Check that all cells are populated.\n",
QMessageBox::Ok);
Estimation_Tabs->setCursor(Qt::ArrowCursor);
return false;
}
}
Expand Down Expand Up @@ -901,10 +900,13 @@ nmfEstimation_Tab4::loadWidgets()
}
resetSpinBox(nonZeroCell,m_smodels2d[0],m_smodels2d[1],m_smodels2d[2]);
}
if (isTypeIII()) {

if (isTypeIII()) {
QStandardItemModel* smodel;
for (unsigned int k=0; k<m_TableNamesTypeIII.size(); ++k) {
// if (m_TableNamesTypeIII[k].empty()) {
// continue;
// }
if (isAggProd) {
smodel = new QStandardItemModel(NumGuilds, 1);
m_TableViewsTypeIII[k]->setModel(smodel);
Expand Down
27 changes: 12 additions & 15 deletions MSSPM_Main/nmfMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ void
nmfMainWindow::menu_about()
{
QString name = "Multi-Species Surplus Production Model";
QString version = "MSSPM v1.3.5 ";
QString version = "MSSPM v1.3.6 ";
QString specialAcknowledgement = "";
QString cppVersion = "C++??";
QString mysqlVersion = "?";
Expand Down Expand Up @@ -6379,9 +6379,7 @@ nmfMainWindow::callback_ShowChart(QString OutputType,
nmfConstantsMSSPM::TableOutputMSYFishing,
nmfConstantsMSSPM::TableOutputPredationExponent,
nmfConstantsMSSPM::TableOutputSurveyQ};
if (isExponent) {
OutputTableNames.push_back(nmfConstantsMSSPM::TableOutputPredationExponent);
}

QList<QString> TableLabels = {"B₀","r","K","q","BMSY","MSY","FMSY","b","Q"};
QList<QTableView*> TableViews = {InitBiomassTV,
GrowthRateTV,
Expand All @@ -6396,7 +6394,6 @@ nmfMainWindow::callback_ShowChart(QString OutputType,

if (! isAMohnsRhoMultiRun())
{

// Load 1d tables
m = 0;
for (int i=0; i<(int)OutputTableNames.size(); ++i) {
Expand All @@ -6423,6 +6420,7 @@ nmfMainWindow::callback_ShowChart(QString OutputType,
}
dataMap = m_DatabasePtr->nmfQueryDatabase(queryStr, fields);
NumRecords = dataMap["SpeName"].size();

if (NumRecords == 0) {
msg = "\n[nmfMainWindow::callback_ShowChart] No data found in: " + OutputTableNames[i] + " for current configuration.\n\n";
msg += "Please run an Estimation with the current algorithm configuration.";
Expand Down Expand Up @@ -6460,6 +6458,7 @@ nmfMainWindow::callback_ShowChart(QString OutputType,

smodel->setVerticalHeaderLabels(SpeciesList);
hLabels << TableLabels[i];

smodel->setHorizontalHeaderLabels(hLabels);
TableViews[i]->setModel(smodel);
TableViews[i]->resizeColumnsToContents();
Expand Down Expand Up @@ -6524,15 +6523,15 @@ nmfMainWindow::callback_ShowChart(QString OutputType,
smodel = new QStandardItemModel( NumSpeciesOrGuilds, NumGuilds );
fields = {"ProjectName","ModelName","Algorithm","Minimizer","ObjectiveCriterion","Scaling","isAggProd","SpeName","Guild","Value"};
queryStr = "SELECT ProjectName,ModelName,Algorithm,Minimizer,ObjectiveCriterion,Scaling,isAggProd,SpeName,Guild,Value FROM " +
OutputTableNames[ii];
OutputTableNames[ii];
queryStr += " WHERE ProjectName = '" + m_ProjectName +
"' AND ModelName = '" + m_ModelName +
"' AND Algorithm = '" + Algorithm +
"' AND Minimizer = '" + Minimizer +
"' AND ObjectiveCriterion = '" + ObjectiveCriterion +
"' AND Scaling = '" + Scaling +
"' AND isAggProd = " + isAggProdStr +
" ORDER by SpeName,Guild";
"' AND ModelName = '" + m_ModelName +
"' AND Algorithm = '" + Algorithm +
"' AND Minimizer = '" + Minimizer +
"' AND ObjectiveCriterion = '" + ObjectiveCriterion +
"' AND Scaling = '" + Scaling +
"' AND isAggProd = " + isAggProdStr +
" ORDER by SpeName,Guild";
dataMap = m_DatabasePtr->nmfQueryDatabase(queryStr, fields);
NumRecords = dataMap["SpeName"].size();
if ((NumRecords != NumSpeciesOrGuilds*NumGuilds) && (NumRecords != 0)) {
Expand Down Expand Up @@ -6568,8 +6567,6 @@ nmfMainWindow::callback_ShowChart(QString OutputType,

} // end if



if (! getOutputBiomass(NumLines,NumSpeciesOrGuilds,RunLength,
Algorithms,Minimizers,ObjectiveCriteria,Scalings,
isAggProdStr,OutputBiomass)) {
Expand Down
Loading

0 comments on commit 977eed3

Please sign in to comment.