-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle incomplete EPW design conditions header #5134
base: develop
Are you sure you want to change the base?
Conversation
be61615
to
82ac99f
Compare
Rebased onto develop and resolved conflicts. |
… optional into optional for getters
CI Results for 2e7710e:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a couple of minor changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector<EpwDesignCondition> designs = epwFile.designConditions(); | ||
EXPECT_EQ(1, designs.size()); | ||
EXPECT_EQ("Climate Design Data 2013 ASHRAE Handbook", designs[0].titleOfDesignCondition()); | ||
ASSERT_FALSE(designs[0].heatingColdestMonth()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: ASSERT_TRUE on an optional before dereferencing it makes sense. Here you could just do EXPECT_FALSE.
@@ -492,6 +494,109 @@ TEST(Filetypes, EpwFile_NoDesign) { | |||
} | |||
} | |||
|
|||
TEST(Filetypes, EpwFile_IncompleteDesign) { | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use a try...? (I know, the other tests have it... but makes no sense)
src/utilities/filetypes/EpwFile.cpp
Outdated
boost::optional<int> EpwDesignCondition::heatingColdestMonth() const { | ||
return boost::optional<int>(m_heatingColdestMonth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why wrapping it? heatingColdestMonth is already a boost::optional, so just return that.
bool ok; | ||
double value = stringToDouble(heatingDryBulb99, &ok); | ||
setHeatingDryBulb99(value); | ||
if (!ok) { | ||
m_heatingDryBulb99 = boost::none; | ||
} else { | ||
setHeatingDryBulb99(value); | ||
} | ||
return ok; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in the scope of this PR, but I dislike this. stringToDouble
should be boost::optional<double> stringToDouble(const std::string& str)
.
Also a lot of fields in EpwDataPoint
internally store a std::string
representation of a number, use magic string numbers for unknown values (constants would be better, whether that's a string or an actual number), which I also don't like.
OpenStudio/src/utilities/filetypes/EpwFile.cpp
Lines 1718 to 1744 in cae9435
boost::optional<double> EpwDataPoint::dryBulbTemperature() const { | |
if (m_dryBulbTemperature == "99.9") { | |
return boost::none; | |
} | |
return boost::optional<double>(std::stod(m_dryBulbTemperature)); | |
} | |
bool EpwDataPoint::setDryBulbTemperature(double value) { | |
if (-70 >= value || 70 <= value) { | |
LOG_FREE(Warn, "openstudio.EpwFile", "DryBulbTemperature value '" << value << "' not within the expected limits"); | |
} | |
m_dryBulbTemperature = std::to_string(value); | |
return true; | |
} | |
bool EpwDataPoint::setDryBulbTemperature(const std::string& dryBulbTemperature) { | |
bool ok; | |
double value = stringToDouble(dryBulbTemperature, &ok); | |
if (!ok) { | |
m_dryBulbTemperature = "99.9"; | |
return false; | |
} else if (-70 >= value || 70 <= value) { | |
LOG_FREE(Warn, "openstudio.EpwFile", "DryBulbTemperature value '" << value << "' not within the expected limits"); | |
} | |
m_dryBulbTemperature = dryBulbTemperature; | |
return true; | |
} |
But this isn't something we need to address now.
I didn't find occurrences of this being used anywhere in the common openstudio-gems I have on my machine right now. The only one I can find is ResStock's weather.rb, but I'm sure @joseph-robertson is well aware he'll need to change that so I'm fine with the API Break. @kbenne, grand protector of the API, could you chime in for confirmation? |
Pull request overview
EpwDesignCondition
has many API-breaking changes related to its getters. The previous behavior was to misleadingly return a value of 0 for any empty design condition header field. The types for the getters are now eitherboost::optional<double>
orboost::optional<int>
.Notes:
stringToDouble
return 0.0 if an empty string is passed in? Yes.heatingDryBulb99
is empty string insetHeatingDryBulb99
? Yes.boost::optional<double>
; e..g,double EpwDesignCondition::heatingDryBulb99() const {
toboost::optional<double> EpwDesignCondition::heatingDryBulb99() const {
? Yes.double m_heatingDryBulb99
toboost::optional<double> m_heatingDryBulb99
in EpwDesignCondition class? Yes.Pull Request Author
src/model/test
)src/energyplus/Test
)src/osversion/VersionTranslator.cpp
)Labels:
IDDChange
APIChange
Pull Request - Ready for CI
so that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.