File tree Expand file tree Collapse file tree 1 file changed +28
-4
lines changed
Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -613,7 +613,31 @@ def hydrateEquilibriumTemperatureAnalyser(name, teststream):
613613 return hydrateEquilibriumTemperatureAnalyser
614614
615615
616- def results_json (process ):
617- json_report = str (process .getReport_json ())
618- results = json .loads (json_report )
619- return results
616+ def results_json (process , filename = None ):
617+ """
618+ Generate a JSON report from the process and optionally save it to a file.
619+
620+ Parameters:
621+ process: The process object to generate the report from.
622+ filename (str, optional): The file path to save the JSON report. If None, the report is not saved.
623+
624+ Returns:
625+ dict: The JSON report as a Python dictionary.
626+ """
627+ try :
628+ # Generate the JSON report
629+ json_report = str (process .getReport_json ())
630+ results = json .loads (json_report )
631+
632+ # Save to file if a filename is provided
633+ if filename :
634+ with open (filename , "w" ) as json_file :
635+ json .dump (results , json_file , indent = 4 )
636+ print (f"JSON report saved to { filename } " )
637+
638+ return results
639+ except Exception as e :
640+ print (f"Error generating JSON report: { e } " )
641+ return None
642+
643+
You can’t perform that action at this time.
0 commit comments