openstudio::Date RunPeriodControlSpecialDays_Impl::getDate(const std::string& text) const { Date result; YearDescription yd = this->model().getUniqueModelObject<YearDescription>(); /* \note <number>/<number> (month/day) \note <number> <Month> \note <Month> <number> \note <Nth> <Weekday> in <Month) \note Last <WeekDay> in <Month> \note <Month> can be January, February, March, April, May, June, July, August, September, October, November, December \note Months can be the first 3 letters of the month \note <Weekday> can be Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday \note <Nth> can be 1 or 1st, 2 or 2nd, etc. up to 5(?) */ boost::smatch matches; if (boost::regex_search(text, matches, boost::regex("(\\d+)\\s?\\/\\s?(\\d+)"))){ std::string monthString(matches[1].first, matches[1].second); MonthOfYear monthOfYear(boost::lexical_cast<unsigned>(monthString)); std::string dayOfMonthString(matches[2].first, matches[2].second); unsigned dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString); result = yd.makeDate(monthOfYear, dayOfMonth); return result; }else if (boost::regex_search(text, matches, boost::regex("(\\d+)\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|July|August|September|October|November|December)", boost::regex::icase))){ std::string dayOfMonthString(matches[1].first, matches[1].second); unsigned dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString); std::string monthString(matches[2].first, matches[2].second); result = yd.makeDate(monthOfYear(monthString), dayOfMonth); return result; }else if (boost::regex_search(text, matches, boost::regex("(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|July|August|September|October|November|December)\\s+(\\d+)", boost::regex::icase))){ std::string monthString(matches[1].first, matches[1].second); std::string dayOfMonthString(matches[2].first, matches[2].second); unsigned dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString); result = yd.makeDate(monthOfYear(monthString), dayOfMonth); return result; }else if (boost::regex_search(text, matches, boost::regex("(1|2|3|4|5|1st|2nd|3rd|4th|5th|Last)\\s+(Sun|Mon|Tue|Wed|Thu|Fri|Sat|Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\\s+in\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|July|August|September|October|November|December)", boost::regex::icase))){ std::string nthString(matches[1].first, matches[1].second); std::string dayOfWeekString(matches[2].first, matches[2].second); std::string monthString(matches[3].first, matches[3].second); result = yd.makeDate(nthDayOfWeekInMonth(nthString), dayOfWeek(dayOfWeekString), monthOfYear(monthString)); return result; } LOG_AND_THROW("Could not determine date for startDate = '" << text << "'"); return Date(); }
boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateHoliday(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model) { //<Name>Thanksgiving Day</Name> //<SpecMthd>Fourth</SpecMthd> //<DayOfWeek>Thursday</DayOfWeek> //<Month>November</Month> //<Name>Christmas Day</Name> //<SpecMthd>Date</SpecMthd> //<Month>December</Month> //<Day>25</Day> boost::optional<openstudio::model::ModelObject> result; QDomElement nameElement = element.firstChildElement("Name"); QDomElement specificationMethodElement = element.firstChildElement("SpecMthd"); OS_ASSERT(!nameElement.isNull()); OS_ASSERT(!specificationMethodElement.isNull()); if (specificationMethodElement.text() == "Date"){ QDomElement monthElement = element.firstChildElement("Month"); QDomElement dayElement = element.firstChildElement("Day"); OS_ASSERT(!monthElement.isNull()); OS_ASSERT(!dayElement.isNull()); MonthOfYear monthOfYear(toString(monthElement.text())); unsigned day = dayElement.text().toUInt(); result = model::RunPeriodControlSpecialDays(monthOfYear, day, model); result->setName(escapeName(nameElement.text())); }else{ QDomElement dayOfWeekElement = element.firstChildElement("DayOfWeek"); QDomElement monthElement = element.firstChildElement("Month"); OS_ASSERT(!dayOfWeekElement.isNull()); OS_ASSERT(!monthElement.isNull()); // fifth is treated equivalently to last std::string specificationMethod = toString(specificationMethodElement.text()); if (specificationMethod == "Last"){ specificationMethod = "Fifth"; } NthDayOfWeekInMonth nth(specificationMethod); DayOfWeek dayOfWeek(toString(dayOfWeekElement.text())); MonthOfYear monthOfYear(toString(monthElement.text())); result = model::RunPeriodControlSpecialDays(nth, dayOfWeek, monthOfYear, model); result->setName(escapeName(nameElement.text())); } return result; }
boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateSchedule(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model) { QDomElement nameElement = element.firstChildElement("Name"); QDomElement typeElement = element.firstChildElement("Type"); OS_ASSERT(!nameElement.isNull()); std::string name = escapeName(nameElement.text()); model::ScheduleYear scheduleYear(model); scheduleYear.setName(name); OS_ASSERT(!typeElement.isNull()); std::string type = escapeName(typeElement.text()); boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getModelObjectByName<model::ScheduleTypeLimits>(type); if (scheduleTypeLimits){ scheduleYear.setScheduleTypeLimits(*scheduleTypeLimits); } QDomNodeList endMonthElements = element.elementsByTagName("EndMonth"); QDomNodeList endDayElements = element.elementsByTagName("EndDay"); QDomNodeList schWeekRefElements = element.elementsByTagName("SchWeekRef"); OS_ASSERT(endMonthElements.count() == endDayElements.count()); OS_ASSERT(endMonthElements.count() == schWeekRefElements.count()); for (int i = 0; i < endMonthElements.count(); i++){ QDomElement endMonthElement = endMonthElements.at(i).toElement(); QDomElement endDayElement = endDayElements.at(i).toElement(); QDomElement schWeekRefElement = schWeekRefElements.at(i).toElement(); boost::optional<model::ScheduleWeek> scheduleWeek = model.getModelObjectByName<model::ScheduleWeek>(escapeName(schWeekRefElement.text())); if (scheduleWeek){ boost::optional<model::YearDescription> yearDescription = model.getOptionalUniqueModelObject<model::YearDescription>(); if (yearDescription){ MonthOfYear monthOfYear(endMonthElement.text().toUInt()); unsigned dayOfMonth = endDayElement.text().toUInt(); Date untilDate(monthOfYear, dayOfMonth, yearDescription->assumedYear()); scheduleYear.addScheduleWeek(untilDate, *scheduleWeek); }else{ MonthOfYear monthOfYear(endMonthElement.text().toUInt()); unsigned dayOfMonth = endDayElement.text().toUInt(); Date untilDate(monthOfYear, dayOfMonth); scheduleYear.addScheduleWeek(untilDate, *scheduleWeek); } } } return scheduleYear; }
void SchedulesTabController::setDstEndDate(const QDate & newdate) { model::RunPeriodControlDaylightSavingTime dst = m_model.getUniqueModelObject<model::RunPeriodControlDaylightSavingTime>(); dst.setEndDate(monthOfYear(newdate.month()),newdate.day()); }
bool SimFile::computeDateTimes(QVector<QString> day, QVector<QString> time) { bool ok; QStringList split; int n = qMin(day.size(),time.size()); for(int i=0;i<n;i++) { split = day[i].split('/'); if(split.size() != 2) { return false; } unsigned month=split[0].toInt(&ok); if(!ok || month > 12) { return false; } unsigned dayOfMonth=split[1].toInt(&ok); if(!ok) { return false; } m_dateTimes.push_back(DateTime(Date(monthOfYear(month),dayOfMonth),Time(time[i].toStdString()))); } return true; }
CODATIME_BEGIN int64_t BaseChronology::getDateTimeMillis(int yearNum, int monthOfYearNum, int dayOfMonthNum, int millisOfDayNum) { int64_t instant = year()->set(0, yearNum); instant = monthOfYear()->set(instant, monthOfYearNum); instant = dayOfMonth()->set(instant, dayOfMonthNum); return millisOfDay()->set(instant, millisOfDayNum); }
int64_t BaseChronology::getDateTimeMillis(int yearNum, int monthOfYearNum, int dayOfMonthNum, int hourOfDayNum, int minuteOfHourNum, int secondOfMinuteNum, int millisOfSecondNum) { int64_t instant = year()->set(0, yearNum); instant = monthOfYear()->set(instant, monthOfYearNum); instant = dayOfMonth()->set(instant, dayOfMonthNum); instant = hourOfDay()->set(instant, hourOfDayNum); instant = minuteOfHour()->set(instant, minuteOfHourNum); instant = secondOfMinute()->set(instant, secondOfMinuteNum); return millisOfSecond()->set(instant, millisOfSecondNum); }
void YearSettingsWidget::onDstEndDayWeekMonthChanged() { std::string s_dayOfWeek; std::string s_monthOfYear; int i_nthDayOfWeekInMonth = m_endWeekBox->currentIndex(); s_dayOfWeek = m_endDayBox->currentText().toStdString(); s_monthOfYear = m_endMonthBox->currentText().toStdString(); NthDayOfWeekInMonth _nth(i_nthDayOfWeekInMonth + 1); DayOfWeek _dayOfWeek = dayOfWeek(s_dayOfWeek); MonthOfYear _monthOfYear = monthOfYear(s_monthOfYear); emit dstEndDayOfWeekAndMonthChanged(_nth.value(), _dayOfWeek.value(), _monthOfYear.value()); }
QDate time2qdate(time_t t) { return QDate(year(t), monthOfYear(t), dayOfMonth(t)); }
boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateSchedule(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model) { QDomElement nameElement = element.firstChildElement("Name"); QDomElement typeElement = element.firstChildElement("Type"); std::string name; if (nameElement.isNull()){ LOG(Error, "Sch element 'Name' is empty.") } else{ name = escapeName(nameElement.text()); } if (typeElement.isNull()){ LOG(Error, "Sch element 'Type' is empty for Sch named '" << name << "'. ScheduleYear will not be created"); return boost::none; } std::string type = escapeName(typeElement.text()); QDomNodeList endMonthElements = element.elementsByTagName("EndMonth"); QDomNodeList endDayElements = element.elementsByTagName("EndDay"); QDomNodeList schWeekRefElements = element.elementsByTagName("SchWeekRef"); if (endMonthElements.count() != endDayElements.count()){ LOG(Error, "Number of 'EndMonth' elements not equal to number of 'EndDay' elements for Sch named '" << name << "'. ScheduleYear will not be created"); return boost::none; } if (endMonthElements.count() != schWeekRefElements.count()){ LOG(Error, "Number of 'EndMonth' elements not equal to number of 'SchWeekRef' elements for Sch named '" << name << "'. ScheduleYear will not be created"); return boost::none; } model::ScheduleYear scheduleYear(model); scheduleYear.setName(name); boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getModelObjectByName<model::ScheduleTypeLimits>(type); if (scheduleTypeLimits){ scheduleYear.setScheduleTypeLimits(*scheduleTypeLimits); } for (int i = 0; i < endMonthElements.count(); i++){ QDomElement endMonthElement = endMonthElements.at(i).toElement(); QDomElement endDayElement = endDayElements.at(i).toElement(); QDomElement schWeekRefElement = schWeekRefElements.at(i).toElement(); boost::optional<model::ScheduleWeek> scheduleWeek = model.getModelObjectByName<model::ScheduleWeek>(escapeName(schWeekRefElement.text())); if (scheduleWeek){ boost::optional<model::YearDescription> yearDescription = model.getOptionalUniqueModelObject<model::YearDescription>(); if (yearDescription){ MonthOfYear monthOfYear(endMonthElement.text().toUInt()); unsigned dayOfMonth = endDayElement.text().toUInt(); Date untilDate(monthOfYear, dayOfMonth, yearDescription->assumedYear()); scheduleYear.addScheduleWeek(untilDate, *scheduleWeek); }else{ MonthOfYear monthOfYear(endMonthElement.text().toUInt()); unsigned dayOfMonth = endDayElement.text().toUInt(); Date untilDate(monthOfYear, dayOfMonth); scheduleYear.addScheduleWeek(untilDate, *scheduleWeek); } } } return scheduleYear; }
void AnnualIlluminanceMap::init(const openstudio::path& path) { // file must exist if (!exists( path )){ LOG(Fatal, "File does not exist: '" << toString(path) << "'" ); return; } // open file boost::filesystem::ifstream file(path); // keep track of line number unsigned lineNum = 0; // keep track of matrix size unsigned M=0; unsigned N=0; // temp string to read file string line; // lines 1 and 2 are the header lines string line1, line2; // this will contain matches to regular expressions smatch matches; // matches a single number followed by either tabs or spaces const regex singleNumber("([-+]?[0-9]*\\.?[0-9]+)[\\s\\t]*"); // conversion from footcandles to lux const double footcandlesToLux(10.76); // read the rest of the file line by line while(getline(file, line)){ ++lineNum; if (lineNum == 1){ // save line 1 line1 = line; }else if (lineNum == 2){ // save line 2 line2 = line; // create the header info HeaderInfo headerInfo(line1, line2); // we can now initialize x and y vectors m_xVector = headerInfo.xVector(); m_yVector = headerInfo.yVector(); M = m_xVector.size(); N = m_yVector.size(); }else{ // each line contains the month, day, time (in hours), // Solar Azimuth(degrees from south), Solar Altitude(degrees), Global Horizontal Illuminance (fc) // followed by M*N illuminance points // break the line up by spaces vector<string> lineVector; tokenizer<char_separator<char>, std::string::const_iterator, std::string > tk(line, char_separator<char>(" ")); for (tokenizer<char_separator<char>, std::string::const_iterator, std::string >::iterator it(tk.begin()); it!=tk.end(); ++it) { lineVector.push_back(*it); } // total number minus 6 standard header items unsigned numValues = lineVector.size() - 6; if (numValues != M*N){ LOG(Fatal, "Incorrect number of illuminance values read " << numValues << ", expecting " << M*N << "."); return; }else{ MonthOfYear month = monthOfYear(lexical_cast<unsigned>(lineVector[0])); unsigned day = lexical_cast<unsigned>(lineVector[1]); double fracDays = lexical_cast<double>(lineVector[2]) / 24.0; // ignore solar angles and global horizontal for now // make the date time DateTime dateTime(Date(month, day), Time(fracDays)); // matrix we are going to read in Matrix illuminanceMap(M,N); // read in the values unsigned index = 6; for (unsigned j = 0; j < N; ++j){ for (unsigned i = 0; i < M; ++i){ illuminanceMap(i,j) = footcandlesToLux*lexical_cast<double>(lineVector[index]); ++index; } } m_dateTimes.push_back(dateTime); m_dateTimeIlluminanceMap[dateTime] = illuminanceMap; } } } // close file file.close(); }