/** Helper function to name it like `Heating Sch Week Rule - Jan1-Dec31` */
 bool setName(const std::string& scheduleYearName, const openstudio::Date& startDate, const openstudio::Date& endDate) {
   if (startDate > endDate) {
     return false;
   }
   std::stringstream ss;
   ss << scheduleYearName << " Week Rule - ";
   ss << startDate.monthOfYear().valueName() << startDate.dayOfMonth() << "-" << endDate.monthOfYear().valueName() << endDate.dayOfMonth();
   this->name = ss.str();
   return true;
 }
Ejemplo n.º 2
0
  bool ScheduleRule_Impl::setEndDate(const openstudio::Date& date) {
    bool result = setString(OS_Schedule_RuleFields::DateSpecificationType, "DateRange", false);
    OS_ASSERT(result);
    result = this->setInt(OS_Schedule_RuleFields::EndMonth, date.monthOfYear().value());
    OS_ASSERT(result);
    result = this->setInt(OS_Schedule_RuleFields::EndDay, date.dayOfMonth());
    OS_ASSERT(result);

    // set end date if need to
    if (this->isEmpty(OS_Schedule_RuleFields::StartMonth) || this->isEmpty(OS_Schedule_RuleFields::StartDay)){
      this->setStartDate(openstudio::Date(MonthOfYear::Jan, 1));
    }

    // clear specific dates
    this->clearExtensibleGroups();
    return true;
  }
Ejemplo n.º 3
0
  bool ScheduleRule_Impl::addSpecificDate(const openstudio::Date& date) {

    bool result = setString(OS_Schedule_RuleFields::DateSpecificationType, "SpecificDates", false);
    OS_ASSERT(result);

    result = setString(OS_Schedule_RuleFields::StartMonth, "", false);
    OS_ASSERT(result);
    result = setString(OS_Schedule_RuleFields::StartDay, "", false);
    OS_ASSERT(result);
    result = setString(OS_Schedule_RuleFields::EndMonth, "", false);
    OS_ASSERT(result);
    result = setString(OS_Schedule_RuleFields::EndDay, "", false);
    OS_ASSERT(result);

    std::vector<std::string> values;
    values.push_back(boost::lexical_cast<std::string>(date.monthOfYear().value()));
    values.push_back(boost::lexical_cast<std::string>(date.dayOfMonth()));

    ModelExtensibleGroup group = pushExtensibleGroup(values, true).cast<ModelExtensibleGroup>();
    OS_ASSERT(!group.empty());

    return true;
  }
Ejemplo n.º 4
0
  bool ScheduleYear_Impl::addScheduleWeek(const openstudio::Date& untilDate, const ScheduleWeek& scheduleWeek)
  {
    YearDescription yd = this->model().getUniqueModelObject<YearDescription>();

    if (yd.assumedYear() != untilDate.assumedBaseYear()){
      LOG(Error, "Assumed base year " << untilDate.assumedBaseYear() << " of untilDate does not match this model's assumed base year of " << yd.assumedYear());
      return false;
    }

    std::vector<ScheduleWeek> scheduleWeeks = this->scheduleWeeks(); // these are already sorted
    std::vector<openstudio::Date> dates = this->dates(); // these are already sorted
    bool inserted = false;
    
    unsigned N = dates.size();
    OS_ASSERT(scheduleWeeks.size() == N);

    this->clearExtensibleGroups();

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

      if (dates[i] == untilDate){

        bool doEmit = (i == (N-1));

        // push back just this schedule/date pair
        std::vector<std::string> groupValues;
        groupValues.push_back(boost::lexical_cast<std::string>(untilDate.monthOfYear().value()));
        groupValues.push_back(boost::lexical_cast<std::string>(untilDate.dayOfMonth()));
        groupValues.push_back(scheduleWeek.name().get());

        ModelExtensibleGroup group = pushExtensibleGroup(groupValues, doEmit).cast<ModelExtensibleGroup>();
        OS_ASSERT(!group.empty());

        inserted = true;

      }else{
        
        // if we need to insert new schedule/date pair here
        if ((untilDate < dates[i]) && !inserted){

          // push back this schedule/date pair
          std::vector<std::string> groupValues;
          groupValues.push_back(boost::lexical_cast<std::string>(untilDate.monthOfYear().value()));
          groupValues.push_back(boost::lexical_cast<std::string>(untilDate.dayOfMonth()));
          groupValues.push_back(scheduleWeek.name().get());

          ModelExtensibleGroup group = pushExtensibleGroup(groupValues, false).cast<ModelExtensibleGroup>();
          OS_ASSERT(!group.empty());

          inserted = true;
        }

        bool doEmit = (i == (N-1)) && inserted;

        // insert existing schedule/date pair
        std::vector<std::string> groupValues;
        groupValues.push_back(boost::lexical_cast<std::string>(dates[i].monthOfYear().value()));
        groupValues.push_back(boost::lexical_cast<std::string>(dates[i].dayOfMonth()));
        groupValues.push_back(scheduleWeeks[i].name().get());

        ModelExtensibleGroup group = pushExtensibleGroup(groupValues, doEmit).cast<ModelExtensibleGroup>();
        OS_ASSERT(!group.empty());
      }
    }

    if (!inserted){
      // push back this schedule/date pair
      std::vector<std::string> groupValues;
      groupValues.push_back(boost::lexical_cast<std::string>(untilDate.monthOfYear().value()));
      groupValues.push_back(boost::lexical_cast<std::string>(untilDate.dayOfMonth()));
      groupValues.push_back(scheduleWeek.name().get());

      ModelExtensibleGroup group = pushExtensibleGroup(groupValues, true).cast<ModelExtensibleGroup>();
      OS_ASSERT(!group.empty());
    }

    return true;
  }