use of cbit.vcell.numericstest.TestCriteriaNewBioModel in project vcell by virtualcell.
the class TestingFrameworkWindowManager method addTestCases.
/**
* Insert the method's description here.
* Creation date: (4/10/2003 11:27:32 AM)
* @param testCase cbit.vcell.numericstestingframework.TestCase
*/
public String addTestCases(final TestSuiteInfoNew tsInfo, final TestCaseNew[] testCaseArray, int regrRefFlag, ClientTaskStatusSupport pp) {
if (tsInfo == null) {
throw new IllegalArgumentException("TestSuiteInfo cannot be null");
}
if (testCaseArray == null || testCaseArray.length == 0) {
throw new IllegalArgumentException("TestCases cannot be null / empty");
}
// make modifiable list
List<TestCaseNew> testCases = new ArrayList<>(Arrays.asList(testCaseArray));
StringBuffer errors = new StringBuffer();
// When a testCase (mathmodel/biomodel) is added to a testSuite, a new version of the mathModel/biomodel should be created.
// Also, the simulations in the original mathmodel/biomodel should be rid of their parent simulation reference.
pp.setMessage("Getting testSuite");
pp.setProgress(1);
TestSuiteNew testSuite = null;
try {
testSuite = getRequestManager().getDocumentManager().getTestSuite(tsInfo.getTSKey());
} catch (Throwable e) {
throw new RuntimeException("couldn't get test suite " + tsInfo.getTSID() + "\n" + e.getClass().getName() + " mesg=" + e.getMessage() + "\n");
}
if (testSuite != null && testSuite.getTSInfoNew().isLocked()) {
throw new RuntimeException("Cannot addTestCases to locked table");
}
if (testSuite != null) {
// Saving BioModels
TestCaseNew[] existingTestCases = testSuite.getTestCases();
java.util.HashMap<KeyValue, BioModel> bioModelHashMap = new java.util.HashMap<KeyValue, BioModel>();
// if(existingTestCases != null){
// Find BioModels, Using the same BM reference for sibling Applications
int pcounter = 0;
// use iterator to allow removal of test case from collection if exception
Iterator<TestCaseNew> iter = testCases.iterator();
while (iter.hasNext()) {
TestCaseNew testCase = iter.next();
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
if (testCase instanceof TestCaseNewBioModel) {
TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
//
if (bioModelHashMap.get(bioTestCase.getBioModelInfo().getVersion().getVersionKey()) == null) {
pp.setMessage("Getting BM " + testCase.getVersion().getName());
BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bioTestCase.getBioModelInfo().getVersion().getVersionKey());
if (!bioModel.getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
throw new Exception("BioModel does not belong to VCELLTESTACCOUNT, cannot proceed with test!");
}
//
// if biomodel already exists in same testsuite, then use this BioModel edition
//
BioModel newBioModel = null;
if (existingTestCases != null) {
for (int j = 0; newBioModel == null && j < existingTestCases.length; j++) {
if (existingTestCases[j] instanceof TestCaseNewBioModel) {
TestCaseNewBioModel existingTestCaseBioModel = (TestCaseNewBioModel) existingTestCases[j];
//
if (existingTestCaseBioModel.getBioModelInfo().getVersion().getBranchID().equals(bioTestCase.getBioModelInfo().getVersion().getBranchID())) {
//
if (existingTestCaseBioModel.getBioModelInfo().getVersion().getVersionKey().equals(bioTestCase.getBioModelInfo().getVersion().getVersionKey())) {
//
// same, store this "unchanged" in bioModelHashMap
//
newBioModel = bioModel;
} else {
//
throw new Exception("can't add new test case using (" + bioTestCase.getBioModelInfo().getVersion().getName() + " " + bioTestCase.getBioModelInfo().getVersion().getDate() + ")\n" + "a test case already exists with different edition of same BioModel dated " + existingTestCaseBioModel.getBioModelInfo().getVersion().getDate());
}
}
}
}
}
if (newBioModel == null) {
pp.setMessage("Saving BM " + testCase.getVersion().getName());
//
// some older models have membrane voltage variable names which are not unique
// (e.g. membranes 'pm' and 'nm' both have membrane voltage variables named 'Voltage_Membrane0')
//
// if this is the case, we will try to repair the conflict (for math testing purposes only) by renaming the voltage variables to their default values.
//
// Ordinarily, the conflict will be identified as an "Error" issue and the user will be prompted to repair before saving or math generation.
//
bioModel.refreshDependencies();
boolean bFoundIdentifierConflictUponLoading = hasDuplicateIdentifiers(bioModel);
if (bFoundIdentifierConflictUponLoading) {
//
// look for two MembraneVoltage instances with same variable name, rename all
//
HashSet<String> membraneVoltageVarNames = new HashSet<String>();
ArrayList<MembraneVoltage> membraneVoltageVars = new ArrayList<MembraneVoltage>();
for (Structure struct : bioModel.getModel().getStructures()) {
if (struct instanceof Membrane) {
MembraneVoltage membraneVoltage = ((Membrane) struct).getMembraneVoltage();
if (membraneVoltage != null) {
membraneVoltageVars.add(membraneVoltage);
membraneVoltageVarNames.add(membraneVoltage.getName());
}
}
}
if (membraneVoltageVars.size() != membraneVoltageVarNames.size()) {
// rename them all to the default names
for (MembraneVoltage memVoltage : membraneVoltageVars) {
memVoltage.setName(Membrane.getDefaultMembraneVoltageName(memVoltage.getMembrane().getName()));
}
}
}
SimulationContext[] simContexts = bioModel.getSimulationContexts();
for (int j = 0; j < simContexts.length; j++) {
simContexts[j].clearVersion();
GeometrySurfaceDescription gsd = simContexts[j].getGeometry().getGeometrySurfaceDescription();
if (gsd != null) {
GeometricRegion[] grArr = gsd.getGeometricRegions();
if (grArr == null) {
gsd.updateAll();
}
}
MathMapping mathMapping = simContexts[j].createNewMathMapping();
// for older models that do not have absolute compartment sizes set, but have relative sizes (SVR/VF); or if there is only one compartment with size not set,
// compute absolute compartment sizes using relative sizes and assuming a default value of '1' for one of the compartments.
// Otherwise, the math generation will fail, since for the relaxed topology (VCell 5.3 and later) absolute compartment sizes are required.
GeometryContext gc = simContexts[j].getGeometryContext();
if (simContexts[j].getGeometry().getDimension() == 0 && ((gc.isAllSizeSpecifiedNull() && !gc.isAllVolFracAndSurfVolSpecifiedNull()) || (gc.getModel().getStructures().length == 1 && gc.isAllSizeSpecifiedNull()))) {
// choose the first structure in model and set its size to '1'.
Structure struct = simContexts[j].getModel().getStructure(0);
double structSize = 1.0;
StructureSizeSolver.updateAbsoluteStructureSizes(simContexts[j], struct, structSize, struct.getStructureSize().getUnitDefinition());
}
simContexts[j].setMathDescription(mathMapping.getMathDescription());
}
Simulation[] sims = bioModel.getSimulations();
String[] simNames = new String[sims.length];
for (int j = 0; j < sims.length; j++) {
// prevents parent simulation (from the original mathmodel) reference connection
// Otherwise it will refer to data from previous (parent) simulation.
sims[j].clearVersion();
simNames[j] = sims[j].getName();
// if(sims[j].getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)){
// sims[j].getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
// }
}
newBioModel = getRequestManager().getDocumentManager().save(bioModel, simNames);
}
bioModelHashMap.put(bioTestCase.getBioModelInfo().getVersion().getVersionKey(), newBioModel);
}
}
} catch (Throwable e) {
String identifier = testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey();
if (lg.isInfoEnabled()) {
lg.info(identifier, e);
}
errors.append("Error collecting BioModel for TestCase " + identifier + '\n' + e.getClass().getName() + " " + e.getMessage() + '\n');
// remove to avoid further processing attempts
iter.remove();
}
}
// }
// then process each BioModelTestCase individually
// if(bioModelHashMap != null){
pcounter = 0;
for (TestCaseNew testCase : testCases) {
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
AddTestCasesOP testCaseOP = null;
if (testCase instanceof TestCaseNewBioModel) {
pp.setMessage("Processing BM " + testCase.getVersion().getName());
TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
BioModel newBioModel = (BioModel) bioModelHashMap.get(bioTestCase.getBioModelInfo().getVersion().getVersionKey());
if (newBioModel == null) {
throw new Exception("BioModel not found");
}
SimulationContext simContext = null;
for (int j = 0; j < newBioModel.getSimulationContexts().length; j++) {
if (newBioModel.getSimulationContext(j).getName().equals(bioTestCase.getSimContextName())) {
simContext = newBioModel.getSimulationContext(j);
}
}
Simulation[] newSimulations = simContext.getSimulations();
AddTestCriteriaOPBioModel[] testCriteriaOPs = new AddTestCriteriaOPBioModel[newSimulations.length];
for (int j = 0; j < newSimulations.length; j++) {
TestCriteriaNewBioModel tcritOrigForSimName = null;
for (int k = 0; bioTestCase.getTestCriterias() != null && k < bioTestCase.getTestCriterias().length; k += 1) {
if (bioTestCase.getTestCriterias()[k].getSimInfo().getName().equals(newSimulations[j].getName())) {
tcritOrigForSimName = (TestCriteriaNewBioModel) bioTestCase.getTestCriterias()[k];
break;
}
}
KeyValue regressionBioModelKey = null;
KeyValue regressionBioModelSimKey = null;
if (bioTestCase.getType().equals(TestCaseNew.REGRESSION)) {
if (regrRefFlag == TestingFrameworkWindowManager.COPY_REGRREF) {
regressionBioModelKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionBioModelInfo() != null ? tcritOrigForSimName.getRegressionBioModelInfo().getVersion().getVersionKey() : null);
regressionBioModelSimKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionSimInfo() != null ? tcritOrigForSimName.getRegressionSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNORIGINAL_REGRREF) {
regressionBioModelKey = (tcritOrigForSimName != null ? bioTestCase.getBioModelInfo().getVersion().getVersionKey() : null);
regressionBioModelSimKey = (tcritOrigForSimName != null ? tcritOrigForSimName.getSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNNEW_REGRREF) {
regressionBioModelKey = newBioModel.getVersion().getVersionKey();
regressionBioModelSimKey = newSimulations[j].getVersion().getVersionKey();
} else {
throw new IllegalArgumentException(this.getClass().getName() + ".addTestCases(...) BIOMODEL Unknown Regression Operation Flag");
}
}
testCriteriaOPs[j] = new AddTestCriteriaOPBioModel(testCase.getTCKey(), newSimulations[j].getVersion().getVersionKey(), regressionBioModelKey, regressionBioModelSimKey, (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxAbsError() : new Double(1e-16)), (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxRelError() : new Double(1e-9)), null);
}
testCaseOP = new AddTestCasesOPBioModel(new BigDecimal(tsInfo.getTSKey().toString()), newBioModel.getVersion().getVersionKey(), simContext.getKey(), bioTestCase.getType(), bioTestCase.getAnnotation(), testCriteriaOPs);
getRequestManager().getDocumentManager().doTestSuiteOP(testCaseOP);
}
} catch (Throwable e) {
errors.append("Error processing Biomodel for TestCase " + (testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey()) + "\n" + e.getClass().getName() + " " + e.getMessage() + "\n");
}
}
// }
// Process MathModels
pcounter = 0;
for (TestCaseNew testCase : testCases) {
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
AddTestCasesOP testCaseOP = null;
if (testCase instanceof TestCaseNewMathModel) {
TestCaseNewMathModel mathTestCase = (TestCaseNewMathModel) testCase;
pp.setMessage("Getting MathModel " + testCase.getVersion().getName());
MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mathTestCase.getMathModelInfo().getVersion().getVersionKey());
if (!mathModel.getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
throw new Exception("MathModel does not belong to VCELLTESTACCOUNT, cannot proceed with test!");
}
Simulation[] sims = mathModel.getSimulations();
String[] simNames = new String[sims.length];
for (int j = 0; j < sims.length; j++) {
// prevents parent simulation (from the original mathmodel) reference connection
// Otherwise it will refer to data from previous (parent) simulation.
sims[j].clearVersion();
simNames[j] = sims[j].getName();
// if(sims[j].getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)){
// sims[j].getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
// }
}
pp.setMessage("Saving MathModel " + testCase.getVersion().getName());
MathModel newMathModel = getRequestManager().getDocumentManager().save(mathModel, simNames);
Simulation[] newSimulations = newMathModel.getSimulations();
AddTestCriteriaOPMathModel[] testCriteriaOPs = new AddTestCriteriaOPMathModel[newSimulations.length];
for (int j = 0; j < newSimulations.length; j++) {
TestCriteriaNewMathModel tcritOrigForSimName = null;
for (int k = 0; mathTestCase.getTestCriterias() != null && k < mathTestCase.getTestCriterias().length; k += 1) {
if (mathTestCase.getTestCriterias()[k].getSimInfo().getName().equals(newSimulations[j].getName())) {
tcritOrigForSimName = (TestCriteriaNewMathModel) mathTestCase.getTestCriterias()[k];
break;
}
}
KeyValue regressionMathModelKey = null;
KeyValue regressionMathModelSimKey = null;
if (mathTestCase.getType().equals(TestCaseNew.REGRESSION)) {
if (regrRefFlag == TestingFrameworkWindowManager.COPY_REGRREF) {
regressionMathModelKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionMathModelInfo() != null ? tcritOrigForSimName.getRegressionMathModelInfo().getVersion().getVersionKey() : null);
regressionMathModelSimKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionSimInfo() != null ? tcritOrigForSimName.getRegressionSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNORIGINAL_REGRREF) {
regressionMathModelKey = (tcritOrigForSimName != null ? mathTestCase.getMathModelInfo().getVersion().getVersionKey() : null);
regressionMathModelSimKey = (tcritOrigForSimName != null ? tcritOrigForSimName.getSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNNEW_REGRREF) {
regressionMathModelKey = newMathModel.getVersion().getVersionKey();
regressionMathModelSimKey = newSimulations[j].getVersion().getVersionKey();
} else {
throw new IllegalArgumentException(this.getClass().getName() + ".addTestCases(...) MATHMODEL Unknown Regression Operation Flag");
}
}
testCriteriaOPs[j] = new AddTestCriteriaOPMathModel(testCase.getTCKey(), newSimulations[j].getVersion().getVersionKey(), regressionMathModelKey, regressionMathModelSimKey, (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxAbsError() : new Double(1e-16)), (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxRelError() : new Double(1e-9)), null);
}
testCaseOP = new AddTestCasesOPMathModel(new BigDecimal(tsInfo.getTSKey().toString()), newMathModel.getVersion().getVersionKey(), mathTestCase.getType(), mathTestCase.getAnnotation(), testCriteriaOPs);
getRequestManager().getDocumentManager().doTestSuiteOP(testCaseOP);
}
} catch (Throwable e) {
errors.append("Error processing MathModel for TestCase " + (testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey()) + "\n" + e.getClass().getName() + " " + e.getMessage() + "\n");
}
}
}
if (errors.length() > 0) {
return errors.toString();
}
return null;
}
use of cbit.vcell.numericstest.TestCriteriaNewBioModel in project vcell by virtualcell.
the class TestingFrameworkWindowManager method generateTestCriteriaReport.
/**
* Insert the method's description here.
* Creation date: (8/18/2003 5:36:47 PM)
*/
private String generateTestCriteriaReport(TestCaseNew testCase, TestCriteriaNew testCriteria, Simulation testSim, TFGenerateReport.VCDocumentAndSimInfo userSelectedRefSimInfo) /*,VCDocument refDoc,VCDocument testDocument*/
{
if (testSim.getScanCount() != 1) {
throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
}
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(testSim, 0);
String simReportStatus = null;
String simReportStatusMessage = null;
StringBuffer reportTCBuffer = new StringBuffer();
VariableComparisonSummary[] failVarSummaries = null;
VariableComparisonSummary[] allVarSummaries = null;
double absErr = 0;
double relErr = 0;
if (testCriteria != null) {
absErr = testCriteria.getMaxAbsError().doubleValue();
relErr = testCriteria.getMaxRelError().doubleValue();
}
try {
VCDocument testDoc = null;
if (testCase instanceof TestCaseNewMathModel) {
MathModelInfo mmInfo = ((TestCaseNewMathModel) testCase).getMathModelInfo();
MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mmInfo);
testDoc = mathModel;
} else if (testCase instanceof TestCaseNewBioModel) {
TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
// bioTestCase.
BioModelInfo bmInfo = bioTestCase.getBioModelInfo();
BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bmInfo);
testDoc = bioModel;
}
TFGenerateReport.VCDocumentAndSimInfo refVCDocumentAndSimInfo = null;
if (userSelectedRefSimInfo == null) {
SimulationInfo refSimInfo = testCriteria.getRegressionSimInfo();
if (refSimInfo != null) {
VCDocument refDoc = null;
if (testCriteria instanceof TestCriteriaNewMathModel) {
MathModelInfo mmInfo = ((TestCriteriaNewMathModel) testCriteria).getRegressionMathModelInfo();
MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mmInfo);
refDoc = mathModel;
} else if (testCriteria instanceof TestCriteriaNewBioModel) {
BioModelInfo bmInfo = ((TestCriteriaNewBioModel) testCriteria).getRegressionBioModelInfo();
BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bmInfo);
refDoc = bioModel;
}
refVCDocumentAndSimInfo = new TFGenerateReport.VCDocumentAndSimInfo(refSimInfo, refDoc);
}
reportTCBuffer.append("\t\t" + testSim.getName() + (refVCDocumentAndSimInfo != null ? " (Using TestCrit RegrRefSim)" : "") + " : " + "\n");
} else {
refVCDocumentAndSimInfo = userSelectedRefSimInfo;
reportTCBuffer.append("\t\t" + testSim.getName() + " (Using UserDefined RegrRefSim '" + userSelectedRefSimInfo.getSimInfo().getAuthoritativeVCSimulationIdentifier() + "') : " + "\n");
}
if (testCase.getType().equals(TestCaseNew.REGRESSION) && refVCDocumentAndSimInfo == null) {
reportTCBuffer.append("\t\t\tNo reference SimInfo, SimInfoKey=" + testCriteria.getSimInfo().getVersion().getName() + ". Cannot perform Regression Test!\n");
simReportStatus = TestCriteriaNew.TCRIT_STATUS_NOREFREGR;
} else {
VCDataIdentifier vcdID = new VCSimulationDataIdentifier(testSim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), 0);
DataManager simDataManager = getRequestManager().getDataManager(null, vcdID, testSim.isSpatial());
double[] timeArray = null;
// can be histogram, so there won't be time array
try {
timeArray = simDataManager.getDataSetTimes();
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
NonspatialStochSimOptions stochOpt = testSim.getSolverTaskDescription().getStochOpt();
if ((stochOpt == null || stochOpt.getNumOfTrials() == 1) && (timeArray == null || timeArray.length == 0)) {
reportTCBuffer.append("\t\t\tNO DATA : Simulation not run yet.\n");
simReportStatus = TestCriteriaNew.TCRIT_STATUS_NODATA;
} else {
// SPATIAL simulation
if (testSim.getMathDescription().isSpatial()) {
PDEDataManager pdeDataManager = (PDEDataManager) simDataManager;
// Get EXACT solution if test case type is EXACT, Compare with numerical
if (testCase.getType().equals(TestCaseNew.EXACT) || testCase.getType().equals(TestCaseNew.EXACT_STEADY)) {
SimulationComparisonSummary simCompSummary = MathTestingUtilities.comparePDEResultsWithExact(simSymbolTable, pdeDataManager, testCase.getType(), testCriteria.getMaxAbsError(), testCriteria.getMaxRelError());
// Failed var summaries
failVarSummaries = simCompSummary.getFailingVariableComparisonSummaries(absErr, relErr);
allVarSummaries = simCompSummary.getVariableComparisonSummaries();
if (failVarSummaries.length > 0) {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
// Failed simulation
reportTCBuffer.append("\t\tTolerance test FAILED \n");
reportTCBuffer.append("\t\tFailed Variables : \n");
for (int m = 0; m < failVarSummaries.length; m++) {
reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
}
} else {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
reportTCBuffer.append("\t\tTolerance test PASSED \n");
}
reportTCBuffer.append("\t\tPassed Variables : \n");
// Check if varSummary exists in failed summaries list. If not, simulation passed.
for (int m = 0; m < allVarSummaries.length; m++) {
if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
}
}
// Get CONSTRUCTED solution if test case type is CONSTRUCTED, Compare with numerical
} else if (testCase.getType().equals(TestCaseNew.CONSTRUCTED)) {
SimulationComparisonSummary simCompSummary = MathTestingUtilities.comparePDEResultsWithExact(simSymbolTable, pdeDataManager, testCase.getType(), testCriteria.getMaxAbsError(), testCriteria.getMaxRelError());
// Failed var summaries
failVarSummaries = simCompSummary.getFailingVariableComparisonSummaries(absErr, relErr);
allVarSummaries = simCompSummary.getVariableComparisonSummaries();
if (failVarSummaries.length > 0) {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
// Failed simulation
reportTCBuffer.append("\t\tTolerance test FAILED \n");
reportTCBuffer.append("\t\tFailed Variables : \n");
for (int m = 0; m < failVarSummaries.length; m++) {
reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
}
} else {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
reportTCBuffer.append("\t\tTolerance test PASSED \n");
}
reportTCBuffer.append("\t\tPassed Variables : \n");
// Check if varSummary exists in failed summaries list. If not, simulation passed.
for (int m = 0; m < allVarSummaries.length; m++) {
if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
}
}
} else if (testCase.getType().equals(TestCaseNew.REGRESSION)) {
Simulation refSim = ((ClientDocumentManager) getRequestManager().getDocumentManager()).getSimulation(refVCDocumentAndSimInfo.getSimInfo());
VCDataIdentifier refVcdID = new VCSimulationDataIdentifier(refVCDocumentAndSimInfo.getSimInfo().getAuthoritativeVCSimulationIdentifier(), 0);
PDEDataManager refDataManager = (PDEDataManager) getRequestManager().getDataManager(null, refVcdID, refSim.isSpatial());
if (refSim.getScanCount() != 1) {
throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
}
SimulationSymbolTable refSimSymbolTable = new SimulationSymbolTable(refSim, 0);
String[] varsToCompare = getVariableNamesToCompare(simSymbolTable, refSimSymbolTable);
SimulationComparisonSummary simCompSummary = MathTestingUtilities.comparePDEResults(simSymbolTable, pdeDataManager, refSimSymbolTable, refDataManager, varsToCompare, testCriteria.getMaxAbsError(), testCriteria.getMaxRelError(), refVCDocumentAndSimInfo.getVCDocument(), getDataInfoProvider(refVCDocumentAndSimInfo.getVCDocument(), refDataManager.getPDEDataContext(), refSim.getName()), testDoc, getDataInfoProvider(testDoc, pdeDataManager.getPDEDataContext(), testSim.getName()));
// Failed var summaries
failVarSummaries = simCompSummary.getFailingVariableComparisonSummaries(absErr, relErr);
allVarSummaries = simCompSummary.getVariableComparisonSummaries();
if (failVarSummaries.length > 0) {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
// Failed simulation
reportTCBuffer.append("\t\tTolerance test FAILED \n");
reportTCBuffer.append("\t\tFailed Variables : \n");
for (int m = 0; m < failVarSummaries.length; m++) {
reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
}
} else {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
reportTCBuffer.append("\t\tTolerance test PASSED \n");
}
reportTCBuffer.append("\t\tPassed Variables : \n");
// Check if varSummary exists in failed summaries list. If not, simulation passed.
for (int m = 0; m < allVarSummaries.length; m++) {
if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
}
}
}
} else {
// NON-SPATIAL CASE
ODEDataManager odeDataManager = (ODEDataManager) simDataManager;
ODESolverResultSet numericalResultSet = odeDataManager.getODESolverResultSet();
// Get EXACT result set if test case type is EXACT, Compare with numerical
if (testCase.getType().equals(TestCaseNew.EXACT) || testCase.getType().equals(TestCaseNew.EXACT_STEADY)) {
ODESolverResultSet exactResultSet = MathTestingUtilities.getExactResultSet(testSim.getMathDescription(), timeArray, testSim.getSolverTaskDescription().getSensitivityParameter());
String[] varsToCompare = getVariableNamesToCompare(simSymbolTable, simSymbolTable);
SimulationComparisonSummary simCompSummary_exact = MathTestingUtilities.compareResultSets(numericalResultSet, exactResultSet, varsToCompare, testCase.getType(), testCriteria.getMaxAbsError(), testCriteria.getMaxRelError());
// Get all the variable comparison summaries and the failed ones to print out report for EXACT solution comparison.
failVarSummaries = simCompSummary_exact.getFailingVariableComparisonSummaries(absErr, relErr);
allVarSummaries = simCompSummary_exact.getVariableComparisonSummaries();
if (failVarSummaries.length > 0) {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
// Failed simulation
reportTCBuffer.append("\t\tTolerance test FAILED \n");
reportTCBuffer.append("\t\tFailed Variables : \n");
for (int m = 0; m < failVarSummaries.length; m++) {
reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
}
} else {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
reportTCBuffer.append("\t\tTolerance test PASSED \n");
}
reportTCBuffer.append("\t\tPassed Variables : \n");
// Check if varSummary exists in failed summaries list. If not, simulation passed.
for (int m = 0; m < allVarSummaries.length; m++) {
if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
}
}
// Get CONSTRUCTED result set if test case type is CONSTRUCTED , compare with numerical
} else if (testCase.getType().equals(TestCaseNew.CONSTRUCTED)) {
ODESolverResultSet constructedResultSet = MathTestingUtilities.getConstructedResultSet(testSim.getMathDescription(), timeArray);
String[] varsToCompare = getVariableNamesToCompare(simSymbolTable, simSymbolTable);
SimulationComparisonSummary simCompSummary_constr = MathTestingUtilities.compareResultSets(numericalResultSet, constructedResultSet, varsToCompare, testCase.getType(), testCriteria.getMaxAbsError(), testCriteria.getMaxRelError());
// Get all the variable comparison summaries and the failed ones to print out report for CONSTRUCTED solution comparison.
failVarSummaries = simCompSummary_constr.getFailingVariableComparisonSummaries(absErr, relErr);
allVarSummaries = simCompSummary_constr.getVariableComparisonSummaries();
if (failVarSummaries.length > 0) {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
// Failed simulation
reportTCBuffer.append("\t\tTolerance test FAILED \n");
reportTCBuffer.append("\t\tFailed Variables : \n");
for (int m = 0; m < failVarSummaries.length; m++) {
reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
}
} else {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
reportTCBuffer.append("\t\tTolerance test PASSED \n");
}
reportTCBuffer.append("\t\tPassed Variables : \n");
// Check if varSummary exists in failed summaries list. If not, simulation passed.
for (int m = 0; m < allVarSummaries.length; m++) {
if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
}
}
} else if (testCase.getType().equals(TestCaseNew.REGRESSION)) {
Simulation refSim = ((ClientDocumentManager) getRequestManager().getDocumentManager()).getSimulation(testCriteria.getRegressionSimInfo());
if (refSim.getScanCount() != 1) {
throw new RuntimeException("paramater scan is not supported in Math Testing Framework");
}
SimulationSymbolTable refSimSymbolTable = new SimulationSymbolTable(refSim, 0);
String[] varsToTest = getVariableNamesToCompare(simSymbolTable, refSimSymbolTable);
VCDataIdentifier refVcdID = new VCSimulationDataIdentifier(refVCDocumentAndSimInfo.getSimInfo().getAuthoritativeVCSimulationIdentifier(), 0);
ODEDataManager refDataManager = (ODEDataManager) getRequestManager().getDataManager(null, refVcdID, refSim.isSpatial());
ODESolverResultSet referenceResultSet = refDataManager.getODESolverResultSet();
SimulationComparisonSummary simCompSummary_regr = null;
int interpolationOrder = 1;
SolverTaskDescription solverTaskDescription = refSim.getSolverTaskDescription();
if (solverTaskDescription.getOutputTimeSpec().isDefault() && ((DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec()).getKeepEvery() == 1) {
SolverDescription solverDescription = solverTaskDescription.getSolverDescription();
if ((!solverDescription.supportsAll(SolverDescription.DiscontinutiesFeatures)) || !refSim.getMathDescription().hasDiscontinuities()) {
interpolationOrder = solverDescription.getTimeOrder();
}
}
simCompSummary_regr = MathTestingUtilities.compareUnEqualResultSets(numericalResultSet, referenceResultSet, varsToTest, testCriteria.getMaxAbsError(), testCriteria.getMaxRelError(), interpolationOrder);
// Get all the variable comparison summaries and the failed ones to print out report for CONSTRUCTED solution comparison.
failVarSummaries = simCompSummary_regr.getFailingVariableComparisonSummaries(absErr, relErr);
allVarSummaries = simCompSummary_regr.getVariableComparisonSummaries();
if (failVarSummaries.length > 0) {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_FAILEDVARS;
// Failed simulation
reportTCBuffer.append("\t\tTolerance test FAILED \n");
reportTCBuffer.append("\t\tFailed Variables : \n");
for (int m = 0; m < failVarSummaries.length; m++) {
reportTCBuffer.append("\t\t\t" + failVarSummaries[m].toShortString() + "\n");
}
} else {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_PASSED;
reportTCBuffer.append("\t\tTolerance test PASSED \n");
}
reportTCBuffer.append("\t\tPassed Variables : \n");
// Check if varSummary exists in failed summaries list. If not, simulation passed.
for (int m = 0; m < allVarSummaries.length; m++) {
if (!BeanUtils.arrayContains(failVarSummaries, allVarSummaries[m])) {
reportTCBuffer.append("\t\t\t" + allVarSummaries[m].toShortString() + "\n");
}
}
}
}
}
}
} catch (Throwable e) {
simReportStatus = TestCriteriaNew.TCRIT_STATUS_RPERROR;
simReportStatusMessage = e.getClass().getName() + " " + e.getMessage();
reportTCBuffer.append("\t\t" + simReportStatusMessage + "\n");
e.printStackTrace(System.out);
}
if (userSelectedRefSimInfo == null) {
try {
// Remove any test results already present for testCriteria
RemoveTestResultsOP removeResultsOP = new RemoveTestResultsOP(new BigDecimal[] { testCriteria.getTCritKey() });
// testResultsOPsVector.add(removeResultsOP);
getRequestManager().getDocumentManager().doTestSuiteOP(removeResultsOP);
// Create new AddTestREsultsOP object for the current simulation./testCriteria.
if (allVarSummaries != null) {
AddTestResultsOP testResultsOP = new AddTestResultsOP(testCriteria.getTCritKey(), allVarSummaries);
// testResultsOPsVector.add(testResultsOP);
// Write the testResults for simulation/TestCriteria into the database ...
getRequestManager().getDocumentManager().doTestSuiteOP(testResultsOP);
}
// Update report status
updateTCritStatus(testCriteria, simReportStatus, simReportStatusMessage);
} catch (Throwable e) {
reportTCBuffer.append("\t\tUpdate DB Results failed. " + e.getClass().getName() + " " + e.getMessage() + "\n");
try {
getRequestManager().getDocumentManager().doTestSuiteOP(new EditTestCriteriaOPReportStatus(testCriteria.getTCritKey(), TestCriteriaNew.TCRIT_STATUS_RPERROR, e.getClass().getName() + " " + e.getMessage()));
} catch (Throwable e2) {
// Nothing more can be done
}
}
}
return reportTCBuffer.toString();
}
use of cbit.vcell.numericstest.TestCriteriaNewBioModel in project vcell by virtualcell.
the class TestingFrmwkTreeModel method createTestCaseSubTree.
/**
* Insert the method's description here.
* Creation date: (11/28/00 1:06:51 PM)
* @return cbit.vcell.desktop.BioModelNode
* @param docManager cbit.vcell.clientdb.DocumentManager
*/
private BioModelNode createTestCaseSubTree(TestCaseNew testCase) throws DataAccessException {
//
// add 'test case' node
//
BioModelNode testCaseNode = new BioModelNode(testCase, true);
TestCriteriaNew[] tCriteria = testCase.getTestCriterias();
// Sort
if (tCriteria != null && tCriteria.length > 0) {
java.util.Arrays.sort(tCriteria, new java.util.Comparator<TestCriteriaNew>() {
public int compare(TestCriteriaNew tc1, TestCriteriaNew tc2) {
return tc1.getSimInfo().getVersion().getName().compareTo(tc2.getSimInfo().getVersion().getName());
}
public boolean equals(Object obj) {
return false;
}
});
//
// False => sim has not been run; True => for a regression test, the ref SimInfo is not set.
boolean bRefSimNull = false;
for (int t = 0; t < tCriteria.length; t += 1) {
TestCriteriaNew tcInfo = tCriteria[t];
BioModelNode simInfoNode = new BioModelNode(tcInfo, true);
String tcInfoStr = null;
if (tcInfo != null) {
tcInfoStr = "TestCriteria : LimitAbsError = " + tcInfo.getMaxAbsError() + "; LimitRelError = " + tcInfo.getMaxRelError() + "; ";
if (testCase.getType().equals(TestCaseNew.REGRESSION)) {
if (tcInfo.getRegressionSimInfo() != null) {
SimulationInfo refSimInfo = tcInfo.getRegressionSimInfo();
if (refSimInfo != null) {
if (tcInfo instanceof TestCriteriaNewMathModel) {
tcInfoStr = tcInfoStr + "MathModel : " + ((TestCriteriaNewMathModel) tcInfo).getRegressionMathModelInfo().getVersion().getName() + "; ";
tcInfoStr = tcInfoStr + "SimInfo : " + refSimInfo.getName();
} else if (tcInfo instanceof TestCriteriaNewBioModel) {
tcInfoStr = tcInfoStr + "BioModel : " + ((TestCriteriaNewBioModel) tcInfo).getRegressionBioModelInfo().getVersion().getName() + "; ";
tcInfoStr = tcInfoStr + "SimInfo : " + refSimInfo.getName();
}
}
} else {
tcInfoStr = tcInfoStr + " REFERENCE SIMULATION NOT SET YET";
bRefSimNull = true;
}
}
BioModelNode testCriteriaNode = new BioModelNode(tcInfoStr, false);
simInfoNode.add(testCriteriaNode);
}
// Add sim results if present (by adding the reportInfo subtree ...)
BioModelNode reportInfoNode = createSimulationSubTree(tcInfo, simInfoNode, bRefSimNull);
if (reportInfoNode != null) {
simInfoNode.add(reportInfoNode);
}
testCaseNode.add(simInfoNode);
}
}
return testCaseNode;
}
use of cbit.vcell.numericstest.TestCriteriaNewBioModel in project vcell by virtualcell.
the class DbDriver method testSuiteGet.
/**
* Insert the method's description here.
* Creation date: (10/16/2004 2:39:49 PM)
* @return cbit.vcell.numericstest.TestSuiteInfoNew[]
*/
public static TestSuiteNew testSuiteGet(BigDecimal getThisTS, Connection con, User user, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
if (!user.isTestAccount()) {
throw new PermissionException("User=" + user.getName() + " not allowed TestSuiteInfo");
}
// if(testSuiteHash.containsKey(getThisTS)){
// return (cbit.vcell.numericstest.TestSuiteNew)testSuiteHash.get(getThisTS);
// }
Hashtable simulationInfoH = new Hashtable();
Hashtable mathModelInfoH = new Hashtable();
Hashtable bioModelInfoH = new Hashtable();
Statement stmt = null;
ResultSet rset = null;
String sql = null;
try {
// double begTime=System.currentTimeMillis();
// int counter = 0;
stmt = con.createStatement();
// Get VariableComparisonSummaries
Hashtable vcsH = new Hashtable();
{
sql = "SELECT " + TFTestResultTable.table.getTableName() + ".*" + " FROM " + TFTestResultTable.table.getTableName() + "," + TFTestCriteriaTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.id.getQualifiedColName() + "=" + TFTestResultTable.table.testCriteriaRef.getQualifiedColName() + " ORDER BY UPPER(" + TFTestResultTable.table.varName.getQualifiedColName() + ")";
rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal tcritRef = rset.getBigDecimal(TFTestResultTable.table.testCriteriaRef.getUnqualifiedColName());
String varName = rset.getString(TFTestResultTable.table.varName.getUnqualifiedColName());
double absError = rset.getDouble(TFTestResultTable.table.absError.getUnqualifiedColName());
double relError = rset.getDouble(TFTestResultTable.table.relError.getUnqualifiedColName());
double maxRef = rset.getDouble(TFTestResultTable.table.maxRef.getUnqualifiedColName());
double minRef = rset.getDouble(TFTestResultTable.table.minRef.getUnqualifiedColName());
double mse = rset.getDouble(TFTestResultTable.table.meanSqrError.getUnqualifiedColName());
double timeAbsError = rset.getDouble(TFTestResultTable.table.timeAbsError.getUnqualifiedColName());
int indexAbsError = rset.getInt(TFTestResultTable.table.indexAbsError.getUnqualifiedColName());
double timeRelError = rset.getDouble(TFTestResultTable.table.timeRelError.getUnqualifiedColName());
int indexRelError = rset.getInt(TFTestResultTable.table.indexRelError.getUnqualifiedColName());
Vector v = (Vector) vcsH.get(tcritRef);
if (v == null) {
v = new Vector();
vcsH.put(tcritRef, v);
}
v.add(new VariableComparisonSummary(varName, minRef, maxRef, absError, relError, mse, timeAbsError, indexAbsError, timeRelError, indexRelError));
// counter+= 1;
}
// System.out.println("VCS count="+counter+" time="+((System.currentTimeMillis()-begTime)/1000));
rset.close();
}
// begTime=System.currentTimeMillis();
// counter = 0;
// Get TestCriteria for mathModel based TestCases
Hashtable tcritH = new Hashtable();
{
sql = "SELECT " + TFTestCriteriaTable.table.getTableName() + ".*" + "," + MathModelSimulationLinkTable.table.getTableName() + ".*" + " FROM " + TFTestCriteriaTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + "," + MathModelSimulationLinkTable.table.getTableName() + "," + SimulationTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + " IS NOT NULL " + " AND " + TFTestCriteriaTable.table.simulationRef.getQualifiedColName() + "=" + SimulationTable.table.id.getQualifiedColName() + " AND " + TFTestCriteriaTable.table.regressionMMSimRef.getQualifiedColName() + "=" + MathModelSimulationLinkTable.table.id.getQualifiedColName() + "(+)" + " ORDER BY UPPER(" + SimulationTable.table.name.getQualifiedColName() + ")";
// System.out.println(sql);
rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal tcritKey = rset.getBigDecimal(TFTestCriteriaTable.table.id.getUnqualifiedColName());
BigDecimal tcaseRef = rset.getBigDecimal(TFTestCriteriaTable.table.testCaseRef.getUnqualifiedColName());
BigDecimal simRef = rset.getBigDecimal(TFTestCriteriaTable.table.simulationRef.getUnqualifiedColName());
BigDecimal simRegrRef = rset.getBigDecimal(MathModelSimulationLinkTable.table.simRef.getUnqualifiedColName());
if (rset.wasNull()) {
simRegrRef = null;
}
BigDecimal mathRegrRef = rset.getBigDecimal(MathModelSimulationLinkTable.table.mathModelRef.getUnqualifiedColName());
if (rset.wasNull()) {
mathRegrRef = null;
}
Double maxRelError = null;
double dtemp = rset.getDouble(TFTestCriteriaTable.table.maxRelError.getUnqualifiedColName());
if (rset.wasNull()) {
maxRelError = null;
} else {
maxRelError = new Double(dtemp);
}
Double maxAbsError = null;
dtemp = rset.getDouble(TFTestCriteriaTable.table.maxAbsError.getUnqualifiedColName());
if (rset.wasNull()) {
maxAbsError = null;
} else {
maxAbsError = new Double(dtemp);
}
String reportStatus = rset.getString(TFTestCriteriaTable.table.reportStatus.getUnqualifiedColName());
if (rset.wasNull()) {
reportStatus = TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT;
}
String reportStatusMessage = rset.getString(TFTestCriteriaTable.table.reportMessage.getUnqualifiedColName());
if (rset.wasNull()) {
reportStatusMessage = null;
}
if (reportStatusMessage != null && reportStatusMessage.length() > 0) {
reportStatusMessage = TokenMangler.getSQLRestoredString(reportStatusMessage);
}
Vector v = (Vector) tcritH.get(tcaseRef);
if (v == null) {
v = new Vector();
tcritH.put(tcaseRef, v);
}
SimulationInfo simInfo = (SimulationInfo) simulationInfoH.get(simRef);
if (simInfo == null) {
Vector<VersionInfo> simVector = getVersionableInfos(con, user, VersionableType.Simulation, false, new KeyValue(simRef), false, dbSyntax);
if (simVector != null && simVector.size() > 0) {
simInfo = (SimulationInfo) simVector.firstElement();
simulationInfoH.put(simRef, simInfo);
}
}
SimulationInfo regrSimInfo = null;
MathModelInfo regrMathModelInfo = null;
if (simRegrRef != null) {
regrSimInfo = (SimulationInfo) simulationInfoH.get(simRegrRef);
if (regrSimInfo == null) {
Vector<VersionInfo> regSimVector = getVersionableInfos(con, user, VersionableType.Simulation, false, new KeyValue(simRegrRef), false, dbSyntax);
if (regSimVector != null && regSimVector.size() > 0) {
regrSimInfo = (SimulationInfo) regSimVector.firstElement();
simulationInfoH.put(simRegrRef, regrSimInfo);
}
}
regrMathModelInfo = (MathModelInfo) mathModelInfoH.get(mathRegrRef);
if (regrMathModelInfo == null) {
Vector<VersionInfo> regMathVector = getVersionableInfos(con, user, VersionableType.MathModelMetaData, false, new KeyValue(mathRegrRef), false, dbSyntax);
if (regMathVector != null && regMathVector.size() > 0) {
regrMathModelInfo = (MathModelInfo) regMathVector.firstElement();
mathModelInfoH.put(mathRegrRef, regrMathModelInfo);
}
}
}
//
VariableComparisonSummary[] neededVCSArr = null;
Vector vcsV = (Vector) vcsH.get(tcritKey);
if (vcsV != null) {
neededVCSArr = new VariableComparisonSummary[vcsV.size()];
vcsV.copyInto(neededVCSArr);
}
//
TestCriteriaNew tcn = null;
if (simInfo != null) {
tcn = new TestCriteriaNewMathModel(tcritKey, simInfo, regrMathModelInfo, regrSimInfo, maxRelError, maxAbsError, neededVCSArr, reportStatus, reportStatusMessage);
v.add(tcn);
}
// counter+= 1;
}
// System.out.println("TCrit count="+counter+" time="+((System.currentTimeMillis()-begTime)/1000));
rset.close();
}
// Get TestCriteria for bioModel based TestCases
// Hashtable tcritH = new Hashtable();
{
final String REGRSIMREF = "REGRSIMREF";
final String SCNAME = "SCNAME";
sql = "SELECT " + TFTestCriteriaTable.table.getTableName() + ".*" + "," + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "," + BioModelSimulationLinkTable.table.simRef.getQualifiedColName() + " " + REGRSIMREF + "," + SimContextTable.table.name.getQualifiedColName() + " " + SCNAME + " FROM " + TFTestCriteriaTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + "," + BioModelSimContextLinkTable.table.getTableName() + "," + SimContextTable.table.getTableName() + "," + BioModelSimulationLinkTable.table.getTableName() + // SimulationTable.table.getTableName()+
" WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.id.getQualifiedColName() + "=" + TFTestCriteriaTable.table.testCaseRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + " IS NOT NULL " + " AND " + TFTestCriteriaTable.table.regressionBMAPPRef.getQualifiedColName() + "=" + BioModelSimContextLinkTable.table.id.getQualifiedColName() + "(+)" + " AND " + BioModelSimContextLinkTable.table.simContextRef + " = " + SimContextTable.table.id.getQualifiedColName() + "(+)" + // SimContextTable.table.mathRef.getQualifiedColName()+" = "+SimulationTable.table.mathRef.getQualifiedColName()+"(+)" +
" AND " + TFTestCriteriaTable.table.regressionBMSimRef.getQualifiedColName() + " = " + BioModelSimulationLinkTable.table.id.getQualifiedColName() + "(+)";
// System.out.println(sql);
rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal tcritKey = rset.getBigDecimal(TFTestCriteriaTable.table.id.getUnqualifiedColName());
BigDecimal tcaseRef = rset.getBigDecimal(TFTestCriteriaTable.table.testCaseRef.getUnqualifiedColName());
BigDecimal tcSimRef = rset.getBigDecimal(TFTestCriteriaTable.table.simulationRef.getUnqualifiedColName());
BigDecimal regrSimRef = rset.getBigDecimal(REGRSIMREF);
// BigDecimal regrSimRef = rset.getBigDecimal(SimulationTable.table.id.getUnqualifiedColName());
if (rset.wasNull()) {
regrSimRef = null;
}
BigDecimal regrBioModelRef = rset.getBigDecimal(BioModelSimContextLinkTable.table.bioModelRef.getUnqualifiedColName());
if (rset.wasNull()) {
regrBioModelRef = null;
}
String regrSCName = rset.getString(SCNAME);
if (rset.wasNull()) {
regrSCName = null;
}
Double maxRelError = null;
double dtemp = rset.getDouble(TFTestCriteriaTable.table.maxRelError.getUnqualifiedColName());
if (rset.wasNull()) {
maxRelError = null;
} else {
maxRelError = new Double(dtemp);
}
Double maxAbsError = null;
dtemp = rset.getDouble(TFTestCriteriaTable.table.maxAbsError.getUnqualifiedColName());
if (rset.wasNull()) {
maxAbsError = null;
} else {
maxAbsError = new Double(dtemp);
}
String reportStatus = rset.getString(TFTestCriteriaTable.table.reportStatus.getUnqualifiedColName());
if (rset.wasNull()) {
reportStatus = TestCriteriaNew.TCRIT_STATUS_NEEDSREPORT;
}
String reportStatusMessage = rset.getString(TFTestCriteriaTable.table.reportMessage.getUnqualifiedColName());
if (rset.wasNull()) {
reportStatusMessage = null;
}
if (reportStatusMessage != null && reportStatusMessage.length() > 0) {
reportStatusMessage = TokenMangler.getSQLRestoredString(reportStatusMessage);
}
Vector v = (Vector) tcritH.get(tcaseRef);
if (v == null) {
v = new Vector();
tcritH.put(tcaseRef, v);
}
SimulationInfo simInfo = (SimulationInfo) simulationInfoH.get(tcSimRef);
if (simInfo == null) {
Vector<VersionInfo> simVector = getVersionableInfos(con, user, VersionableType.Simulation, false, new KeyValue(tcSimRef), false, dbSyntax);
if (simVector != null && simVector.size() == 1) {
simInfo = (SimulationInfo) simVector.firstElement();
simulationInfoH.put(tcSimRef, simInfo);
} else {
throw new DataAccessException("Found more than 1 versionable for tcsimRef=" + tcSimRef);
}
}
SimulationInfo regrSimInfo = null;
BioModelInfo regrBioModelInfo = null;
if (regrSimRef != null) {
regrSimInfo = (SimulationInfo) simulationInfoH.get(regrSimRef);
if (regrSimInfo == null) {
Vector<VersionInfo> regSimVector = getVersionableInfos(con, user, VersionableType.Simulation, false, new KeyValue(regrSimRef), false, dbSyntax);
if (regSimVector != null && regSimVector.size() == 1) {
regrSimInfo = (SimulationInfo) regSimVector.firstElement();
simulationInfoH.put(regrSimRef, regrSimInfo);
} else {
throw new DataAccessException("Found more than 1 versionable for simregRef=" + regrSimRef);
}
}
regrBioModelInfo = (BioModelInfo) mathModelInfoH.get(regrBioModelRef);
if (regrBioModelInfo == null) {
Vector<VersionInfo> regBioModelVector = getVersionableInfos(con, user, VersionableType.BioModelMetaData, false, new KeyValue(regrBioModelRef), false, dbSyntax);
if (regBioModelVector != null && regBioModelVector.size() == 1) {
regrBioModelInfo = (BioModelInfo) regBioModelVector.firstElement();
mathModelInfoH.put(regrBioModelRef, regrBioModelInfo);
} else {
throw new DataAccessException("Found more than 1 versionable for reegrbiomodelRef=" + regrBioModelRef);
}
}
}
//
VariableComparisonSummary[] neededVCSArr = null;
Vector vcsV = (Vector) vcsH.get(tcritKey);
if (vcsV != null) {
neededVCSArr = new VariableComparisonSummary[vcsV.size()];
vcsV.copyInto(neededVCSArr);
}
//
TestCriteriaNew tcn = null;
if (simInfo != null) {
tcn = new TestCriteriaNewBioModel(tcritKey, simInfo, regrBioModelInfo, regrSCName, regrSimInfo, maxRelError, maxAbsError, neededVCSArr, reportStatus, reportStatusMessage);
v.add(tcn);
}
// counter+= 1;
}
// System.out.println("TCrit count="+counter+" time="+((System.currentTimeMillis()-begTime)/1000));
rset.close();
}
// Get TestCases
Vector tcV = new Vector();
// begTime=System.currentTimeMillis();
// counter = 0;
{
// final String BMSCL = "bmscl";
final String OBTCTYPECOLUMN = "OBTCTYPECOLUMN";
final String OBNAMECOLUMN = "OBNAMECOLUMN";
final String BMSCBMRNAME = "BMSCBMRNAME";
final String BMSCSCRNAME = "BMSCSCRNAME";
final String SCNAME = "SCNAME";
final String SORTHELP1 = "SORTHELP1";
final String SORTHELP2 = "SORTHELP2";
sql = "SELECT " + "UPPER(" + MathModelTable.table.name.getQualifiedColName() + ") " + SORTHELP1 + "," + "TO_CHAR(NULL) " + SORTHELP2 + "," + TFTestCaseTable.table.getTableName() + ".*" + "," + "TO_NUMBER(NULL) " + BMSCBMRNAME + "," + "TO_NUMBER(NULL) " + BMSCSCRNAME + "," + "TO_CHAR(NULL) " + SCNAME + "," + "'MM' " + OBTCTYPECOLUMN + "," + MathModelTable.table.name.getQualifiedColName() + " " + OBNAMECOLUMN + " FROM " + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + "," + MathModelTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + " IS NOT NULL" + " AND " + TFTestCaseTable.table.mathModelRef.getQualifiedColName() + " = " + MathModelTable.table.id.getQualifiedColName() + " UNION " + "SELECT " + "UPPER(" + BioModelTable.table.name.getQualifiedColName() + ") " + SORTHELP1 + ",UPPER(" + SimContextTable.table.name.getQualifiedColName() + ") " + SORTHELP2 + "," + TFTestCaseTable.table.getTableName() + ".*" + "," + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + " " + BMSCBMRNAME + "," + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + " " + BMSCSCRNAME + "," + SimContextTable.table.name.getQualifiedColName() + " " + SCNAME + "," + "'BM' " + OBTCTYPECOLUMN + "," + BioModelTable.table.name.getQualifiedColName() + " " + OBNAMECOLUMN + " FROM " + BioModelSimContextLinkTable.table.getTableName() + "," + SimContextTable.table.getTableName() + "," + TFTestCaseTable.table.getTableName() + "," + TFTestSuiteTable.table.getTableName() + "," + BioModelTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " AND " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + TFTestCaseTable.table.testSuiteRef.getQualifiedColName() + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + " IS NOT NULL" + " AND " + TFTestCaseTable.table.bmAppRef.getQualifiedColName() + " = " + BioModelSimContextLinkTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + " = " + SimContextTable.table.id.getQualifiedColName() + " AND " + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + "=" + BioModelTable.table.id.getQualifiedColName() + // " ORDER BY 11,"+"UPPER(12)"+","+"UPPER(10)";
" ORDER BY 13,1,2";
rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal tcaseKey = rset.getBigDecimal(TFTestCaseTable.table.id.getUnqualifiedColName());
BigDecimal mmRef = rset.getBigDecimal(TFTestCaseTable.table.mathModelRef.getUnqualifiedColName());
if (rset.wasNull()) {
mmRef = null;
}
BigDecimal simContextRef = rset.getBigDecimal(BMSCSCRNAME);
if (rset.wasNull()) {
simContextRef = null;
}
BigDecimal bioModelRef = rset.getBigDecimal(BMSCBMRNAME);
if (rset.wasNull()) {
bioModelRef = null;
}
String simContextName = rset.getString(SCNAME);
if (rset.wasNull()) {
simContextName = null;
}
String tcType = rset.getString(TFTestCaseTable.table.tcSolutionType.getUnqualifiedColName());
String tcAnnot = rset.getString(TFTestCaseTable.table.tcAnnotation.getUnqualifiedColName());
if (rset.wasNull()) {
tcAnnot = "";
} else {
tcAnnot = TokenMangler.getSQLRestoredString(tcAnnot);
}
java.util.Date tcDate = VersionTable.getDate(rset, TFTestCaseTable.table.creationDate.getUnqualifiedColName());
MathModelInfo mmInfo = null;
BioModelInfo bmInfo = null;
if (mmRef != null) {
mmInfo = (MathModelInfo) mathModelInfoH.get(mmRef);
if (mmInfo == null) {
Vector<VersionInfo> mathVector = getVersionableInfos(con, user, VersionableType.MathModelMetaData, false, new KeyValue(mmRef), false, dbSyntax);
if (mathVector != null && mathVector.size() > 0) {
mmInfo = (MathModelInfo) mathVector.firstElement();
mathModelInfoH.put(mmRef, mmInfo);
}
}
} else if (bioModelRef != null) {
bmInfo = (BioModelInfo) bioModelInfoH.get(bioModelRef);
if (bmInfo == null) {
Vector<VersionInfo> bmAppVector = getVersionableInfos(con, user, VersionableType.BioModelMetaData, false, new KeyValue(bioModelRef), false, dbSyntax);
if (bmAppVector != null && bmAppVector.size() > 0) {
bmInfo = (BioModelInfo) bmAppVector.firstElement();
bioModelInfoH.put(bioModelRef, bmInfo);
}
}
} else {
throw new RuntimeException("Test case in DB does not have MathmodelRef or BioModelAppRef");
}
TestCriteriaNew[] neededTcritArr = null;
Vector needTcritV = (Vector) tcritH.get(tcaseKey);
if (needTcritV != null) {
neededTcritArr = new TestCriteriaNew[needTcritV.size()];
needTcritV.copyInto(neededTcritArr);
}
TestCaseNew tcn = null;
if (mmInfo != null) {
tcn = new TestCaseNewMathModel(tcaseKey, mmInfo, tcType, tcAnnot, neededTcritArr);
tcV.add(tcn);
} else if (bmInfo != null) {
tcn = new TestCaseNewBioModel(tcaseKey, bmInfo, simContextName, new KeyValue(simContextRef), tcType, tcAnnot, neededTcritArr);
tcV.add(tcn);
} else {
// throw new RuntimeException("Expected testCase MathModelInfo or BioModelInfo to be not null");
}
// counter+= 1;
}
// System.out.println("TCase count="+counter+" time="+((System.currentTimeMillis()-begTime)/1000));
rset.close();
}
// Get TestSuite
{
TestCaseNew[] tcnArr = null;
if (tcV.size() > 0) {
tcnArr = new TestCaseNew[tcV.size()];
tcV.copyInto(tcnArr);
}
sql = "SELECT " + TFTestSuiteTable.table.getTableName() + ".*" + " FROM " + TFTestSuiteTable.table.getTableName() + " WHERE " + TFTestSuiteTable.table.id.getQualifiedColName() + "=" + getThisTS + " ORDER BY UPPER(" + TFTestSuiteTable.table.tsVersion.getQualifiedColName() + ")";
rset = stmt.executeQuery(sql);
BigDecimal tsKey = null;
String tsVersion = null;
String tsVCBuild = null;
String tsNumericsBuild = null;
java.util.Date tsDate = null;
String tsAnnot = null;
boolean islocked = true;
if (rset.next()) {
tsKey = rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName());
tsVersion = rset.getString(TFTestSuiteTable.table.tsVersion.getUnqualifiedColName());
tsVCBuild = rset.getString(TFTestSuiteTable.table.vcBuildVersion.getUnqualifiedColName());
tsNumericsBuild = rset.getString(TFTestSuiteTable.table.vcNumericsVersion.getUnqualifiedColName());
tsDate = VersionTable.getDate(rset, TFTestSuiteTable.table.creationDate.getUnqualifiedColName());
tsAnnot = rset.getString(TFTestSuiteTable.table.tsAnnotation.getUnqualifiedColName());
islocked = rset.getBoolean(TFTestSuiteTable.table.isLocked.getUnqualifiedColName());
} else {
throw new ObjectNotFoundException("TestSuite with key=" + getThisTS + " not found");
}
rset.close();
TestSuiteInfoNew tsiNew = new TestSuiteInfoNew(tsKey, tsVersion, tsVCBuild, tsNumericsBuild, tsDate, tsAnnot, islocked);
TestSuiteNew tsn = new TestSuiteNew(tsiNew, tcnArr);
// testSuiteHash.put(tsKey,tsn);
return tsn;
}
} catch (SQLException e) {
lg.error("failed: (" + sql + "): " + e.getMessage(), e);
throw e;
} finally {
if (stmt != null) {
stmt.close();
}
}
}
Aggregations