-
Notifications
You must be signed in to change notification settings - Fork 69
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
Adds the ability to register new functions for EpBunch objects #250
base: develop
Are you sure you want to change the base?
Adds the ability to register new functions for EpBunch objects #250
Conversation
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.
I use PyCharm as an IDE, therefore a lot of the changes are simply code cleanups.
very very nice. I like this. I have not looked into your code carefully yet - my mindspace is taken up another project at the moment. If this works and passes all tests (including ones that you may write), I'll be happy to merge it into the eppy. We should also develop user documentation for this. |
I'm glad you like it. Before merging anything, I suggest we continue on this pull request to improve the logic and to, like you said, create documentation. Finally, I don't see why we should not implement the decorator logic to the IDF class as well! This would allow users to add functionality without using subclasses. |
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.
Looks good to me in general. I've not thought much about how (if at all) it will affect other tools that build on eppy - but I'll have a good look at geomeppy when I get another chunk of time.
I actually prefer this approach to the patching I've used in geomeppy, so thanks for this contribution. Just want to be sure that we don't introduce anything that might break other's code without a very good reason.
Agree 100% |
@jamiebull1 , No objections to black. Also, You make a good point about not breaking other tools built on eppy. There may be internal tools that are not public, that we don't know about. |
Great! In the mean time, I don't know if you guys can help me with a small issue with the current logic: Since functions are registered before class instantiation and that the function name is added as an attribute (see this Line) of EpBunch, all functions are "available" on an instance of the class, even though not all of them will appear in Does that make sense to you guys? |
@samuelduchesne |
@jamiebull1 but what about possible surface types? eg.: "BuildingSurface:Detailed", "Surface:Wall", etc... |
From memory it's names in the IDD, so surface types. I'm away from a computer right now so can't check. |
@jamiebull1 I can confirm it is |
Let's keep a todo list (@jamiebull1 & @santoshphilip, feel free to add to this list) Todo
|
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.
Oups, looks like CIs are not happy with that one on some platforms. Ideas why?
ouch ! I merged the pull request #251 @samuelduchesne the line number for the error is visible on https://travis-ci.org/santoshphilip/eppy/jobs/563726632 If you look at https://travis-ci.org/santoshphilip/eppy/builds/563726631?utm_source=github_status&utm_medium=notification you will see that three of them failed and one passes. Click on the links to follow up and see why they are failing. If you are not able to figure it out, I'll take a look |
Ok, I'll have a look this week. |
The problem is a circular import. You're importing Two ways to fix it:
I prefer option 2, as it keeps all the imports at the top of the module. Late imports are almost always a code smell. |
Codecov Report
@@ Coverage Diff @@
## develop #250 +/- ##
==========================================
- Coverage 43.32% 43.1% -0.22%
==========================================
Files 89 90 +1
Lines 7568 7611 +43
==========================================
+ Hits 3279 3281 +2
- Misses 4289 4330 +41
Continue to review full report at Codecov.
|
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.
Looking good. Good test coverage. I've suggested a few minor changes, but mainly style things. There's also one issue with a test that I think is not testing what it should be (testing for area
vs new_area
). I may have misunderstood the intent though.
snames = [sname.upper() for sname in snames] | ||
func_dict = { | ||
"area": (area, snames), | ||
"height": (height, snames), # not working correctly |
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.
Are these comments from before the 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.
They are not mine
# then it is likely to be a surface. | ||
# of course we need to recode for surfaces that do not have coordinates :-( | ||
# or we can filter those out since they do not have | ||
# the field "Number_of_Vertices" |
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.
Filtering is fine, I think.
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.
This is for @santoshphilip I think. Not my code.
eppy/tests/test_function_helpers.py
Outdated
IDF.setiddname(iddfhandle) | ||
yield IDF | ||
|
||
@pytest.fixture() |
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.
I'd prefer these two fixtures to be in conftest.py
. In fact I think there may be equivalent ones there already.
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.
corrected in 3080f0d
…ing the original test_bunch_subclass idftxt
I think this is related to the fixture scope.
I don't understand why Travis is not happy. I think it's because the modeleditor.IDF's idd has already been set. I still don't understand why we can't change the IDD for another instance of modeleditor.IDF |
When I suggested reusing an existing fixture, I meant to use one to give you the base IDF. You can then just add the objects you need in your test. For example:
This gives you a zone with just a floor surface. You could add a wall and a ceiling to ensure they're filtered out, but that's more testing the As an aside, I'd suggest using |
Totally makes sense. Adjusted in f37e882 |
Looks good to me. Anything to add, @santoshphilip ? |
Currently working on these: Todo
|
@jamiebull1, |
First thing - Second, I get the same error as you for the IDF helper function registration -works when just running that module, but not if running the full test suite. Not sure what's breaking there, and don't have the time to look into it right now. It shouldn't be the fixture scope as that's |
Hi @santoshphilip,
Hi @jamiebull1,
Gentlemen, I have been working a lot with eppy lately and sometimes I needed to develop new functions for convenience. For instance, I needed to create a function to return the total conditioned area of the whole building.
My first reflex was to subclass the IDF class and to add a
conditioned_area()
as a property (with the@property
decorator). See here:This worked well for an IDF level property. But then, I also needed a similar function for zone EpBunch objects (EpBunch.key == 'ZONE') since I wanted to know the conditioned area of individual zones. Since I didn't want to subclass the EpBunch class as well, I figured I could implement a new type of function decorator instead. This is inspired by how Pandas asks developers to extend pandas functionalities.
My suggestion is this: users should decorate custom functions with the
register_epbunch_function
decorator. Here is an example:In this example, the function has also to
@property
decorator because I what the function to behave like a property (no need for the empty parentheses). Furthermore, in the first decorator, the keys attribute lets you specify which type of EP object should implement the function. For example, I only want myconditioned_area
method to work forZONE
objects.To implement the new functionality, I had to change a few things in the way EpBunch class instances are populated with the default methods. I will try to comment directly in this pull request to guide you guys through my logic.