std::vector<ObjectRecord> CloudSessionRecord_Impl::children() const { ObjectRecordVector result; if (OptionalUrlRecord sur = serverUrlRecord()) { result.push_back(*sur); } UrlRecordVector workers = workerUrlRecords(); result.insert(result.end(),workers.begin(),workers.end()); return result; }
std::vector<ObjectRecord> DakotaAlgorithmRecord_Impl::children() const { ObjectRecordVector result = AlgorithmRecord_Impl::children(); if (OptionalFileReferenceRecord restartFile = restartFileReferenceRecord()) { result.push_back(*restartFile); } if (OptionalFileReferenceRecord outFile = outFileReferenceRecord()) { result.push_back(*outFile); } return result; }
std::vector<ObjectRecord> FunctionRecord_Impl::children() const { ObjectRecordVector result; VariableRecordVector variableRecords = this->variableRecords(); result.insert(result.end(),variableRecords.begin(),variableRecords.end()); return result; }
TEST_F(ProjectFixture, RubyMeasureRecord_RubyScript) { // Measures MeasureVector measures; // Null Measure measures.push_back(NullMeasure()); openstudio::path rubyLibDirPath = openstudio::toPath(rubyLibDir()); openstudio::path perturbScript = rubyLibDirPath/openstudio::toPath("openstudio/runmanager/rubyscripts/PerturbObject.rb"); RubyMeasure rubyMeasure(perturbScript, FileReferenceType::OSM, FileReferenceType::OSM); rubyMeasure.addArgument("inputPath", "in.osm"); rubyMeasure.addArgument("outputPath", "out.osm"); rubyMeasure.addArgument("objectType", "OS:Material"); rubyMeasure.addArgument("nameRegex", "I02 50mm insulation board"); rubyMeasure.addArgument("field", "3"); rubyMeasure.addArgument("value", "0.10"); // RubyMeasure measures.push_back(rubyMeasure); // Variables VariableVector variables; variables.push_back(MeasureGroup("Wall Construction",measures)); // Workflow openstudio::runmanager::Workflow workflow; // Problem Problem problem("Variable",variables,workflow); // Save to database { ProjectDatabase database = getCleanDatabase("RubyMeasureRecord_RubyScript"); bool didStartTransaction = database.startTransaction(); EXPECT_TRUE(didStartTransaction); // Problem Record ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database); database.save(); if (didStartTransaction) { EXPECT_TRUE(database.commitTransaction()); } // Variable Records InputVariableRecordVector measureGroupRecords = problemRecord.inputVariableRecords(); EXPECT_EQ(1u,measureGroupRecords.size()); // Discrete Variable Record MeasureGroupRecord measureGroupRecord = measureGroupRecords.at(0).cast<MeasureGroupRecord>(); EXPECT_EQ(2u,measureGroupRecord.measureRecordIds(true).size()); EXPECT_EQ(2u,measureGroupRecord.measureRecords(true).size()); RubyMeasureRecord rubyMeasureRecord(rubyMeasure,measureGroupRecord,0); EXPECT_EQ("MeasureRecords",rubyMeasureRecord.databaseTableName()); ObjectRecordVector objectRecordVector = rubyMeasureRecord.children(); EXPECT_EQ(6u,objectRecordVector.size()); // arguments objectRecordVector = rubyMeasureRecord.resources(); EXPECT_EQ(1u,objectRecordVector.size()); // script FileReferenceRecord scriptRecord = rubyMeasureRecord.fileReferenceRecord(); EXPECT_EQ("FileReferenceRecords",scriptRecord.databaseTableName()); Measure measure = rubyMeasureRecord.measure(); EXPECT_EQ(true,measure.isSelected()); ASSERT_TRUE(measure.optionalCast<RubyMeasure>()); RubyMeasure rubyMeasureCopy = measure.cast<RubyMeasure>(); EXPECT_FALSE(rubyMeasureCopy.usesBCLMeasure()); EXPECT_FALSE(rubyMeasureCopy.isUserScript()); EXPECT_EQ(6u,rubyMeasureCopy.arguments().size()); MeasureGroupRecord measureGroupRecordFromRuby = rubyMeasureRecord.measureGroupRecord().get(); EXPECT_EQ(measureGroupRecord.databaseTableName(),measureGroupRecordFromRuby.databaseTableName()); EXPECT_EQ(measureGroupRecord.id(),measureGroupRecordFromRuby.id()); } // Reopen database { ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_RubyScript"); ProblemRecordVector problemRecords = ProblemRecord::getProblemRecords(database); ASSERT_FALSE(problemRecords.empty()); EXPECT_EQ(1u,problemRecords.size()); ProblemRecord problemRecord = problemRecords[0]; // COPY-PASTED FROM ABOVE // Variable Records InputVariableRecordVector measureGroupRecords = problemRecord.inputVariableRecords(); EXPECT_EQ(1u,measureGroupRecords.size()); // Discrete Variable Record MeasureGroupRecord measureGroupRecord = measureGroupRecords.at(0).cast<MeasureGroupRecord>(); EXPECT_EQ(2u,measureGroupRecord.measureRecordIds(true).size()); EXPECT_EQ(2u,measureGroupRecord.measureRecords(true).size()); RubyMeasureRecord rubyMeasureRecord(rubyMeasure,measureGroupRecord,0); EXPECT_EQ("MeasureRecords",rubyMeasureRecord.databaseTableName()); ObjectRecordVector objectRecordVector = rubyMeasureRecord.children(); EXPECT_EQ(6u,objectRecordVector.size()); // arguments objectRecordVector = rubyMeasureRecord.resources(); EXPECT_EQ(1u,objectRecordVector.size()); // script FileReferenceRecord scriptRecord = rubyMeasureRecord.fileReferenceRecord(); EXPECT_EQ("FileReferenceRecords",scriptRecord.databaseTableName()); Measure measure = rubyMeasureRecord.measure(); EXPECT_EQ(true,measure.isSelected()); ASSERT_TRUE(measure.optionalCast<RubyMeasure>()); RubyMeasure rubyMeasureCopy = measure.cast<RubyMeasure>(); EXPECT_FALSE(rubyMeasureCopy.usesBCLMeasure()); EXPECT_FALSE(rubyMeasureCopy.isUserScript()); EXPECT_EQ(6u,rubyMeasureCopy.arguments().size()); MeasureGroupRecord measureGroupRecordFromRuby = rubyMeasureRecord.measureGroupRecord().get(); EXPECT_EQ(measureGroupRecord.databaseTableName(),measureGroupRecordFromRuby.databaseTableName()); EXPECT_EQ(measureGroupRecord.id(),measureGroupRecordFromRuby.id()); } }
std::vector<ObjectRecord> MeasureGroupRecord_Impl::children() const { ObjectRecordVector result = InputVariableRecord_Impl::children(); std::vector<MeasureRecord> measureRecords = this->measureRecords(false); result.insert(result.end(),measureRecords.begin(),measureRecords.end()); return result; }
std::vector<ObjectRecord> RubyContinuousVariableRecord_Impl::resources() const { ObjectRecordVector result; result.push_back(rubyMeasureRecord()); return result; }
std::vector<ObjectRecord> RubyContinuousVariableRecord_Impl::children() const { ObjectRecordVector result = InputVariableRecord_Impl::children(); result.push_back(osArgumentRecord()); return result; }