Exemplo n.º 1
0
  boost::optional<ScheduleWeek> ScheduleYear_Impl::getScheduleWeek(const openstudio::Date& date) const
  {
    YearDescription yd = this->model().getUniqueModelObject<YearDescription>();

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

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

    if (N == 0){
      return boost::none;
    }

    boost::optional<ScheduleWeek> result;

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

      // want first date which is greater than or equal to the target date
      if(dates[i] >= date){
        result = scheduleWeeks[i];
        break;
      }
    }

    return result;
  }
 /** 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;
 }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
0
  bool ScheduleRule_Impl::containsDate(const openstudio::Date& date) {
    bool result = false;

    // need to check or adjust assumed base year on input date?

    boost::optional<std::string> dateSpecificationType = this->getString(OS_Schedule_RuleFields::DateSpecificationType, true);
    OS_ASSERT(dateSpecificationType);
    if (istringEqual("DateRange", *dateSpecificationType)){
      boost::optional<openstudio::Date> startDate = this->startDate();
      OS_ASSERT(startDate);
      boost::optional<openstudio::Date> endDate = this->endDate();
      OS_ASSERT(endDate);
      if (*startDate <= *endDate){
        result = ((date >= *startDate) && (date <= *endDate));
      }else{
        result = ((date >= *startDate) || (date <= *endDate));
      }
    }else{
      std::vector<openstudio::Date> specificDates = this->specificDates();
      for (const openstudio::Date& specificDate : specificDates){
        if (specificDate == date){
          result = true;
          break;
        }
      }
    }

    if (result){
      switch (date.dayOfWeek().value()){
        case DayOfWeek::Sunday:
          result = this->applySunday();
          break;
        case DayOfWeek::Monday:
          result = this->applyMonday();
          break;
        case DayOfWeek::Tuesday:
          result = this->applyTuesday();
          break;
        case DayOfWeek::Wednesday:
          result = this->applyWednesday();
          break;
        case DayOfWeek::Thursday:
          result = this->applyThursday();
          break;
        case DayOfWeek::Friday:
          result = this->applyFriday();
          break;
        case DayOfWeek::Saturday:
          result = this->applySaturday();
          break;
        default:
          OS_ASSERT(false);
      }
    }

    return result;
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
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;
  }