Get data associated with this output variable and this object. */
| 136 | |
| 137 | /** Get data associated with this output variable and this object. */ |
| 138 | openstudio::OptionalTimeSeries ModelObject_Impl::getData(const OutputVariable& variable, const std::string& envPeriod) const { |
| 139 | openstudio::OptionalTimeSeries result; |
| 140 | OptionalSqlFile sqlFile = this->model().sqlFile(); |
| 141 | |
| 142 | if (sqlFile) { |
| 143 | OptionalString variableName = variable.getString(OS_Output_VariableFields::VariableName); |
| 144 | OptionalString keyValue = variable.getString(OS_Output_VariableFields::KeyValue); |
| 145 | OptionalString reportingFrequency = variable.getString(OS_Output_VariableFields::ReportingFrequency, true); |
| 146 | |
| 147 | // solve any issues if key value is '*' |
| 148 | keyValue = getSpecificKeyValue(keyValue); |
| 149 | |
| 150 | if (variableName && keyValue) { |
| 151 | if (!reportingFrequency) { |
| 152 | // default to hourly frequency |
| 153 | LOG(Warn, "Variable does not specify reporting frequency, defaulting to hourly."); |
| 154 | reportingFrequency = ReportingFrequency(ReportingFrequency::Hourly).valueName(); |
| 155 | } |
| 156 | // use query interface because replaces requested strings with exact strings in database |
| 157 | ReportingFrequency rf(ReportingFrequency::Hourly); |
| 158 | try { |
| 159 | ReportingFrequency rf(boost::trim_copy(*reportingFrequency)); |
| 160 | } catch (...) { |
| 161 | LOG(Warn, "Unrecognized reporting frequency string. Defaulting to hourly."); |
| 162 | } |
| 163 | SqlFileTimeSeriesQuery q(envPeriod, rf, *variableName, *keyValue); |
| 164 | TimeSeriesVector tsVec = sqlFile->timeSeries(q); |
| 165 | if (tsVec.size() == 1) { |
| 166 | result = tsVec[0]; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | // set name from optional string |
| 175 | bool ModelObject_Impl::mf_setName(const boost::optional<std::string>& name) { |