|
14 | 14 | """ |
15 | 15 |
|
16 | 16 | import json |
| 17 | +import csv |
17 | 18 | import os |
18 | 19 | import traceback |
19 | 20 | import warnings |
@@ -588,6 +589,25 @@ def __evaluate_flight_outputs(self, flight, sim_idx): |
588 | 589 | json.dumps(outputs_dict, cls=RocketPyEncoder, **self._export_config) + "\n" |
589 | 590 | ) |
590 | 591 |
|
| 592 | + def export_results(self, output_filename, output_format): |
| 593 | + txt_data = [] |
| 594 | + with open(self.filename, "r", encoding="utf-8") as f: |
| 595 | + for line in enumerate(f): |
| 596 | + line = line.strip() |
| 597 | + data = json.loads(line) |
| 598 | + txt_data.append(data) |
| 599 | + |
| 600 | + output_format = output_format.strip().lower() |
| 601 | + if output_format == "json": |
| 602 | + with open(f"{output_filename}.json", "w", encoding="utf-8") as f: |
| 603 | + json.dump(txt_data, f, indent=4) |
| 604 | + elif output_format == "csv": |
| 605 | + output_csv_header = txt_data[0].keys() |
| 606 | + with open(f"{output_filename}.csv", "w", newLine='', encoding="utf-8") as f: |
| 607 | + output_writer = csv.DictWriter(f, fieldnames=output_csv_header) |
| 608 | + output_writer.writeheader() |
| 609 | + output_writer.writerows(txt_data) |
| 610 | + |
591 | 611 | def __terminate_simulation(self): |
592 | 612 | """ |
593 | 613 | Terminates the simulation, closes the files and prints the results. |
|
0 commit comments