Esempio n. 1
0
std::vector<Attribute> AlgorithmRecord_Impl::options() const {
    AttributeVector result;
    BOOST_FOREACH(const ObjectRecord& child, children()) {
        if (OptionalAttributeRecord attributeRecord = child.optionalCast<AttributeRecord>()) {
            result.push_back(attributeRecord->attribute());
        }
    }
    return result;
}
 boost::optional<analysis::UncertaintyDescription> InputVariableRecord_Impl::uncertaintyDescription() const {
   analysis::OptionalUncertaintyDescription result;
   if (m_uncertaintyDescriptionType) {
     AttributeVector attributes;
     for (const AttributeRecord& attributeRecord : attributeRecords()) {
       attributes.push_back(attributeRecord.attribute());
     }
     result = analysis::GenericUncertaintyDescription(*m_uncertaintyDescriptionType,attributes);
   }
   return result;
 }
TEST_F(ProjectFixture, AttributeRecord_AttributeTypes)
{
  ProjectDatabase database = getCleanDatabase("AttributeRecord_AttributeTypes");

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

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

  // make attributes
  Attribute boolAttribute("bool", true);
  Attribute unsignedAttribute("unsigned", 2u);
  Attribute intAttribute("int", -1);
  Attribute doubleAttribute("double", 1.23, std::string("m"));
  Attribute stringAttribute("string", "hello");
  // because of tracking by UUID, have to make separate child attributes
  AttributeVector childAttributes;
  childAttributes.push_back(Attribute("bool", true));
  childAttributes.push_back(Attribute("bool", true));
  Attribute vectorAttribute("vector", childAttributes);

  // create AttributeRecords
  AttributeRecord boolAttributeRecord(boolAttribute, model);
  AttributeRecord unsignedAttributeRecord(unsignedAttribute, model);
  AttributeRecord intAttributeRecord(intAttribute, model);
  AttributeRecord doubleAttributeRecord(doubleAttribute, model);
  AttributeRecord stringAttributeRecord(stringAttribute, model);
  AttributeRecord vectorAttributeRecord(vectorAttribute, model);

  ASSERT_TRUE(model.getAttributeRecord("bool"));
  EXPECT_TRUE(boolAttribute == model.getAttributeRecord("bool").get().attribute());
  ASSERT_TRUE(model.getAttributeRecord("unsigned"));
  EXPECT_TRUE(unsignedAttribute == model.getAttributeRecord("unsigned").get().attribute());
  ASSERT_TRUE(model.getAttributeRecord("int"));
  EXPECT_TRUE(intAttribute == model.getAttributeRecord("int").get().attribute());
  ASSERT_TRUE(model.getAttributeRecord("double"));
  EXPECT_TRUE(doubleAttribute == model.getAttributeRecord("double").get().attribute());
  ASSERT_TRUE(model.getAttributeRecord("string"));
  EXPECT_TRUE(stringAttribute == model.getAttributeRecord("string").get().attribute());
  ASSERT_TRUE(model.getAttributeRecord("vector"));
  EXPECT_TRUE(vectorAttribute == model.getAttributeRecord("vector").get().attribute());

  EXPECT_EQ(static_cast<unsigned>(6), AttributeRecord::getAttributeRecords(database).size());
  EXPECT_EQ(static_cast<unsigned>(6), model.attributeRecords().size());

  database.save();
}
void ShipComponentData::getAttributes(AttributeVector & data) const
{
	Unicode::String attrib;
	static char buffer[128];
	static const size_t buffer_size = sizeof (buffer);

	//armor
	snprintf(buffer, buffer_size, "%.1f", m_armorHitpointsCurrent);
	attrib = Unicode::narrowToWide(buffer);
	attrib += cm_slash;
	snprintf(buffer, buffer_size, "%.1f", m_armorHitpointsMaximum);
	attrib += Unicode::narrowToWide(buffer);
	data.push_back(std::make_pair(cm_shipComponentCategory + SharedObjectAttributes::ship_component_armor, attrib));

	//hitpoints
	snprintf(buffer, buffer_size, "%.1f", m_hitpointsCurrent);
	attrib = Unicode::narrowToWide(buffer);
	attrib += cm_slash;
	snprintf(buffer, buffer_size, "%.1f", m_hitpointsMaximum);
	attrib += Unicode::narrowToWide(buffer);
	data.push_back(std::make_pair(cm_shipComponentCategory + SharedObjectAttributes::ship_component_hitpoints, attrib));

	//general efficiency
	if(m_efficiencyGeneral < 1.0f)
	{
		snprintf(buffer, buffer_size, "%.1f", m_efficiencyGeneral);
		attrib = Unicode::narrowToWide(buffer);
		data.push_back(std::make_pair(cm_shipComponentCategory + SharedObjectAttributes::ship_component_efficiency_general, attrib));
	}

	//energy efficiency
	if(m_efficiencyEnergy < 1.0f)
	{
		snprintf(buffer, buffer_size, "%.1f", m_efficiencyEnergy);
		attrib = Unicode::narrowToWide(buffer);
		data.push_back(std::make_pair(cm_shipComponentCategory + SharedObjectAttributes::ship_component_efficiency_energy, attrib));
	}

	//energy maintenance requirement
	if(m_energyMaintenanceRequirement > 0.0f)
	{
		snprintf(buffer, buffer_size, "%.1f", m_energyMaintenanceRequirement);
		attrib = Unicode::narrowToWide(buffer);
		data.push_back(std::make_pair(cm_shipComponentCategory + SharedObjectAttributes::ship_component_energy_required, attrib));
	}

	//mass
	snprintf(buffer, buffer_size, "%.1f", m_mass);
	attrib = Unicode::narrowToWide(buffer);
	data.push_back(std::make_pair(cm_shipComponentCategory + SharedObjectAttributes::ship_component_mass, attrib));
}
Esempio n. 5
0
bool OSRunner::validateUserArguments(const std::vector<OSArgument>& script_arguments,
                                     const std::map<std::string, OSArgument>& user_arguments)
{
    bool result(true);
    std::stringstream ss;
    AttributeVector argumentValueAttributes;
    for (const OSArgument& script_argument : script_arguments) {
        auto it = user_arguments.find(script_argument.name());
        if (it == user_arguments.end()) {
            // script_argument is not in user_arguments
            // this is only okay for purely optional arguments
            if (script_argument.required() || script_argument.hasDefaultValue()) {
                ss << "Argument " << script_argument.name() << " is required or has a default value, ";
                ss << "but is not in user_arguments.";
                registerError(ss.str());
                ss.str("");
                result = false;
            }
        }
        else {
            // script_argument is in user_arguments
            OSArgument user_argument = it->second;

            // check that names still match
            if (user_argument.name() != script_argument.name()) {
                ss << "User argument name '" << user_argument.name() << "' does not match map key ";
                ss << script_argument.name() << ".";
                registerWarning(ss.str());
                ss.str("");
            }

            // check that types still match
            if (user_argument.type() != script_argument.type()) {
                ss << "User argument type " << user_argument.type().valueName() << " does not match ";
                ss << "script argument type " << script_argument.type().valueName() << ".";
                registerError(ss.str());
                ss.str("");
                result = false;
            }

            //  check that we have values
            if ((script_argument.required()) &&
                    !(user_argument.hasValue() || user_argument.hasDefaultValue()))
            {
                ss << "Script argument '" << script_argument.name() << "' is required, ";
                ss << "but the user argument does not have a value or default value set.";
                registerError(ss.str());
                ss.str("");
                result = false;
            }

            // check for default value mismatch
            if (script_argument.hasDefaultValue() && !user_argument.hasDefaultValue()) {
                ss << "Script argument '" << script_argument.name() << "' has a default value, but the ";
                ss << "user-supplied version does not.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (!script_argument.hasDefaultValue() && user_argument.hasDefaultValue()) {
                ss << "Script argument '" << script_argument.name() << "' does not have a default value, ";
                ss << "but the user-supplied version does.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (script_argument.hasDefaultValue() && user_argument.hasDefaultValue() &&
                    (user_argument.type() == script_argument.type()))
            {
                ss << "The default value of script argument " << std::endl << script_argument << std::endl;
                ss << "does not match that of the corresponding user argument " << std::endl << user_argument << ".";
                switch (script_argument.type().value()) {
                case OSArgumentType::Boolean :
                    if (user_argument.defaultValueAsBool() != script_argument.defaultValueAsBool()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Double :
                    if (user_argument.defaultValueAsDouble() != script_argument.defaultValueAsDouble()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Quantity :
                    if (user_argument.defaultValueAsQuantity() != script_argument.defaultValueAsQuantity()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Integer :
                    if (user_argument.defaultValueAsInteger() != script_argument.defaultValueAsInteger()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::String :
                case OSArgumentType::Choice :
                case OSArgumentType::Path :
                    if (user_argument.defaultValueAsString() != script_argument.defaultValueAsString()) {
                        registerWarning(ss.str());
                    }
                    break;
                default :
                    OS_ASSERT(false);
                }
                ss.str("");
            }

            // check for domain mismatch
            if (script_argument.hasDomain() && !user_argument.hasDomain()) {
                ss << "Script argument '" << script_argument.name() << "' has a specified domain, but the ";
                ss << "user-supplied version does not.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (!script_argument.hasDomain() && user_argument.hasDomain()) {
                ss << "Script argument '" << script_argument.name() << "' does not have a specified domain, ";
                ss << "but the user-supplied version does.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (script_argument.hasDomain() && user_argument.hasDomain() &&
                    (user_argument.type() == script_argument.type()))
            {
                ss << "The domain of script argument " << std::endl << script_argument << std::endl;
                ss << "does not match that of the corresponding user argument " << std::endl << user_argument << ".";
                switch (script_argument.type().value()) {
                case OSArgumentType::Boolean:
                    // DLM: should bool's even have domains?
                    if (user_argument.domainAsBool() != script_argument.domainAsBool()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Double:
                    if (user_argument.domainAsDouble() != script_argument.domainAsDouble()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Quantity:
                    // DLM: deprecated forget about getting this to compile
                    //if (user_argument.domainAsQuantity() != script_argument.domainAsQuantity()) {
                    //  registerWarning(ss.str());
                    //}
                    break;
                case OSArgumentType::Integer:
                    if (user_argument.domainAsInteger() != script_argument.domainAsInteger()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::String:
                case OSArgumentType::Choice:
                case OSArgumentType::Path:
                    if (user_argument.domainAsString() != script_argument.domainAsString()) {
                        registerWarning(ss.str());
                    }
                    break;
                default:
                    OS_ASSERT(false);
                }
                ss.str("");
            }

            // success, set the values
            if (result) {
                Quantity q;
                switch(user_argument.type().value()) {
                case OSArgumentType::Boolean :
                    if (user_argument.hasValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsBool()));
                    } else if (user_argument.hasDefaultValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsBool()));
                    }
                    break;
                case OSArgumentType::Double :
                    if (user_argument.hasValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsDouble()));
                    } else if (user_argument.hasDefaultValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsDouble()));
                    }
                    break;
                case OSArgumentType::Quantity :
                    if (user_argument.hasValue()) {
                        q = user_argument.valueAsQuantity();
                    } else if (user_argument.hasDefaultValue()) {
                        q = user_argument.defaultValueAsQuantity();
                    }
                    argumentValueAttributes.push_back(Attribute(user_argument.name(),q.value(),q.units().print()));
                    break;
                case OSArgumentType::Integer :
                    if (user_argument.hasValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsInteger()));
                    } else if (user_argument.hasDefaultValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsInteger()));
                    }
                    break;
                case OSArgumentType::String :
                case OSArgumentType::Choice :
                case OSArgumentType::Path :
                    if (user_argument.hasValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsString()));
                    } else if (user_argument.hasDefaultValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsString()));
                    }
                    break;
                default:
                    OS_ASSERT(false);
                }
            }
        }
    }

    if (result) {
        for (Attribute& attribute : argumentValueAttributes) {
            registerAttribute(attribute);
        }
    }

    return result;
}
Esempio n. 6
0
openstudio::analysis::Analysis AnalysisFixture::analysis1(AnalysisState state) {
  // Create problem and analysis
  Problem problem("My Problem");

  BCLMeasure bclMeasure(resourcesPath() / toPath("utilities/BCL/Measures/SetWindowToWallRatioByFacade"));
  RubyMeasure measure(bclMeasure);

  // Measure Group
  StringVector choices;
  choices.push_back("North");
  choices.push_back("South");
  choices.push_back("East");
  choices.push_back("West");
  OSArgument facade = OSArgument::makeChoiceArgument("facade",choices);
  OSArgument arg = facade.clone();
  arg.setValue("South");
  measure.setArgument(arg);
  OSArgument wwr = OSArgument::makeDoubleArgument("wwr");
  MeasureVector measures(1u,NullMeasure());
  measures.push_back(measure.clone().cast<Measure>());
  arg = wwr.clone();
  arg.setValue(0.1);
  measures.back().cast<RubyMeasure>().setArgument(arg);
  measures.push_back(measure.clone().cast<Measure>());
  arg = wwr.clone();
  arg.setValue(0.2);
  measures.back().cast<RubyMeasure>().setArgument(arg);
  measures.push_back(measure.clone().cast<Measure>());
  arg = wwr.clone();
  arg.setValue(0.3);
  measures.back().cast<RubyMeasure>().setArgument(arg);
  problem.push(MeasureGroup("South Windows",measures));

  // Continuous Variables Attached to Arguments
  arg = facade.clone();
  arg.setValue("North");
  measure.setArgument(arg);
  arg = wwr.clone();
  RubyContinuousVariable wwrCV("Window to Wall Ratio",arg,measure);
  wwrCV.setMinimum(0.0);
  wwrCV.setMaximum(1.0);
  TriangularDistribution td(0.2,0.0,0.5);
  wwrCV.setUncertaintyDescription(td);
  problem.push(wwrCV);
  OSArgument offset = OSArgument::makeDoubleArgument("offset");
  RubyContinuousVariable offsetCV("Offset",offset,measure);
  offsetCV.setMinimum(0.0);
  offsetCV.setMaximum(1.5);
  NormalDistribution nd(0.9,0.05);
  offsetCV.setUncertaintyDescription(nd);
  problem.push(offsetCV);

  // Simulation
  problem.push(WorkItem(JobType::ModelToIdf));
  problem.push(WorkItem(JobType::EnergyPlusPreProcess));
  problem.push(WorkItem(JobType::EnergyPlus));
  problem.push(WorkItem(JobType::OpenStudioPostProcess));

  // Responses
  LinearFunction response1("Energy Use Intensity",
                           VariableVector(1u,OutputAttributeVariable("EUI","site.eui")));
  problem.pushResponse(response1);
  VariableVector vars;
  vars.push_back(OutputAttributeVariable("Heating Energy","heating.energy.gas"));
  vars.push_back(OutputAttributeVariable("Cooling Energy","cooling.energy.elec"));
  DoubleVector coeffs;
  coeffs.push_back(1.0); // approx. source factor
  coeffs.push_back(2.5); // approx. source factor
  LinearFunction response2("Approximate Source Energy",vars,coeffs);
  problem.pushResponse(response2);
  LinearFunction response3("North WWR",VariableVector(1u,wwrCV)); // input variable as output
  problem.pushResponse(response3);

  Analysis analysis("My Analysis",problem,FileReferenceType::OSM);

  if (state == PreRun) {
    // Add three DataPoints
    std::vector<QVariant> values;
    values.push_back(0);
    values.push_back(0.2);
    values.push_back(0.9);
    OptionalDataPoint dataPoint = problem.createDataPoint(values);
    analysis.addDataPoint(*dataPoint);
    values[0] = 1; values[1] = 0.21851789; values[2] = 1.1681938;
    dataPoint = problem.createDataPoint(values);
    analysis.addDataPoint(*dataPoint);
    values[0] = 2; values[1] = 0.0; values[2] = 0.581563892;
    dataPoint = problem.createDataPoint(values);
    analysis.addDataPoint(*dataPoint);
  }
  else {
    // state == PostRun
    // Add one complete DataPoint
    std::vector<QVariant> values;
    values.push_back(1);
    values.push_back(0.3);
    values.push_back(0.9);
    DoubleVector responseValues;
    responseValues.push_back(58.281967);
    responseValues.push_back(718952.281);
    responseValues.push_back(0.3);
    TagVector tags;
    tags.push_back(Tag("custom"));
    tags.push_back(Tag("faked"));
    // attributes
    AttributeVector attributes;
    attributes.push_back(Attribute("electricity.Cooling",281.281567,"kWh"));
    attributes.push_back(Attribute("electricity.Lighting",19206.291876,"kWh"));
    attributes.push_back(Attribute("electricity.Equipment",5112.125718,"kWh"));
    attributes = AttributeVector(1u,Attribute("enduses.electric",attributes));
    attributes.push_back(Attribute("eui",createQuantity(128.21689,"kBtu/ft^2").get()));
    // complete job
    // 1. get vector of work items
    std::vector<WorkItem> workItems;
    // 0
    workItems.push_back(problem.variables()[0].cast<MeasureGroup>().createWorkItem(QVariant(1),
                                                                                   toPath(rubyOpenStudioDir())));
    RubyContinuousVariable rcv = problem.variables()[1].cast<RubyContinuousVariable>();
    RubyMeasure rm = rcv.measure();
    OSArgument arg = rcv.argument().clone();
    arg.setValue(values[1].toDouble());
    rm.setArgument(arg);
    rcv = problem.variables()[2].cast<RubyContinuousVariable>();
    arg = rcv.argument().clone();
    arg.setValue(values[2].toDouble());
    rm.setArgument(arg);
    // 1
    workItems.push_back(rm.createWorkItem(toPath(rubyOpenStudioDir())));
    // 2
    workItems.push_back(WorkItem(JobType::ModelToIdf));
    // 3
    workItems.push_back(WorkItem(JobType::EnergyPlusPreProcess));
    // 4
    workItems.push_back(WorkItem(JobType::EnergyPlus));
    // 5
    workItems.push_back(WorkItem(JobType::OpenStudioPostProcess));
    // 2. step through work items and create jobs with results
    WorkItem wi = workItems[5];
    std::vector<FileInfo> inFiles = wi.files.files();
    inFiles.push_back(FileInfo("eplusout.sql",
                               DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,33,32)),
                               "",
                               toPath("myProject/fakeDataPoint/75-OpenStudioPostProcess-0/eplusout.sql")));                             
    Files inFilesObject(inFiles);
    std::vector<std::pair<ErrorType, std::string> > errors;
    errors.push_back(std::make_pair(ErrorType::Info,"Post-process completed successfully."));
    JobErrors errorsObject(OSResultValue::Success,errors);
    std::vector<FileInfo> outFiles;
    outFiles.push_back(FileInfo("report.xml",
                                DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,34,21)),
                                "",
                                toPath("myProject/fakeDataPoint/75-OpenStudioPostProcess-0/report.xml")));
    Files outFilesObject(outFiles);
    Job job = JobFactory::createJob(
          wi.type,
          wi.tools,
          wi.params,
          inFilesObject,
          std::vector<openstudio::URLSearchPath>(),
          false,
          createUUID(),
          JobState(
            DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,34,21)),
            errorsObject,
            outFilesObject,
            AdvancedStatus(),
            openstudio::path())

          ); // OpenStudioPostProcess

    Job jobLast = job;
    wi = workItems[4];
    inFiles = wi.files.files();
    inFiles.push_back(FileInfo("in.idf",
                                DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,23,05)),
                                "",
                                toPath("myProject/fakeDataPoint/74-EnergyPlus-0/in.idf")));
    inFilesObject = Files(inFiles);
    errors.clear();
    errors.push_back(std::make_pair(ErrorType::Warning,"ENERGYPLUS WARNING: ..."));
    errors.push_back(std::make_pair(ErrorType::Warning,"ENERGYPLUS WARNING: ..."));
    errors.push_back(std::make_pair(ErrorType::Warning,"ENERGYPLUS WARNING: ..."));
    errorsObject = JobErrors(OSResultValue::Success,errors);
    outFiles.clear();
    outFiles.push_back(FileInfo("eplusout.sql",
                                DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,33,32)),
                                "",
                                toPath("myProject/fakeDataPoint/74-EnergyPlus-0/eplusout.sql")));
    outFiles.push_back(FileInfo("eplusout.err",
                                DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,33,34)),
                                "",
                                toPath("myProject/fakeDataPoint/74-EnergyPlus-0/eplusout.err")));
    outFilesObject = Files(outFiles);
    job = JobFactory::createJob(
          wi.type,
          wi.tools,
          wi.params,
          inFilesObject,
          std::vector<openstudio::URLSearchPath>(),
          false,
          createUUID(),
          JobState(
            DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,33,42)),
            errorsObject,
            outFilesObject,
            AdvancedStatus(),
            openstudio::path())
          ); // EnergyPlus
    job.addChild(jobLast);

    jobLast = job;
    wi = workItems[3];
    inFiles = wi.files.files();
    inFiles.push_back(FileInfo("in.idf",
                                DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,22,30)),
                                "",
                                toPath("myProject/fakeDataPoint/73-EnergyPlusPreProcess-0/in.idf")));
    inFilesObject = Files(inFiles);
    errors.clear();
    errorsObject = JobErrors(OSResultValue::Success,errors);
    outFiles.clear();
    outFiles.push_back(FileInfo("out.idf",
                                DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,23,05)),
                                "",
                                toPath("myProject/fakeDataPoint/73-EnergyPlusPreProcess-0/out.idf")));
    outFilesObject = Files(outFiles);
    job = JobFactory::createJob(
          wi.type,
          wi.tools,
          wi.params,
          inFilesObject,
          std::vector<openstudio::URLSearchPath>(),
          false,
          createUUID(),
          JobState(
            DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,23,12)),
            errorsObject,
            outFilesObject,
            AdvancedStatus(),
            openstudio::path())
          ); // EnergyPlusPreProcess
    job.addChild(jobLast);

    jobLast = job;
    wi = workItems[2];
    inFiles = wi.files.files();
    inFiles.push_back(FileInfo("in.osm",
                                DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,22,01)),
                                "",
                                toPath("myProject/fakeDataPoint/72-ModelToIdf-0/in.osm")));
    inFilesObject = Files(inFiles);
    errors.clear();
    errors.push_back(std::make_pair(ErrorType::Info,"Did not find ScheduleTypeLimits for Schedule ..."));
    errors.push_back(std::make_pair(ErrorType::Warning,"Unexpectedly did not find a child object of a certain type, replaced with a default one."));
    errorsObject = JobErrors(OSResultValue::Success,errors);
    outFiles.clear();
    outFiles.push_back(FileInfo("out.idf",
                                DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,22,30)),
                                "",
                                toPath("myProject/fakeDataPoint/72-ModelToIdf-0/out.idf")));
    outFilesObject = Files(outFiles);
    job = JobFactory::createJob(
          wi.type,
          wi.tools,
          wi.params,
          inFilesObject,
          std::vector<openstudio::URLSearchPath>(),
          false,
          createUUID(),
          JobState(
            DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,22,32)),
            errorsObject,
            outFilesObject,
            AdvancedStatus(),
            openstudio::path())
          ); // ModelToIdf
    job.addChild(jobLast);

    jobLast = job;
    wi = workItems[1];
    errors.clear();
    errors.push_back(std::make_pair(ErrorType::InitialCondition,"Started with a window to wall ratio of ..."));
    errors.push_back(std::make_pair(ErrorType::FinalCondition,"Set the window to wall ratio ..."));
    errorsObject = JobErrors(OSResultValue::Success,errors);
    outFiles.clear();
    outFilesObject = Files(outFiles);
    wi.params.append("outdir","myProject/fakeDataPoint/");
    job = JobFactory::createJob(
          wi.type,
          wi.tools,
          wi.params,
          wi.files,
          std::vector<openstudio::URLSearchPath>(),
          false,
          createUUID(),
          JobState(
            DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,21,52)),
            errorsObject,
            outFilesObject,
            AdvancedStatus(),
            openstudio::path())
          ); // Variables 2 & 3
    job.addChild(jobLast);

    jobLast = job;
    wi = workItems[0];
    errors.clear();
    errors.push_back(std::make_pair(ErrorType::InitialCondition,"Started with a window to wall ratio of ..."));
    errors.push_back(std::make_pair(ErrorType::FinalCondition,"Set the window to wall ratio ..."));
    errorsObject = JobErrors(OSResultValue::Success,errors);
    outFiles.clear();
    outFilesObject = Files(outFiles);
    // add outdir job param
    JobParams params = wi.params;
    params.append("outdir","myProject/fakeDataPoint");
    job = JobFactory::createJob(
          wi.type,
          wi.tools,
          params,
          wi.files,
          std::vector<openstudio::URLSearchPath>(),
          false,
          createUUID(),
          JobState(
            DateTime(Date(MonthOfYear::Mar,21,2018),Time(0,8,21,10)),
            errorsObject,
            outFilesObject,
            AdvancedStatus(),
            openstudio::path())
          ); // Variable 1
    job.addChild(jobLast);

    DataPoint dataPoint(createUUID(),
                        createUUID(),
                        "fakeDataPoint",
                        "Fake Data Point",
                        "Demonstrating json serialization of complete DataPoint.",
                        problem,
                        true,
                        false,
                        true,
                        DataPointRunType::Local,
                        values,
                        responseValues,
                        toPath("myProject/fakeDataPoint/"),
                        FileReference(toPath("myProject/fakeDataPoint/71-Ruby-0/out.osm")),
                        FileReference(toPath("myProject/fakeDataPoint/72-ModelToIdf-0/out.idf")),
                        FileReference(toPath("myProject/fakeDataPoint/74-EnergyPlus-0/eplusout.sql")),
                        FileReferenceVector(1u,FileReference(toPath("myProject/fakeDataPoint/75-OpenStudioPostProcess-0/report.xml"))),
                        job,
                        std::vector<openstudio::path>(),
                        tags,
                        attributes);
    EXPECT_TRUE(analysis.addDataPoint(dataPoint));
  }

  return analysis;
}
Esempio n. 7
0
TEST_F(DataFixture, Attribute_Source) {
  AttributeVector attributes;

  // create vector of attributes with no sources
  attributes.push_back(Attribute("My Boolean Attribute",false));
  attributes.push_back(Attribute("My Double Attribute",34.2,"W"));
  attributes.push_back(Attribute("My Integer Attribute",5));
  attributes.push_back(Attribute("My String Attribute","flat finish"));
  attributes.push_back(Attribute("tricky_source","don't talk back"));

  // xml and back
  Attribute container("Containing Attribute",attributes);
  QDomDocument doc = container.toXml();
  OptionalAttribute containerCopy = Attribute::loadFromXml(doc);
  ASSERT_TRUE(containerCopy);
  AttributeVector attributesCopy = containerCopy.get().valueAsAttributeVector();
  EXPECT_EQ(attributes.size(),attributesCopy.size());
  for (const Attribute& attributeCopy : attributesCopy) {
    EXPECT_TRUE(attributeCopy.source().empty());
  }

  // json and back
  QVariant variant = detail::toVariant(attributes);
  int n = variant.toMap().size();
  attributesCopy = detail::toVectorOfAttribute(variant,VersionString(openStudioVersion()));
  EXPECT_EQ(attributes.size(),attributesCopy.size());
  for (const Attribute& attributeCopy : attributesCopy) {
    EXPECT_TRUE(attributeCopy.source().empty());
  }

  // apply same source to all attributes
  for (Attribute& attribute : attributes) {
    attribute.setSource("big data set");
  }

  // xml and back
  doc = container.toXml();
  containerCopy = Attribute::loadFromXml(doc);
  ASSERT_TRUE(containerCopy);
  attributesCopy = containerCopy.get().valueAsAttributeVector();
  EXPECT_EQ(attributes.size(),attributesCopy.size());
  for (const Attribute& attributeCopy : attributesCopy) {
    EXPECT_EQ("big data set",attributeCopy.source());
  }

  // json and back
  variant = detail::toVariant(attributes);
  EXPECT_EQ(n+1,variant.toMap().size());
  attributesCopy = detail::toVectorOfAttribute(variant,VersionString(openStudioVersion()));
  EXPECT_EQ(attributes.size(),attributesCopy.size());
  for (const Attribute& attributeCopy : attributesCopy) {
    EXPECT_EQ("big data set",attributeCopy.source());
  }

  // change one attribute's source to something different
  attributes[2].setSource("a wiki");

  // xml and back
  doc = container.toXml();
  containerCopy = Attribute::loadFromXml(doc);
  ASSERT_TRUE(containerCopy);
  attributesCopy = containerCopy.get().valueAsAttributeVector();
  EXPECT_EQ(attributes.size(),attributesCopy.size());
  for (const Attribute& attributeCopy : attributesCopy) {
    EXPECT_FALSE(attributeCopy.source().empty());
  }
  EXPECT_EQ("a wiki",attributesCopy[2].source());

  // json and back
  variant = detail::toVariant(attributes);
  EXPECT_EQ(n+attributes.size(),variant.toMap().size());
  attributesCopy = detail::toVectorOfAttribute(variant,VersionString(openStudioVersion()));
  EXPECT_EQ(attributes.size(),attributesCopy.size());
  for (const Attribute& attributeCopy : attributesCopy) {
    EXPECT_FALSE(attributeCopy.source().empty());
  }
  // order is not guaranteed

}