-
-
Notifications
You must be signed in to change notification settings - Fork 230
ENH: Add JSON export and CSV export support for monte carlo result #916
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
base: develop
Are you sure you want to change the base?
Changes from all commits
2168a34
2589fca
894cc83
841c58e
9ce41fe
a228d59
9216cea
a7fa7d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you dont need to create the tests/integration/simulation/test_monte_carlo_export_csv_create_valid_file.py and tests/integration/simulation/test_monte_carlo_export_json_creates_valid_file.py files, there are only 2 est functions, which could be easily placed at the tests/unit/simulation/flight.py file (or similar) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import os | ||
| import csv | ||
|
|
||
|
|
||
| def test_csv_export(monte_carlo_calisto): | ||
| mc = monte_carlo_calisto | ||
| mc.simulate(3) | ||
|
|
||
| filename = "temp_mc_export.csv" | ||
| """ | ||
| tests that results of monte carlo are exported to a CSV file | ||
| """ | ||
| mc.export_csv(filename) | ||
|
|
||
| assert os.path.exists(filename) | ||
|
|
||
| with open(filename, newline="") as f: | ||
| reader = list(csv.reader(f)) | ||
|
|
||
| # Header exists | ||
| assert len(reader[0]) > 0 | ||
|
|
||
| # Should have 3 rows of data after header | ||
| assert len(reader) == 4 | ||
|
|
||
| os.remove(filename) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_json_export(monte_carlo_calisto): | ||||||||||||||||||||||||||||||||||||||
| mc = monte_carlo_calisto | ||||||||||||||||||||||||||||||||||||||
| mc.simulate(3) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| filename = "temp_test_output.json" | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| tests weather the results of monte carlo are exported to a JSON file. | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| mc.export_json(filename) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+13
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert os.path.exists(filename) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||
| mc.export_json(filename) | ||||||||||||||||||||||||||||||||||||||
| assert os.path.exists(filename) | ||||||||||||||||||||||||||||||||||||||
| with open(filename, "r") as f: | ||||||||||||||||||||||||||||||||||||||
| data = json.load(f) | ||||||||||||||||||||||||||||||||||||||
| # Assert dictionary keys exist | ||||||||||||||||||||||||||||||||||||||
| assert len(data.keys()) > 0 | ||||||||||||||||||||||||||||||||||||||
| # Check that at least one key corresponds to a list of simulation results | ||||||||||||||||||||||||||||||||||||||
| list_keys = [k for k, v in data.items() if isinstance(v, list)] | ||||||||||||||||||||||||||||||||||||||
| # There must be at least 1 Monte Carlo-dependent field | ||||||||||||||||||||||||||||||||||||||
| assert len(list_keys) > 0 | ||||||||||||||||||||||||||||||||||||||
| first_list_key = list_keys[0] | ||||||||||||||||||||||||||||||||||||||
| assert len(data[first_list_key]) == 3 | ||||||||||||||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||||||||||||||
| if os.path.exists(filename): | ||||||||||||||||||||||||||||||||||||||
| os.remove(filename) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+32
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be more pythonic... |
||||||||||||||||||||||||||||||||||||||
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 wonder whether we should create a "MonteCarloDataExporter" similarly to what we have recelty done with the Flight class.
Needs to think more about it.