Skip to content

Add presentvalue from old resscript#1

Merged
berland merged 5 commits intomasterfrom
presentvalue
Sep 30, 2019
Merged

Add presentvalue from old resscript#1
berland merged 5 commits intomasterfrom
presentvalue

Conversation

@berland
Copy link
Collaborator

@berland berland commented Aug 27, 2019

Minimal amount of work to get it py3-compatible;

  • tabs-to-spaces
  • 2to3 -w presentvalue.py
  • black presentvalue.py
  • Encapsulate code in def main()
  • Add test-code that only tries to launch the script, nothing more
  • Added test-data

@berland
Copy link
Collaborator Author

berland commented Aug 27, 2019

There is a 64MB dump of test-data that is a duplicate of the test-data-set used for ecl2df.

For presentvalue.py, probably only the UNSMRY file is strictly needed.

@pgdr
Copy link

pgdr commented Aug 27, 2019

Cool! I know it's just a WIP, but would you mind removing the shebang?

@berland
Copy link
Collaborator Author

berland commented Aug 27, 2019

Open to suggestions on how to solve the relative path issue for test data.

Is it feasible to capture stdout when testing?

"presentvalue",
"--discountto",
"2001",
"tests/data/reek/eclipse/model/2_R001_REEK-0.DATA",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about os.path.join(__file__, "data", .....). We can even add a utils inside the test-module that fetches test data tests.utils.get_test_data("reek", "eclipse", "model", "2_R001_REEK-0.DATA").

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it feasible to capture stdout when testing?

Yes, but how about writing a test of the main function first?

@berland
Copy link
Collaborator Author

berland commented Aug 28, 2019

I think I want to leave this as is, for my first conversion. But docs should probably be added, here the simple solution is to add a short descriptive string to the wiki, where it is already documented. https://wiki.equinor.com/wiki/index.php/ResScript:Python:Scripts:presentvalue

Or/and employ sphinx-argparse?

@markusdregi
Copy link
Contributor

Or/and employ sphinx-argparse?

That sounds like a good idea!

@markusdregi
Copy link
Contributor

Are we sure this functionality is not covered by the NPV job in spinningjenny? Because if so, there is no reason to port this one I guess...

import pandas
import sys

# import resscript.header as header
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to make a replacement for this + logging.

@@ -0,0 +1,508 @@
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably remove this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The documentation at the top with out names etc, as well as the link to the script documentation: that should be some new Sphinx site)

parser.add_argument("--quiet", "-q", action="store_true", help="Be quiet")
args = parser.parse_args()

# if not args.quiet:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold until we have a new header solution.

@berland
Copy link
Collaborator Author

berland commented Aug 29, 2019

Are we sure this functionality is not covered by the NPV job in spinningjenny? Because if so, there is no reason to port this one I guess...

This script has break-even-calculations also, which I could not find by scrolling the spinningjenny source. But it is already ported, so not much more we need to do.

@markusdregi
Copy link
Contributor

This script has break-even-calculations also, which I could not find by scrolling the spinningjenny source. But it is already ported, so not much more we need to do.

You are right, that is not in the current implementation as it was not necessary from an Everest perspective (in the forward models at least).

@berland
Copy link
Collaborator Author

berland commented Sep 2, 2019

I think we should merge this for now, and continue to other scripts. Review requested :)

@berland berland mentioned this pull request Sep 2, 2019
@markusdregi
Copy link
Contributor

My recommendation is that the minimum effort put into this PR before it being merged is that you rewrite the main function so that it either return values as requested or throws an exception. In addition you can use the logging capabilities in Python to log warnings to the user (https://docs.python.org/3/library/logging.html). After this is done each return statement, each exception and each logging statement should be triggered by at least one test and the value should be checked explicitly. There is no other way to remotely ensure similar behavior in Python 2 and 3.

However, I'm not the maintainer of this code, so do as you like with my recommendations...

@markusdregi markusdregi mentioned this pull request Sep 13, 2019
@berland
Copy link
Collaborator Author

berland commented Sep 20, 2019

Thanks, those are good suggestions for improval, but I prefer to put them in a separate issue for later triaging.

I added a numerical test that will ensure that it at least computes correctly on a sample test. Test code clearly illustrates some refactoring need.

@markusdregi
Copy link
Contributor

Thanks, those are good suggestions for improval, but I prefer to put them in a separate issue for later triaging.

Then you can merge it if you like. I would encourage you to make an issue regarding the improvements ;)

@berland
Copy link
Collaborator Author

berland commented Sep 24, 2019

"Merging can be performed automatically with 1 approving review." ;)

@pgdr
Copy link

pgdr commented Sep 25, 2019

I would prefer the commits being remade; first commit for the testdata, second commit for the code, third commit for fixing the code according to black, flake, etc, fourth commit for the testing or something like that.

We don't need the commits that are Fix Traxis (sic), Iterate on libecl, Fix most/Fix all... It sets a bad precedent for the first commits of the tree.

It should be

  1. Add test data
  2. Add original script
  3. Fix original script
  4. Refactor code
  5. Add testing, and other aux files

@pgdr
Copy link

pgdr commented Sep 25, 2019

Why are there raw except Exception rather than catching what could potentially be thrown?

@berland
Copy link
Collaborator Author

berland commented Sep 25, 2019

(I don't have the knowledge to reorder/selectively squash the commits in an effective manner)

@berland
Copy link
Collaborator Author

berland commented Sep 26, 2019

Why are there raw except Exception rather than catching what could potentially be thrown?

(fixed)

* 2to3
* Blacken
* Encapsulate code in def main()
* Precise exceptions
@berland berland merged commit 635581f into master Sep 30, 2019
@berland berland deleted the presentvalue branch October 21, 2019 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants