TEST_F(EnergyPlusFixture,ReverseTranslator_ScheduleDayInterval) { // ScheduleDayInterval time entries contain the string 'Until: ' that must be // stripped off before constructing a Time object. We are also more lenient in // making this optional. Workspace ws(StrictnessLevel::Draft,IddFileType(IddFileType::EnergyPlus)); OptionalWorkspaceObject owo = ws.addObject(IdfObject(IddObjectType::Schedule_Day_Interval)); ASSERT_TRUE(owo); WorkspaceObject object = *owo; object.setName("Heating Setpoint Design Day"); StringVector groupValues(2u); groupValues[0] = std::string("Until: 12:00"); groupValues[1] = std::string("21.1"); object.pushExtensibleGroup(groupValues); groupValues[0] = std::string("24:00"); groupValues[1] = std::string("20.5"); object.pushExtensibleGroup(groupValues); ReverseTranslator translator; Model model = translator.translateWorkspace(ws); EXPECT_TRUE(translator.errors().empty()); // There are warnings related to ws being a partial model. EXPECT_TRUE(translator.untranslatedIdfObjects().empty()); ScheduleDayVector daySchedules = model.getModelObjects<ScheduleDay>(); ASSERT_EQ(1u,daySchedules.size()); ScheduleDay daySchedule = daySchedules[0]; DoubleVector values = daySchedule.values(); ASSERT_EQ(2u,values.size()); EXPECT_DOUBLE_EQ(21.1,values[0]); EXPECT_DOUBLE_EQ(20.5,values[1]); TimeVector times = daySchedule.times(); ASSERT_EQ(2u,times.size()); EXPECT_EQ(Time(0,12,0),times[0]); EXPECT_EQ(Time(0,24,0),times[1]); }
boost::optional<IdfObject> ForwardTranslator::translateScheduleDay( ScheduleDay & modelObject ) { IdfObject scheduleDay = createRegisterAndNameIdfObject(openstudio::IddObjectType::Schedule_Day_Interval, modelObject); boost::optional<ScheduleTypeLimits> scheduleTypeLimits = modelObject.scheduleTypeLimits(); if (scheduleTypeLimits){ boost::optional<IdfObject> idfScheduleTypeLimits = translateAndMapModelObject(*scheduleTypeLimits); if (idfScheduleTypeLimits){ scheduleDay.setString(Schedule_Day_IntervalFields::ScheduleTypeLimitsName, idfScheduleTypeLimits->name().get()); } } if (modelObject.interpolatetoTimestep()){ scheduleDay.setString(Schedule_Day_IntervalFields::InterpolatetoTimestep, "Yes"); }else{ scheduleDay.setString(Schedule_Day_IntervalFields::InterpolatetoTimestep, "No"); } std::vector<double> values = modelObject.values(); std::vector<openstudio::Time> times = modelObject.times(); unsigned N = values.size(); OS_ASSERT(N == times.size()); scheduleDay.clearExtensibleGroups(); for (unsigned i = 0; i < N; ++i){ IdfExtensibleGroup group = scheduleDay.pushExtensibleGroup(); std::string hourPrefix; std::string minutePrefix; int hours = times[i].hours() + 24*times[i].days(); if (hours < 10){ hourPrefix = "0"; } int minutes = times[i].minutes() + floor((times[i].seconds()/60.0) + 0.5); if (minutes < 10){ minutePrefix = "0"; } std::stringstream ss; ss << hourPrefix << hours << ":" << minutePrefix << minutes; group.setString(Schedule_Day_IntervalExtensibleFields::Time, ss.str()); group.setDouble(Schedule_Day_IntervalExtensibleFields::ValueUntilTime, values[i]); } return scheduleDay; }