void EC_DynamicComponent::DeserializeCommon(std::vector<DeserializeData>& deserializedAttributes, AttributeChange::Type change) { // Sort both lists in alphabetical order. AttributeVector oldAttributes = NonEmptyAttributes(); std::stable_sort(oldAttributes.begin(), oldAttributes.end(), &CmpAttributeById); std::stable_sort(deserializedAttributes.begin(), deserializedAttributes.end(), &CmpAttributeDataById); std::vector<DeserializeData> addAttributes; std::vector<DeserializeData> remAttributes; AttributeVector::iterator iter1 = oldAttributes.begin(); std::vector<DeserializeData>::iterator iter2 = deserializedAttributes.begin(); // Check what attributes we need to add or remove from the dynamic component (done by comparing two list differences). while(iter1 != oldAttributes.end() || iter2 != deserializedAttributes.end()) { // No point to continue the iteration if other list is empty. We can just push all new attributes into the dynamic component. if(iter1 == oldAttributes.end()) { for(;iter2 != deserializedAttributes.end(); ++iter2) addAttributes.push_back(*iter2); break; } // Only old attributes are left and they can be removed from the dynamic component. else if(iter2 == deserializedAttributes.end()) { for(;iter1 != oldAttributes.end(); ++iter1) remAttributes.push_back(DeserializeData((*iter1)->Id())); break; } // Attribute has already created and we only need to update it's value. if((*iter1)->Id() == (*iter2).id_) { //SetAttribute(QString::fromStdString(iter2->name_), QString::fromStdString(iter2->value_), change); for(AttributeVector::const_iterator attr_iter = attributes.begin(); attr_iter != attributes.end(); ++attr_iter) if((*attr_iter)->Id() == iter2->id_) (*attr_iter)->FromString(iter2->value_.toStdString(), change); ++iter2; ++iter1; } // Found a new attribute that need to be created and added to the component. else if((*iter1)->Id() > (*iter2).id_) { addAttributes.push_back(*iter2); ++iter2; } // Couldn't find the attribute in a new list so it need to be removed from the component. else { remAttributes.push_back(DeserializeData((*iter1)->Id())); ++iter1; } } while(!addAttributes.empty()) { DeserializeData attributeData = addAttributes.back(); IAttribute *attribute = CreateAttribute(attributeData.type_, attributeData.id_); if (attribute) attribute->FromString(attributeData.value_.toStdString(), change); addAttributes.pop_back(); } while(!remAttributes.empty()) { DeserializeData attributeData = remAttributes.back(); RemoveAttribute(attributeData.id_); remAttributes.pop_back(); } }
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; }
bool EC_DynamicComponent::ContainSameAttributes(const EC_DynamicComponent &comp) const { AttributeVector myAttributeVector = NonEmptyAttributes(); AttributeVector attributeVector = comp.NonEmptyAttributes(); if(attributeVector.size() != myAttributeVector.size()) return false; if(attributeVector.empty() && myAttributeVector.empty()) return true; std::sort(myAttributeVector.begin(), myAttributeVector.end(), &CmpAttributeById); std::sort(attributeVector.begin(), attributeVector.end(), &CmpAttributeById); AttributeVector::const_iterator iter1 = myAttributeVector.begin(); AttributeVector::const_iterator iter2 = attributeVector.begin(); while(iter1 != myAttributeVector.end() && iter2 != attributeVector.end()) { // Compare attribute names and type and if they mach continue iteration if not components aren't exactly the same. if (((*iter1)->Id().compare((*iter2)->Id(), Qt::CaseInsensitive) == 0) && (*iter1)->TypeName().compare((*iter2)->TypeName(), Qt::CaseInsensitive) == 0) { if(iter1 != myAttributeVector.end()) ++iter1; if(iter2 != attributeVector.end()) ++iter2; } else { return false; } } return true; /*// Get both attributes and check if they are holding exact number of attributes. AttributeVector myAttributeVector = Attributes(); AttributeVector attributeVector = comp.Attributes(); if(attributeVector.size() != myAttributeVector.size()) return false; // Compare that every attribute is same in both components. QSet<IAttribute*> myAttributeSet; QSet<IAttribute*> attributeSet; for(uint i = 0; i < myAttributeSet.size(); i++) { attributeSet.insert(myAttributeVector[i]); myAttributeSet.insert(attributeVector[i]); } if(attributeSet != myAttributeSet) return false; return true;*/ }
TEST_F(AnalysisFixture, DDACEAlgorithmOptions) { // problem with three variables VariableVector variables; BCLMeasure bclMeasure(resourcesPath() / toPath("utilities/BCL/Measures/v2/SetWindowToWallRatioByFacade")); RubyMeasure measure(bclMeasure); variables.push_back(RubyContinuousVariable("Var 1",OSArgument::makeDoubleArgument("wwr1"),measure)); variables.push_back(RubyContinuousVariable("Var 2",OSArgument::makeDoubleArgument("wwr2"),measure)); variables.push_back(RubyContinuousVariable("Var 3",OSArgument::makeDoubleArgument("wwr3"),measure)); Problem problem("Null Problem",variables,runmanager::Workflow()); DDACEAlgorithmOptions options(DDACEAlgorithmType::grid); EXPECT_EQ(DDACEAlgorithmType(DDACEAlgorithmType::grid),options.algorithmType()); EXPECT_FALSE(options.samples()); options.setSamplesForGrid(2,problem); ASSERT_TRUE(options.samples()); EXPECT_EQ(8,options.samples().get()); options.setSamplesForGrid(5,problem); ASSERT_TRUE(options.samples()); EXPECT_EQ(125,options.samples().get()); DDACEAlgorithmOptions optionsClone = options.clone().cast<DDACEAlgorithmOptions>(); // all Attributes should be equivalent but have different UUIDs AttributeVector attributes = options.options(); AttributeVector attributeClones = optionsClone.options(); ASSERT_EQ(attributes.size(),attributeClones.size()); for (unsigned i = 0, n = attributes.size(); i < n; ++i) { EXPECT_TRUE(attributes[i] == attributeClones[i]); EXPECT_FALSE(attributes[i].uuid() == attributeClones[i].uuid()); EXPECT_FALSE(attributes[i].versionUUID() == attributeClones[i].versionUUID()); } options = DDACEAlgorithmOptions(DDACEAlgorithmType::lhs); options.setSeed(891678); options.setSamples(62); ASSERT_TRUE(options.seed()); EXPECT_EQ(891678,options.seed().get()); ASSERT_TRUE(options.samples()); EXPECT_EQ(62,options.samples().get()); EXPECT_FALSE(options.symbols()); options.setSeed(1); ASSERT_TRUE(options.seed()); EXPECT_EQ(1,options.seed().get()); options.clearSeed(); EXPECT_FALSE(options.seed()); options = DDACEAlgorithmOptions(DDACEAlgorithmType::oas); options.setSamplesAndSymbolsForOrthogonalArray(13,1); EXPECT_TRUE(options.seed()); // default is to generate a fixed seed ASSERT_TRUE(options.symbols()); EXPECT_EQ(13,options.symbols().get()); ASSERT_TRUE(options.samples()); EXPECT_EQ(169,options.samples().get()); optionsClone = options.clone().cast<DDACEAlgorithmOptions>(); // all Attributes should be equivalent but have different UUIDs attributes = options.options(); attributeClones = optionsClone.options(); ASSERT_EQ(attributes.size(),attributeClones.size()); for (unsigned i = 0, n = attributes.size(); i < n; ++i) { EXPECT_TRUE(attributes[i] == attributeClones[i]); EXPECT_FALSE(attributes[i].uuid() == attributeClones[i].uuid()); EXPECT_FALSE(attributes[i].versionUUID() == attributeClones[i].versionUUID()); } options.clearSymbols(); EXPECT_FALSE(options.symbols()); EXPECT_TRUE(options.samples()); options.clearSamples(); EXPECT_FALSE(options.samples()); int n = DDACEAlgorithmOptions::samplesForCentralComposite(problem); EXPECT_EQ(15,n); n = DDACEAlgorithmOptions::samplesForBoxBehnken(problem); EXPECT_EQ(13,n); }
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; }
OTSDPAttribute::OTSDPAttribute( sdp_data_t * attrib ) { setNil(); switch( attrib->dtd ) { case SDP_DATA_NIL: // Nil type { setNil(); break; } case SDP_UINT8: // Unsigned integer setUInt(attrib->val.uint8); break; case SDP_UINT16: // Unsigned integer setUInt(attrib->val.uint16); break; case SDP_UINT32: // Unsigned integer setUInt(attrib->val.uint32); break; case SDP_UINT64: // Unsigned integer setUInt(attrib->val.uint64); break; case SDP_UINT128: // Unsigned integer // setUInt(attrib->val.uint16); assert(false); // BUG/TODO: uint128 integers not supported break; case SDP_INT8: // Unsigned integer setInt(attrib->val.int8); break; case SDP_INT16: // Unsigned integer setInt(attrib->val.int16); break; case SDP_INT32: // Unsigned integer setInt(attrib->val.int32); break; case SDP_INT64: // Unsigned integer setInt(attrib->val.int64); break; case SDP_INT128: // Unsigned integer // newAttr.setInt(attrib->val.uint16); assert(false); // BUG/TODO: uint128 integers not supported break; case SDP_UUID16: { OTUUID id; ::uuid_t uuidVal = attrib->val.uuid; id.setUUID32(uuidVal.value.uuid16); setUUID(id ); } break; case SDP_UUID32: { OTUUID id; ::uuid_t uuidVal = attrib->val.uuid; id.setUUID32(uuidVal.value.uuid32); setUUID(id ); } break; case SDP_UUID128: { OTUUID id; ::uuid_t uuidVal = attrib->val.uuid; uint64_t* v128; v128 = reinterpret_cast<uint64_t*>(&(uuidVal.value.uuid128)); id.setUUID128(v128[0], v128[1]); setUUID(id ); } break; case SDP_TEXT_STR_UNSPEC : case SDP_TEXT_STR8 : case SDP_TEXT_STR16 : case SDP_TEXT_STR32 : setString( QString(attrib->val.str) ); break; case SDP_URL_STR_UNSPEC : case SDP_URL_STR8 : case SDP_URL_STR16 : case SDP_URL_STR32 : setURL( QString(attrib->val.str) ); break; case SDP_BOOL: setBool( attrib->val.int8 != 0); break; case SDP_SEQ_UNSPEC : case SDP_SEQ8 : case SDP_SEQ16 : case SDP_SEQ32 : case SDP_ALT_UNSPEC : case SDP_ALT8 : case SDP_ALT16 : case SDP_ALT32 : { AttributeVector subAttribs; OTSDPAttribute * Attr; sdp_data_t* subAttrib = attrib->val.dataseq; for (; subAttrib; subAttrib = subAttrib->next) { Attr = new OTSDPAttribute(subAttrib); subAttribs.resize( subAttribs.size() + 1 ); subAttribs.insert( subAttribs.size() - 1, Attr ); } if( attrib->dtd == SDP_ALT_UNSPEC || attrib->dtd == SDP_ALT8 || attrib->dtd == SDP_ALT16 || attrib->dtd == SDP_ALT32 ) { setAlternative(subAttribs); } else { setSequence(subAttribs); } break; } } // end case }
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 }
void XMLErrors::insertErrorMessageBlock() { // One or more errors occurred during parsing of the code. Display an error block to the user above // the normal content (the DOM tree is created manually and includes line/col info regarding // where the errors are located) // Create elements for display RefPtr<Element> documentElement = m_document->documentElement(); if (!documentElement) { RefPtr<Element> rootElement = m_document->createElement(htmlTag, true); RefPtr<Element> body = m_document->createElement(bodyTag, true); rootElement->parserAddChild(body); m_document->parserAddChild(rootElement); if (m_document->attached() && !rootElement->attached()) rootElement->attach(); documentElement = body.get(); } #if ENABLE(SVG) else if (documentElement->namespaceURI() == SVGNames::svgNamespaceURI) { RefPtr<Element> rootElement = m_document->createElement(htmlTag, true); RefPtr<Element> body = m_document->createElement(bodyTag, true); rootElement->parserAddChild(body); documentElement->parentNode()->parserRemoveChild(documentElement.get()); if (documentElement->attached()) documentElement->detach(); body->parserAddChild(documentElement); m_document->parserAddChild(rootElement.get()); if (m_document->attached()) // In general, rootElement shouldn't be attached right now, but it will be if there is a style element // in the SVG content. rootElement->reattach(); documentElement = body.get(); } #endif String errorMessages = m_errorMessages.toString(); RefPtr<Element> reportElement = createXHTMLParserErrorHeader(m_document, errorMessages); #if ENABLE(XSLT) if (m_document->transformSourceDocument()) { AttributeVector attributes; attributes.append(Attribute(styleAttr, "white-space: normal")); RefPtr<Element> paragraph = m_document->createElement(pTag, true); paragraph->parserSetAttributes(attributes, FragmentScriptingNotAllowed); paragraph->parserAddChild(m_document->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result.")); reportElement->parserAddChild(paragraph.release()); } #endif Node* firstChild = documentElement->firstChild(); if (firstChild) documentElement->parserInsertBefore(reportElement, documentElement->firstChild()); else documentElement->parserAddChild(reportElement); if (documentElement->attached() && !reportElement->attached()) reportElement->attach(); m_document->updateStyleIfNeeded(); }