Skip to content

Commit

Permalink
MNT: Refactor input/output log parsing to use JSON instead of ast.lit…
Browse files Browse the repository at this point in the history
…eral_eval()
  • Loading branch information
Gui-FernandesBR committed Mar 13, 2024
1 parent d0b9711 commit 17d91d0
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions rocketpy/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ast
import json
from time import process_time, time

import numpy as np
Expand Down Expand Up @@ -447,9 +447,12 @@ def set_inputs_log(self):
if line[0] != "{":
continue
# Try to convert the line to a dictionary
d = ast.literal_eval(line)
# If successful, append the dictionary to the list
self.inputs_log.append(d)
try:
d = json.loads(line)
# If successful, append the dictionary to the list
self.inputs_log.append(d)
except json.JSONDecodeError:
continue

def set_outputs_log(self):
"""Sets outputs_log from a file into an attribute for easy access"""
Expand All @@ -461,9 +464,11 @@ def set_outputs_log(self):
if line[0] != "{":
continue
# Try to convert the line to a dictionary
d = ast.literal_eval(line)
# If successful, append the dictionary to the list
self.outputs_log.append(d)
try:
# If successful, append the dictionary to the list
self.outputs_log.append(json.loads(line))
except json.JSONDecodeError:
continue

def set_errors_log(self):
"""Sets errors_log log from a file into an attribute for easy access"""
Expand All @@ -475,9 +480,11 @@ def set_errors_log(self):
if line[0] != "{":
continue
# Try to convert the line to a dictionary
d = ast.literal_eval(line)
# If successful, append the dictionary to the list
self.errors_log.append(d)
try:
# If successful, append the dictionary to the list
self.errors_log.append(json.loads(line))
except json.JSONDecodeError:
continue

def set_num_of_loaded_sims(self):
"""Number of simulations loaded from output_file being currently used."""
Expand Down

0 comments on commit 17d91d0

Please sign in to comment.