当前位置: 首页>>代码示例>>C++>>正文


C++ ProjectDatabase::save方法代码示例

本文整理汇总了C++中ProjectDatabase::save方法的典型用法代码示例。如果您正苦于以下问题:C++ ProjectDatabase::save方法的具体用法?C++ ProjectDatabase::save怎么用?C++ ProjectDatabase::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProjectDatabase的用法示例。


在下文中一共展示了ProjectDatabase::save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: model

TEST_F(ProjectFixture, AttributeRecord_ManyAnnualEndUses)
{
  ProjectDatabase database = getCleanDatabase("AttributeRecord_ManyAnnualEndUses");

  for (unsigned i = 0; i < 10; ++i){

    EndUses endUses;
    endUses.addEndUse(25.0, EndUseFuelType::Gas, EndUseCategoryType::Heating);
    endUses.addEndUse(2.0, EndUseFuelType::Electricity, EndUseCategoryType::Cooling);
    endUses.addEndUse(1.0, EndUseFuelType::Electricity, EndUseCategoryType::InteriorLights);
    endUses.addEndUse(10.0, EndUseFuelType::Electricity, EndUseCategoryType::Fans, "Fan Energy");
    endUses.addEndUse(10.0, EndUseFuelType::Water, EndUseCategoryType::Humidifier);

    std::stringstream ss;
    ss << "model " << i;

    FileReferenceRecord model(FileReference(toPath("./in.osm")),database);

    AttributeRecord attributeRecord(endUses.attribute(), model);
    ASSERT_TRUE(model.getAttributeRecord(EndUses::attributeName()));
    EXPECT_TRUE(endUses.attribute() == model.getAttributeRecord(EndUses::attributeName()).get().attribute());
  }

  database.save();
}
开发者ID:Rahjou,项目名称:OpenStudio,代码行数:25,代码来源:AttributeRecord_GTest.cpp

示例2: record

// Test not yet to scale re: data points.
TEST_F(ProjectFixture,Profile_SaveAnalysis) {
  Analysis analysis = getAnalysisToRun(100,500);

  // time the process of saving to database
  ptime start = microsec_clock::local_time();
  ProjectDatabase db = getCleanDatabase(toPath("./SaveAnalysis"));
  ASSERT_TRUE(db.startTransaction());
  AnalysisRecord record(analysis,db);
  db.save();
  ASSERT_TRUE(db.commitTransaction());
  time_duration saveTime = microsec_clock::local_time() - start;

  std::cout << "Time: " << to_simple_string(saveTime) << std::endl;
}
开发者ID:NREL,项目名称:OpenStudio-resources,代码行数:15,代码来源:ProjectDatabaseProfiling_GTest.cpp

示例3: problem

TEST_F(ProjectFixture, ProblemRecord_RubyContinuousVariables)
{
  // Create a database containing a ProblemRecord with a chain of 
  // RubyContinuousVariables that reference the same RubyMeasure
  analysis::Problem problem("Contains Linked RubyContinuousVariables");

  // Measure with two RubyContinuousVariables  
  analysis::RubyMeasure wwrScript(openstudio::toPath(rubyLibDir()) / 
                                  openstudio::toPath("openstudio/sketchup_plugin/user_scripts/Alter or Add Model Elements/Set_Window_to_Wall_Ratio.rb"),
                                  FileReferenceType::OSM,
                                  FileReferenceType::OSM,
                                  true);
  ruleset::OSArgument arg = ruleset::OSArgument::makeDoubleArgument("wwr");
  analysis::RubyContinuousVariable wwr("Window to Wall Ratio",arg,wwrScript);
  wwr.setMinimum(0.15);
  wwr.setMaximum(0.60);
  problem.push(wwr);
  arg = ruleset::OSArgument::makeDoubleArgument("offset");
  analysis::RubyContinuousVariable offset("Window Offset from Floor",arg,wwrScript);
  offset.setMinimum(0.5);
  offset.setMaximum(2.0);
  problem.push(offset);
  EXPECT_EQ(wwr.measure(), offset.measure());
  
  // Project Database
  ProjectDatabase database = getCleanDatabase("ProblemRecord_RubyContinuousVariables");

  // Problem Record
  ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);
  database.save();

  // Deserialize the problem and verify that the deserialized RubyMeasures are 
  // all equal.  
  problemRecord = ProblemRecord::getProblemRecords(database)[0];
  problem = problemRecord.problem();
  ASSERT_EQ(2u,problem.variables().size());
  ASSERT_TRUE(problem.variables()[0].optionalCast<RubyContinuousVariable>());
  ASSERT_TRUE(problem.variables()[1].optionalCast<RubyContinuousVariable>());
  EXPECT_EQ(problem.variables()[0].cast<RubyContinuousVariable>().measure(), 
            problem.variables()[1].cast<RubyContinuousVariable>().measure());
}
开发者ID:pepsi7959,项目名称:OpenStudio,代码行数:41,代码来源:ProblemRecord_GTest.cpp

示例4: session

TEST_F(ProjectFixture,CloudSessionRecord_VagrantPopulated) {
  std::string id;
  UUID uuid, versionUUID;
  {
    ProjectDatabase database = getCleanDatabase("CloudSessionRecord_VagrantPopulated");

    VagrantSession session(toString(createUUID()),
                           Url("http://localhost:8080"),
                           UrlVector(1u,Url("http://localhost:8081")));
    id = session.sessionId();
    uuid = session.uuid();
    versionUUID = session.versionUUID();

    CloudSessionRecord record = CloudSessionRecord::factoryFromCloudSession(session,database);
    database.save();

    EXPECT_EQ(1u,CloudSessionRecord::getCloudSessionRecords(database).size());    
  }
  {
    ProjectDatabase database = getExistingDatabase("CloudSessionRecord_VagrantPopulated");

    EXPECT_EQ(1u,CloudSessionRecord::getCloudSessionRecords(database).size());
    ASSERT_FALSE(CloudSessionRecord::getCloudSessionRecords(database).empty());

    CloudSessionRecord record = CloudSessionRecord::getCloudSessionRecords(database)[0];

    CloudSession session = record.cloudSession();
    ASSERT_TRUE(session.optionalCast<VagrantSession>());

    VagrantSession vagrantSession = session.cast<VagrantSession>();
    EXPECT_EQ(uuid,vagrantSession.uuid());
    EXPECT_EQ(versionUUID,vagrantSession.versionUUID());
    EXPECT_EQ("VagrantProvider",vagrantSession.cloudProviderType());
    EXPECT_EQ(id,vagrantSession.sessionId());
    ASSERT_TRUE(vagrantSession.serverUrl());
    EXPECT_EQ(Url("http://localhost:8080"),vagrantSession.serverUrl().get());
    ASSERT_EQ(1u,vagrantSession.workerUrls().size());
    EXPECT_EQ(Url("http://localhost:8081"),vagrantSession.workerUrls()[0]);
  }
}
开发者ID:jtanaa,项目名称:OpenStudio,代码行数:40,代码来源:CloudSessionRecord_GTest.cpp

示例5: rubyMeasure

TEST_F(ProjectFixture, RubyContinuousVariableRecord_SaveAndRetrieve)
{
  openstudio::path perturbScript = openstudio::toPath(rubyLibDir()) /
                                   openstudio::toPath("openstudio/runmanager/rubyscripts/PerturbObject.rb");
  RubyMeasure rubyMeasure(perturbScript,FileReferenceType::OSM,FileReferenceType::OSM);
  rubyMeasure.addArgument("objectType","OS:Material");
  rubyMeasure.addArgument("nameRegex","Insulation");
  rubyMeasure.addArgument("field","2");
  ruleset::OSArgument thickness = ruleset::OSArgument::makeDoubleArgument("Thickness");
  RubyContinuousVariable insulationThickness("Insulation Thickness",thickness,rubyMeasure);

  Problem problem("Trivial Problem",VariableVector(1u,insulationThickness),runmanager::Workflow());


  int id(0);
  {
    ProjectDatabase database = getCleanDatabase("RubyContinuousVariableRecord_SaveAndRetrieve");
    ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);
    id = problemRecord.id();
    database.save();
  }

  {
    ProjectDatabase database = getExistingDatabase("RubyContinuousVariableRecord_SaveAndRetrieve");
    OptionalProblemRecord oProblemRecord = ProblemRecord::getProblemRecord(id,database);
    ASSERT_TRUE(oProblemRecord);
    problem = oProblemRecord->problem();
  }

  EXPECT_EQ(1,problem.numVariables());
  ASSERT_TRUE(problem.variables()[0].optionalCast<RubyContinuousVariable>());
  insulationThickness = problem.variables()[0].cast<RubyContinuousVariable>();

  EXPECT_EQ("Thickness",insulationThickness.argument().name());
  EXPECT_EQ(3u,insulationThickness.perturbation().arguments().size());
}
开发者ID:jtanaa,项目名称:OpenStudio,代码行数:36,代码来源:RubyContinuousVariableRecord_GTest.cpp

示例6: getCleanDatabase

TEST_F(ProjectFixture,CloudSessionRecord_AWSDefault) {
  {
    ProjectDatabase database = getCleanDatabase("CloudSessionRecord_AWSDefault");

    AWSProvider provider;
    CloudSession session = provider.session();

    CloudSessionRecord record = CloudSessionRecord::factoryFromCloudSession(session,database);
    database.save();

    EXPECT_EQ(1u,CloudSessionRecord::getCloudSessionRecords(database).size());
  }
  {
    ProjectDatabase database = getExistingDatabase("CloudSessionRecord_AWSDefault");

    EXPECT_EQ(1u,CloudSessionRecord::getCloudSessionRecords(database).size());
    ASSERT_FALSE(CloudSessionRecord::getCloudSessionRecords(database).empty());

    CloudSessionRecord record = CloudSessionRecord::getCloudSessionRecords(database)[0];

    CloudSession session = record.cloudSession();
    EXPECT_TRUE(session.optionalCast<AWSSession>());
  }
}
开发者ID:jtanaa,项目名称:OpenStudio,代码行数:24,代码来源:CloudSessionRecord_GTest.cpp

示例7: problem

TEST_F(ProjectFixture, WorkflowRecord_Base) {
  ProjectDatabase database = getCleanDatabase("WorkflowRecord_Base");
  EXPECT_EQ(database.timestampCreate(), database.timestampLast());
  EXPECT_EQ(database.handle(), database.uuidLast());

  openstudio::System::msleep(1000);

  EXPECT_EQ(static_cast<unsigned>(0), WorkflowRecord::getWorkflowRecords(database).size());

  openstudio::runmanager::Workflow rmWorkflow;
  rmWorkflow.addJob(openstudio::runmanager::JobType::Null, "");

  // Fake ProblemRecord so can test WorkflowRecord
  Problem problem("Dummy",WorkflowStepVector());
  ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);

  WorkflowRecord workflowRecord(rmWorkflow, problemRecord, 0);
  EXPECT_EQ("", workflowRecord.name());
  EXPECT_EQ("", workflowRecord.displayName());
  EXPECT_EQ("", workflowRecord.description());
  EXPECT_TRUE(workflowRecord.timestampCreate() > database.timestampCreate());
  EXPECT_EQ(workflowRecord.timestampCreate(), workflowRecord.timestampLast());
  EXPECT_EQ(workflowRecord.handle(), rmWorkflow.uuid());

  EXPECT_EQ(database.timestampLast(), database.timestampCreate());
  EXPECT_EQ(database.handle(), database.uuidLast());

  openstudio::System::msleep(1000);

  database.save();

  EXPECT_TRUE(database.timestampLast() > database.timestampCreate());
  EXPECT_NE(database.handle(), database.uuidLast());

  DateTime databaseTimestampLast = database.timestampLast();
  UUID databaseUUIDLast = database.uuidLast();

  openstudio::System::msleep(1000);

  database.save();

  EXPECT_EQ(database.timestampLast(), databaseTimestampLast);
  EXPECT_EQ(database.uuidLast(), databaseUUIDLast);

  EXPECT_EQ(static_cast<unsigned>(1), WorkflowRecord::getWorkflowRecords(database).size());

  EXPECT_EQ(database.timestampLast(), databaseTimestampLast);
  EXPECT_EQ(database.uuidLast(), databaseUUIDLast);
  EXPECT_EQ(workflowRecord.timestampCreate(), workflowRecord.timestampLast());
  EXPECT_EQ(workflowRecord.handle(), rmWorkflow.uuid());

  EXPECT_TRUE(workflowRecord.setDescription("A simple workflowRecord"));

  EXPECT_EQ(database.timestampLast(), databaseTimestampLast);
  EXPECT_EQ(database.uuidLast(), databaseUUIDLast);
  EXPECT_TRUE(workflowRecord.timestampCreate() < workflowRecord.timestampLast());
  EXPECT_NE(workflowRecord.handle(), workflowRecord.uuidLast());

  openstudio::System::msleep(1000);

  database.save();

  EXPECT_TRUE(databaseTimestampLast < database.timestampLast());
  EXPECT_NE(database.uuidLast(), databaseUUIDLast);
  EXPECT_TRUE(workflowRecord.timestampCreate() < workflowRecord.timestampLast());
  EXPECT_NE(workflowRecord.handle(), workflowRecord.uuidLast());

  databaseTimestampLast = database.timestampLast();
  databaseUUIDLast = database.uuidLast();
  DateTime workflowTimestampLast = workflowRecord.timestampLast();
  UUID workflowUUIDLast = workflowRecord.uuidLast();

  EXPECT_EQ(static_cast<unsigned>(1), WorkflowRecord::getWorkflowRecords(database).size());

  EXPECT_EQ(database.timestampLast(), databaseTimestampLast);
  EXPECT_EQ(database.uuidLast(), databaseUUIDLast);
  EXPECT_EQ(workflowRecord.timestampLast(), workflowTimestampLast);
  EXPECT_EQ(workflowRecord.uuidLast(), workflowUUIDLast);

  EXPECT_TRUE(database.removeRecord(workflowRecord));

  EXPECT_EQ(static_cast<unsigned>(0), WorkflowRecord::getWorkflowRecords(database).size());

  EXPECT_EQ(database.timestampLast(), databaseTimestampLast);
  EXPECT_EQ(database.uuidLast(), databaseUUIDLast);
  EXPECT_EQ(workflowTimestampLast, workflowRecord.timestampLast());
  EXPECT_EQ(workflowUUIDLast, workflowRecord.uuidLast());

  openstudio::System::msleep(1000);

  database.save();

  EXPECT_TRUE(databaseTimestampLast < database.timestampLast());
  EXPECT_NE(database.uuidLast(), databaseUUIDLast);
  EXPECT_EQ(workflowTimestampLast, workflowRecord.timestampLast());
  EXPECT_EQ(workflowUUIDLast, workflowRecord.uuidLast());

}
开发者ID:ORNL-BTRIC,项目名称:OpenStudio,代码行数:98,代码来源:WorkflowRecord_GTest.cpp

示例8: rubyMeasure

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();
//.........这里部分代码省略.........
开发者ID:whztt07,项目名称:OpenStudio,代码行数:101,代码来源:RubyMeasureRecord_GTest.cpp

示例9: problem

TEST_F(ProjectFixture, RubyMeasureRecord_BCLMeasure) {
    // Construct problem with RubyMeasure that points to BCLMeasure
    Problem problem("Problem",VariableVector(),runmanager::Workflow());
    MeasureGroup dvar("Variable",MeasureVector());
    problem.push(dvar);
    openstudio::path measuresPath = resourcesPath() / toPath("/utilities/BCL/Measures");
    openstudio::path dir = measuresPath / toPath("SetWindowToWallRatioByFacade");
    BCLMeasure measure = BCLMeasure::load(dir).get();
    RubyMeasure rpert(measure);
    dvar.push(rpert);
    OSArgument arg = OSArgument::makeDoubleArgument("wwr");
    arg.setValue(0.4);
    rpert.setArgument(arg);
    arg = OSArgument::makeIntegerArgument("typo_arg");
    arg.setDefaultValue(1);
    rpert.setArgument(arg);

    // Serialize to database
    {
        ProjectDatabase database = getCleanDatabase("RubyMeasureRecord_BCLMeasure");

        bool didStartTransaction = database.startTransaction();
        EXPECT_TRUE(didStartTransaction);

        // Problem Record
        ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);

        database.save();
        if (didStartTransaction) {
            EXPECT_TRUE(database.commitTransaction());
        }
    }

    // Re-open database, de-serialize, verify that RubyMeasure is intact.
    openstudio::path tempDir1 = measuresPath / toPath(toString(createUUID()));
    {
        ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_BCLMeasure");
        ASSERT_EQ(1u,ProblemRecord::getProblemRecords(database).size());
        ASSERT_EQ(1u,MeasureGroupRecord::getMeasureGroupRecords(database).size());
        EXPECT_EQ(1u,RubyMeasureRecord::getRubyMeasureRecords(database).size());

        MeasureRecordVector dprs = MeasureGroupRecord::getMeasureGroupRecords(database)[0].measureRecords(false);
        ASSERT_EQ(1u,dprs.size());
        ASSERT_TRUE(dprs[0].optionalCast<RubyMeasureRecord>());
        RubyMeasureRecord rpr = dprs[0].cast<RubyMeasureRecord>();
        RubyMeasure rp = rpr.rubyMeasure();
        EXPECT_TRUE(rp.usesBCLMeasure());
        EXPECT_TRUE(rp.measure());
        EXPECT_EQ(dir,rp.measureDirectory());
        EXPECT_EQ(measure.uuid(),rp.measureUUID());
        EXPECT_EQ(measure.versionUUID(),rp.measureVersionUUID());
        EXPECT_ANY_THROW(rp.perturbationScript());
        EXPECT_EQ(2u,rp.arguments().size());
        EXPECT_FALSE(rp.hasIncompleteArguments());

        // Update measure and save
        BCLMeasure newVersion = measure.clone(tempDir1).get();
        newVersion.setDescription("Window to wall ratio with sill height configurable.");
        newVersion.save();
        EXPECT_NE(measure.versionUUID(),newVersion.versionUUID());
        OSArgumentVector args;
        args.push_back(OSArgument::makeDoubleArgument("wwr"));
        args.push_back(OSArgument::makeDoubleArgument("sillHeight"));

        Problem problemCopy = ProblemRecord::getProblemRecords(database)[0].problem();
        problemCopy.updateMeasure(newVersion,args,false);

        bool didStartTransaction = database.startTransaction();
        EXPECT_TRUE(didStartTransaction);

        // Problem Record
        ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problemCopy,database);

        database.save();
        if (didStartTransaction) {
            EXPECT_TRUE(database.commitTransaction());
        }
    }

    // Re-open database, check that old argument records are gone, check that de-serialized object ok
    openstudio::path tempDir2 = measuresPath / toPath(toString(createUUID()));
    {
        ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_BCLMeasure");
        ASSERT_EQ(1u,ProblemRecord::getProblemRecords(database).size());
        EXPECT_EQ(1u,MeasureGroupRecord::getMeasureGroupRecords(database).size());
        EXPECT_EQ(1u,RubyMeasureRecord::getRubyMeasureRecords(database).size());
        EXPECT_EQ(1u,FileReferenceRecord::getFileReferenceRecords(database).size());
        EXPECT_EQ(2u,OSArgumentRecord::getOSArgumentRecords(database).size());

        Problem problemCopy = ProblemRecord::getProblemRecords(database)[0].problem();
        InputVariableVector vars = problemCopy.variables();
        ASSERT_FALSE(vars.empty());
        ASSERT_TRUE(vars[0].optionalCast<MeasureGroup>());
        MeasureVector dps = vars[0].cast<MeasureGroup>().measures(false);
        ASSERT_FALSE(dps.empty());
        ASSERT_TRUE(dps[0].optionalCast<RubyMeasure>());
        RubyMeasure rp = dps[0].cast<RubyMeasure>();
        EXPECT_TRUE(rp.usesBCLMeasure());
        EXPECT_TRUE(rp.measure());
        EXPECT_EQ(tempDir1,rp.measureDirectory());
//.........这里部分代码省略.........
开发者ID:whztt07,项目名称:OpenStudio,代码行数:101,代码来源:RubyMeasureRecord_GTest.cpp

示例10: problem

TEST_F(ProjectFixture, DataPointTagRecords) {
  // create Analysis with one DataPoint with one Tag ("test tag")
  analysis::Problem problem("problem",analysis::VariableVector(),runmanager::Workflow());
  FileReference seed(toPath("in.osm"));
  analysis::Analysis analysis("analysis",problem,seed);
  analysis::DataPoint dataPoint = problem.createDataPoint(std::vector<QVariant>()).get();
  dataPoint.addTag("test tag");
  analysis.addDataPoint(dataPoint);

  // make sure tag records follow data points around.
  // trying to replicate issue where data point tag records get repointed to
  // file reference record with id 0.
  {
    // save analysis to a new database
    ProjectDatabase database = getCleanDatabase("DataPointTagRecords");
    AnalysisRecord analysisRecord(analysis,database);
    database.save();
    ASSERT_EQ(1u,analysisRecord.dataPointRecords().size());
    DataPointRecord dataPointRecord = analysisRecord.dataPointRecords()[0];
    ASSERT_EQ(1u,dataPointRecord.tagRecords().size());
    TagRecord tagRecord = dataPointRecord.tagRecords()[0];
    EXPECT_EQ("test tag",tagRecord.name());
    analysis::DataPoint dataPoint = dataPointRecord.dataPoint();
    ASSERT_EQ(1u,dataPoint.tags().size());
    EXPECT_EQ("test tag",dataPoint.tags()[0].name());
    analysis::Analysis analysis = analysisRecord.analysis();
    ASSERT_EQ(1u,analysis.dataPoints().size());
    dataPoint = analysis.dataPoints()[0];
    ASSERT_EQ(1u,dataPoint.tags().size());
    EXPECT_EQ("test tag",dataPoint.tags()[0].name());
  }

  NameFinder<TagRecord> testRecordFinder("test tag");
  NameFinder<TagRecord> anotherTestRecordFinder("another test");
  NameFinder<Tag> testTagFinder("test tag");
  NameFinder<Tag> anotherTestTagFinder("another test");

  {
    ProjectDatabase database = getExistingDatabase("DataPointTagRecords");
    ASSERT_EQ(1u,AnalysisRecord::getAnalysisRecords(database).size());
    AnalysisRecord analysisRecord = AnalysisRecord::getAnalysisRecords(database)[0];
    ASSERT_EQ(1u,analysisRecord.dataPointRecords().size());
    DataPointRecord dataPointRecord = analysisRecord.dataPointRecords()[0];
    ASSERT_EQ(1u,dataPointRecord.tagRecords().size());
    TagRecord tagRecord = dataPointRecord.tagRecords()[0];
    EXPECT_EQ("test tag",tagRecord.name());
    analysis::DataPoint dataPoint = dataPointRecord.dataPoint();
    ASSERT_EQ(1u,dataPoint.tags().size());
    EXPECT_EQ("test tag",dataPoint.tags()[0].name());
    analysis::Analysis analysis = analysisRecord.analysis();
    ASSERT_EQ(1u,analysis.dataPoints().size());
    dataPoint = analysis.dataPoints()[0];
    ASSERT_EQ(1u,dataPoint.tags().size());
    EXPECT_EQ("test tag",dataPoint.tags()[0].name());

    // adding a second tag and resaving the analysis
    dataPoint.addTag("another test");
    analysisRecord = AnalysisRecord(analysis,database);
    bool test = database.save();
    EXPECT_TRUE(test);
    ASSERT_EQ(1u,analysisRecord.dataPointRecords().size());
    dataPointRecord = analysisRecord.dataPointRecords()[0];
    TagRecordVector tagRecords = dataPointRecord.tagRecords();
    EXPECT_EQ(2u,tagRecords.size());
    EXPECT_FALSE(std::find_if(tagRecords.begin(),tagRecords.end(),testRecordFinder) == tagRecords.end());
    EXPECT_FALSE(std::find_if(tagRecords.begin(),tagRecords.end(),anotherTestRecordFinder) == tagRecords.end());
    dataPoint = dataPointRecord.dataPoint();
    TagVector tags = dataPoint.tags();
    EXPECT_EQ(2u,tags.size());
    EXPECT_FALSE(std::find_if(tags.begin(),tags.end(),testTagFinder) == tags.end());
    EXPECT_FALSE(std::find_if(tags.begin(),tags.end(),anotherTestTagFinder) == tags.end());
    analysis = analysisRecord.analysis();
    ASSERT_EQ(1u,analysis.dataPoints().size());
    dataPoint = analysis.dataPoints()[0];
    tags = dataPoint.tags();
    EXPECT_EQ(2u,tags.size());
    EXPECT_FALSE(std::find_if(tags.begin(),tags.end(),testTagFinder) == tags.end());
    EXPECT_FALSE(std::find_if(tags.begin(),tags.end(),anotherTestTagFinder) == tags.end());
    tagRecords = TagRecord::getTagRecords(database);
    EXPECT_EQ(2u,tagRecords.size());
    EXPECT_FALSE(std::find_if(tagRecords.begin(),tagRecords.end(),testRecordFinder) == tagRecords.end());
    EXPECT_FALSE(std::find_if(tagRecords.begin(),tagRecords.end(),anotherTestRecordFinder) == tagRecords.end());
  }

  {
    ProjectDatabase database = getExistingDatabase("DataPointTagRecords");
    ASSERT_EQ(1u,AnalysisRecord::getAnalysisRecords(database).size());
    AnalysisRecord analysisRecord = AnalysisRecord::getAnalysisRecords(database)[0];
    ASSERT_EQ(1u,analysisRecord.dataPointRecords().size());
    DataPointRecord dataPointRecord = analysisRecord.dataPointRecords()[0];
    TagRecordVector tagRecords = dataPointRecord.tagRecords();
    EXPECT_EQ(2u,tagRecords.size());
    EXPECT_FALSE(std::find_if(tagRecords.begin(),tagRecords.end(),testRecordFinder) == tagRecords.end());
    EXPECT_FALSE(std::find_if(tagRecords.begin(),tagRecords.end(),anotherTestRecordFinder) == tagRecords.end());
    dataPoint = dataPointRecord.dataPoint();
    TagVector tags = dataPoint.tags();
    EXPECT_FALSE(std::find_if(tags.begin(),tags.end(),testTagFinder) == tags.end());
    EXPECT_FALSE(std::find_if(tags.begin(),tags.end(),anotherTestTagFinder) == tags.end());
    analysis = analysisRecord.analysis();
    ASSERT_EQ(1u,analysis.dataPoints().size());
//.........这里部分代码省略.........
开发者ID:CUEBoxer,项目名称:OpenStudio,代码行数:101,代码来源:TagRecord_GTest.cpp

示例11: analysis

TEST_F(ProjectFixture,DataPoint_DataPointRecord_Synchronization) {

  // create analysis with one data point
  ProjectDatabase database = getCleanDatabase("DataPoint_DataPointRecord_Synchronization");

  analysis::Analysis analysis(
      "Test Analysis",
      analysis::Problem("Test Problem",analysis::VariableVector(),runmanager::Workflow()),
      analysis::DesignOfExperiments(analysis::DesignOfExperimentsOptions(
          analysis::DesignOfExperimentsType::FullFactorial)),
      FileReference(toPath("in.osm")));

  std::vector<QVariant> variableValues;
  analysis::DataPoint original = analysis.problem().createDataPoint(variableValues).get();
  analysis.addDataPoint(original);

  // save analysis to database
  {
    bool didStartTransaction = database.startTransaction();
    AnalysisRecord analysisRecord(analysis,database);

    DataPointRecordVector dataPointRecords = DataPointRecord::getDataPointRecords(database);
    ASSERT_EQ(1u,dataPointRecords.size());
    DataPointRecord dataPointRecord = dataPointRecords[0];
    EXPECT_FALSE(dataPointRecord.isComplete());

    database.save();
    if (didStartTransaction) {
      database.commitTransaction();
    }
  }

  // reload analysis, change data point, save back to database
  // verify that change shows up in database
  OptionalAnalysis loadedAnalysis;
  {
    AnalysisRecordVector loadedAnalysisRecords = AnalysisRecord::getAnalysisRecords(database);
    ASSERT_EQ(1u,loadedAnalysisRecords.size());
    loadedAnalysis = loadedAnalysisRecords[0].analysis();

    analysis::DataPointVector loadedDataPoints = loadedAnalysis->dataPoints();
    ASSERT_EQ(1u,loadedDataPoints.size());
    loadedDataPoints[0].getImpl<analysis::detail::DataPoint_Impl>()->markComplete();
    EXPECT_TRUE(loadedDataPoints[0].isComplete());
  }
  ASSERT_TRUE(loadedAnalysis);

  {
    bool didStartTransaction = database.startTransaction();
    database.unloadUnusedCleanRecords();
    AnalysisRecord analysisRecord(*loadedAnalysis,database);
    database.save();
    if (didStartTransaction) {
      database.commitTransaction();
    }
    EXPECT_EQ(1u,AnalysisRecord::getAnalysisRecords(database).size());

    DataPointRecordVector dataPointRecords = DataPointRecord::getDataPointRecords(database);
    ASSERT_EQ(1u,dataPointRecords.size());
    DataPointRecord dataPointRecord = dataPointRecords[0];
    EXPECT_TRUE(dataPointRecord.isComplete());
  }

}
开发者ID:jtanaa,项目名称:OpenStudio,代码行数:64,代码来源:DataPointRecord_GTest.cpp

示例12: attribute

// this is a monster test that is more for testing the database than attributes
TEST_F(ProjectFixture, AttributeRecord_LoadSave)
{
  int id;
  UUID handle;
  Attribute attribute("name", 1.0, std::string("m"));
  {
    ProjectDatabase database = getCleanDatabase("AttributeRecord_LoadSave");

    EXPECT_EQ(static_cast<unsigned>(0), AttributeRecord::getAttributeRecords(database).size());

    FileReferenceRecord model(FileReference(toPath("./in.osm")),database);

    AttributeRecord attributeRecord(attribute,model);
    id = attributeRecord.id();
    handle = attributeRecord.handle();
    EXPECT_EQ("name", attributeRecord.name());
    EXPECT_EQ("name", attributeRecord.displayName());
    EXPECT_EQ("", attributeRecord.description());
    EXPECT_EQ(AttributeValueType::Double, attributeRecord.attributeValueType().value());
    EXPECT_EQ(1.0, attributeRecord.attributeValueAsDouble());
    ASSERT_TRUE(attributeRecord.attributeUnits());
    EXPECT_EQ("m", attributeRecord.attributeUnits().get());

    EXPECT_TRUE(database.includesRecord(attributeRecord));
    EXPECT_TRUE(database.isNewRecord(attributeRecord));
    EXPECT_FALSE(database.isDirtyRecord(attributeRecord));
    EXPECT_FALSE(database.isCleanRecord(attributeRecord));
    EXPECT_FALSE(database.isRemovedRecord(attributeRecord));
    EXPECT_EQ(static_cast<unsigned>(2), attributeRecord.useCount());
  }

  {
    // open existing database
    ProjectDatabase database = getExistingDatabase("AttributeRecord_LoadSave");

    // new objects were removed
    EXPECT_EQ(static_cast<unsigned>(0), AnalysisRecord::getAnalysisRecords(database).size());
    EXPECT_EQ(static_cast<unsigned>(0), FileReferenceRecord::getFileReferenceRecords(database).size());
    EXPECT_EQ(static_cast<unsigned>(0), AttributeRecord::getAttributeRecords(database).size());

    FileReferenceRecord model(FileReference(toPath("./in.osm")),database);

    // create AttributeRecord
    AttributeRecord attributeRecord(attribute, model);
    id = attributeRecord.id();
    handle = attributeRecord.handle();
    EXPECT_EQ("name", attributeRecord.name());
    EXPECT_EQ("name", attributeRecord.displayName());
    EXPECT_EQ("", attributeRecord.description());
    EXPECT_EQ(AttributeValueType::Double, attributeRecord.attributeValueType().value());
    EXPECT_EQ(1.0, attributeRecord.attributeValueAsDouble());
    ASSERT_TRUE(attributeRecord.attributeUnits());
    EXPECT_EQ("m", attributeRecord.attributeUnits().get());

    EXPECT_TRUE(database.includesRecord(attributeRecord));
    EXPECT_TRUE(database.isNewRecord(attributeRecord));
    EXPECT_FALSE(database.isDirtyRecord(attributeRecord));
    EXPECT_FALSE(database.isCleanRecord(attributeRecord));
    EXPECT_FALSE(database.isRemovedRecord(attributeRecord));
    EXPECT_EQ(static_cast<unsigned>(2), attributeRecord.useCount());

    // save to database
    EXPECT_TRUE(database.save());

    EXPECT_TRUE(database.includesRecord(attributeRecord));
    EXPECT_FALSE(database.isNewRecord(attributeRecord));
    EXPECT_FALSE(database.isDirtyRecord(attributeRecord));
    EXPECT_TRUE(database.isCleanRecord(attributeRecord));
    EXPECT_FALSE(database.isRemovedRecord(attributeRecord));
    EXPECT_EQ(static_cast<unsigned>(2), attributeRecord.useCount());
  }

  {
    // open existing database
    ProjectDatabase database = getExistingDatabase("AttributeRecord_LoadSave");

    // saved objects were not removed
    ASSERT_EQ(static_cast<unsigned>(1), FileReferenceRecord::getFileReferenceRecords(database).size());
    ASSERT_EQ(static_cast<unsigned>(1), AttributeRecord::getAttributeRecords(database).size());

    std::vector<FileReferenceRecord> fileReferenceRecords = FileReferenceRecord::getFileReferenceRecords(database);
    FileReferenceRecord model = fileReferenceRecords.at(0);
    EXPECT_EQ(static_cast<unsigned>(1), model.attributeRecords().size());
    AttributeRecord attributeRecord = model.attributeRecords()[0];

    EXPECT_EQ(id, attributeRecord.id());
    EXPECT_EQ(handle, attributeRecord.handle());
    EXPECT_EQ("name", attributeRecord.name());
    EXPECT_EQ("name", attributeRecord.displayName());
    EXPECT_EQ("", attributeRecord.description());
    EXPECT_EQ(AttributeValueType::Double, attributeRecord.attributeValueType().value());
    EXPECT_EQ(1.0, attributeRecord.attributeValueAsDouble());
    ASSERT_TRUE(attributeRecord.attributeUnits());
    EXPECT_EQ("m", attributeRecord.attributeUnits().get());

    EXPECT_TRUE(database.includesRecord(attributeRecord));
    EXPECT_FALSE(database.isNewRecord(attributeRecord));
    EXPECT_FALSE(database.isDirtyRecord(attributeRecord));
    EXPECT_TRUE(database.isCleanRecord(attributeRecord));
//.........这里部分代码省略.........
开发者ID:Rahjou,项目名称:OpenStudio,代码行数:101,代码来源:AttributeRecord_GTest.cpp

示例13: analysis

TEST_F(ProjectFixture,AnalysisRecord_AddAndRemoveDataPoints) {
  // create an analysis with data points, no results
  Analysis analysis("My Analysis",
                    Problem("My Problem",VariableVector(),runmanager::Workflow()),
                    FileReferenceType::OSM);
  Problem problem = analysis.problem();

  DiscretePerturbationVector perturbations;
  int pi = 1;
  std::stringstream ss;
  for (int i = 0; i < 3; ++i) {
    perturbations.push_back(NullPerturbation());
    for (int j = 0; j < 4; ++j) {
      ss << "measure" << pi << ".rb";
      perturbations.push_back(RubyPerturbation(toPath(ss.str()),
                                               FileReferenceType::OSM,
                                               FileReferenceType::OSM,true));
      ss.str("");
      ++pi;
    }
    ss << "Variable " << i+1;
    problem.push(DiscreteVariable(ss.str(),perturbations));
    perturbations.clear();
    ss.str("");
  }

  EXPECT_EQ(3u,analysis.problem().variables().size());
  ASSERT_FALSE(problem.variables().empty());
  EXPECT_EQ(5u,problem.variables()[0].cast<DiscreteVariable>().numPerturbations(true));

  problem.pushResponse(
        LinearFunction("Energy Use",
                       VariableVector(1u,OutputAttributeVariable("Energy Use","Total.Energy.Use"))));
  EXPECT_EQ(1u,problem.responses().size());

  std::vector<QVariant> values(3u,0);
  OptionalDataPoint dataPoint = problem.createDataPoint(values);
  ASSERT_TRUE(dataPoint);
  bool test = analysis.addDataPoint(*dataPoint);
  EXPECT_TRUE(test);
  values[1] = 3;
  dataPoint = problem.createDataPoint(values);
  ASSERT_TRUE(dataPoint);
  test = analysis.addDataPoint(*dataPoint);
  EXPECT_TRUE(test);
  values[0] = 1;
  values[1] = 2;
  values[2] = 4;
  dataPoint = problem.createDataPoint(values);
  ASSERT_TRUE(dataPoint);
  test = analysis.addDataPoint(*dataPoint);
  EXPECT_TRUE(test);

  EXPECT_TRUE(analysis.isDirty());
  EXPECT_TRUE(problem.isDirty());
  BOOST_FOREACH(const Variable& variable, problem.variables()) {
    EXPECT_TRUE(variable.isDirty());
    ASSERT_TRUE(variable.optionalCast<DiscreteVariable>());
    BOOST_FOREACH(const DiscretePerturbation& perturbation,variable.cast<DiscreteVariable>().perturbations(false)) {
      EXPECT_TRUE(perturbation.isDirty());
    }
  }
  BOOST_FOREACH(const Function& response, problem.responses()) {
    EXPECT_TRUE(response.isDirty());
  }
  BOOST_FOREACH(const DataPoint& dataPoint, analysis.dataPoints()) {
    EXPECT_TRUE(dataPoint.isDirty());
  }

  // save to database, make sure everything is there, make sure clean signal filters down
  ProjectDatabase database = getCleanDatabase("AnalysisRecord_AddAndRemoveDataPoints");
  {
    bool transactionStarted = database.startTransaction();
    EXPECT_TRUE(transactionStarted);
    AnalysisRecord analysisRecord(analysis,database);
    database.save();
    test = database.commitTransaction();
    EXPECT_TRUE(test);
    EXPECT_EQ(analysis.uuid(),analysisRecord.handle());
    EXPECT_EQ(analysis.versionUUID(),analysisRecord.uuidLast());
    ASSERT_NO_THROW(analysisRecord.problemRecord());
    ProblemRecord problemRecord = analysisRecord.problemRecord();
    InputVariableRecordVector variableRecords = problemRecord.inputVariableRecords();
    EXPECT_EQ(3u,variableRecords.size());
    ASSERT_FALSE(variableRecords.empty());
    ASSERT_TRUE(variableRecords[0].optionalCast<DiscreteVariableRecord>());
    DiscretePerturbationRecordVector perturbationRecords = variableRecords[0].cast<DiscreteVariableRecord>().discretePerturbationRecords(false);
    EXPECT_EQ(5u,perturbationRecords.size());
    ASSERT_TRUE(perturbationRecords.size() > 1);
    EXPECT_TRUE(perturbationRecords[0].optionalCast<NullPerturbationRecord>());
    EXPECT_TRUE(perturbationRecords[1].optionalCast<RubyPerturbationRecord>());
    EXPECT_EQ(3u,analysisRecord.dataPointRecords().size());
    EXPECT_TRUE(analysisRecord.completeDataPointRecords().empty());
  }

  analysis.clearDirtyFlag();
  EXPECT_FALSE(analysis.isDirty());
  EXPECT_FALSE(problem.isDirty());
  BOOST_FOREACH(const Variable& variable, problem.variables()) {
    EXPECT_FALSE(variable.isDirty());
//.........这里部分代码省略.........
开发者ID:Rahjou,项目名称:OpenStudio,代码行数:101,代码来源:AnalysisRecord_GTest.cpp


注:本文中的ProjectDatabase::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。