Skip to content

Commit

Permalink
Code changes for standardization per input from reviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolm-dsider committed Mar 9, 2024
1 parent afd4f21 commit a0892a9
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/hip_ra_x/hip_ra_x.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@
"""


def UpgradeSymbologyOfUnits(unit: str) -> str:
"""
UpgradeSymbologyOfUnits is a function that takes a string that represents a unit and replaces the **2 and **3
with the appropriate unicode characters for superscript 2 and 3, and replaces "deg" with the unicode character
for degrees.
:param unit: a string that represents a unit
:return: a string that represents a unit with the appropriate unicode characters for superscript 2 and 3, and
replaces "deg" with the unicode character for degrees.
"""
unit = unit.replace('**2', '\u00b2').replace('**3', '\u00b3').replace('deg', '\u00b0')
return unit


class HIP_RA_X:
"""
HIP_RA_X is the container class of the HIP-RA-X application, giving access to everything else, including the logger
Expand Down Expand Up @@ -892,28 +905,22 @@ def render_scientific(p: floatParameter | OutputParameter) -> str:
f.write(f' {k}:{kv_spaces}{v}{nl}')

except FileNotFoundError as ex:
print(str(ex))
traceback_str = traceback.format_exc()
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
print(msg)
self.logger.critical(str(ex))
self.logger.critical(msg)
raise

except PermissionError as ex:
print(str(ex))
traceback_str = traceback.format_exc()
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
print(msg)
self.logger.critical(str(ex))
self.logger.critical(msg)
raise

except Exception as ex:
print(str(ex))
traceback_str = traceback.format_exc()
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
print(msg)
self.logger.critical(str(ex))
self.logger.critical(msg)
raise
Expand Down Expand Up @@ -958,13 +965,7 @@ def PrintOutputsHTML(self, inputs, outputs, output_filename: str = 'HIP.html'):
val = val1[0]
unit = ''
if len(val1) > 1:
unit: str = str(val1[1])
if '**2' in unit:
unit = unit.replace('**2', '\u00b2')
if '**3' in unit:
unit = unit.replace('**3', '\u00b3')
if 'deg' in unit:
unit = unit.replace('deg', '\u00b0')
unit: str = UpgradeSymbologyOfUnits(str(val1[1]))
inputs_table.add_row(name, val, unit)

for key, value in outputs['SUMMARY OF RESULTS'].items():
Expand All @@ -973,13 +974,8 @@ def PrintOutputsHTML(self, inputs, outputs, output_filename: str = 'HIP.html'):
val = val1[0]
unit = ''
if len(val1) > 1:
unit: str = str(val1[1])
if '**2' in unit:
unit = unit.replace('**2', '\u00b2')
if '**3' in unit:
unit = unit.replace('**3', '\u00b3')
if 'deg' in unit:
unit = unit.replace('deg', '\u00b0')
unit: str = UpgradeSymbologyOfUnits(str(val1[1]))

outputs_table.add_row(name, val, unit)

console = Console(style='bold white on blue', force_terminal=True, record=True)
Expand All @@ -993,28 +989,22 @@ def PrintOutputsHTML(self, inputs, outputs, output_filename: str = 'HIP.html'):
console.save_html('d:\\temp\\test_table.html')

except FileNotFoundError as ex:
print(str(ex))
traceback_str = traceback.format_exc()
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
print(msg)
self.logger.critical(str(ex))
self.logger.critical(msg)
raise

except PermissionError as ex:
print(str(ex))
traceback_str = traceback.format_exc()
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
print(msg)
self.logger.critical(str(ex))
self.logger.critical(msg)
raise

except Exception as ex:
print(str(ex))
traceback_str = traceback.format_exc()
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
print(msg)
self.logger.critical(str(ex))
self.logger.critical(msg)
raise
Expand Down

0 comments on commit a0892a9

Please sign in to comment.