Skip to content

Commit a0892a9

Browse files
Code changes for standardization per input from reviewer
1 parent afd4f21 commit a0892a9

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/hip_ra_x/hip_ra_x.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@
5858
"""
5959

6060

61+
def UpgradeSymbologyOfUnits(unit: str) -> str:
62+
"""
63+
UpgradeSymbologyOfUnits is a function that takes a string that represents a unit and replaces the **2 and **3
64+
with the appropriate unicode characters for superscript 2 and 3, and replaces "deg" with the unicode character
65+
for degrees.
66+
:param unit: a string that represents a unit
67+
:return: a string that represents a unit with the appropriate unicode characters for superscript 2 and 3, and
68+
replaces "deg" with the unicode character for degrees.
69+
"""
70+
unit = unit.replace('**2', '\u00b2').replace('**3', '\u00b3').replace('deg', '\u00b0')
71+
return unit
72+
73+
6174
class HIP_RA_X:
6275
"""
6376
HIP_RA_X is the container class of the HIP-RA-X application, giving access to everything else, including the logger
@@ -892,28 +905,22 @@ def render_scientific(p: floatParameter | OutputParameter) -> str:
892905
f.write(f' {k}:{kv_spaces}{v}{nl}')
893906

894907
except FileNotFoundError as ex:
895-
print(str(ex))
896908
traceback_str = traceback.format_exc()
897909
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
898-
print(msg)
899910
self.logger.critical(str(ex))
900911
self.logger.critical(msg)
901912
raise
902913

903914
except PermissionError as ex:
904-
print(str(ex))
905915
traceback_str = traceback.format_exc()
906916
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
907-
print(msg)
908917
self.logger.critical(str(ex))
909918
self.logger.critical(msg)
910919
raise
911920

912921
except Exception as ex:
913-
print(str(ex))
914922
traceback_str = traceback.format_exc()
915923
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
916-
print(msg)
917924
self.logger.critical(str(ex))
918925
self.logger.critical(msg)
919926
raise
@@ -958,13 +965,7 @@ def PrintOutputsHTML(self, inputs, outputs, output_filename: str = 'HIP.html'):
958965
val = val1[0]
959966
unit = ''
960967
if len(val1) > 1:
961-
unit: str = str(val1[1])
962-
if '**2' in unit:
963-
unit = unit.replace('**2', '\u00b2')
964-
if '**3' in unit:
965-
unit = unit.replace('**3', '\u00b3')
966-
if 'deg' in unit:
967-
unit = unit.replace('deg', '\u00b0')
968+
unit: str = UpgradeSymbologyOfUnits(str(val1[1]))
968969
inputs_table.add_row(name, val, unit)
969970

970971
for key, value in outputs['SUMMARY OF RESULTS'].items():
@@ -973,13 +974,8 @@ def PrintOutputsHTML(self, inputs, outputs, output_filename: str = 'HIP.html'):
973974
val = val1[0]
974975
unit = ''
975976
if len(val1) > 1:
976-
unit: str = str(val1[1])
977-
if '**2' in unit:
978-
unit = unit.replace('**2', '\u00b2')
979-
if '**3' in unit:
980-
unit = unit.replace('**3', '\u00b3')
981-
if 'deg' in unit:
982-
unit = unit.replace('deg', '\u00b0')
977+
unit: str = UpgradeSymbologyOfUnits(str(val1[1]))
978+
983979
outputs_table.add_row(name, val, unit)
984980

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

995991
except FileNotFoundError as ex:
996-
print(str(ex))
997992
traceback_str = traceback.format_exc()
998993
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
999-
print(msg)
1000994
self.logger.critical(str(ex))
1001995
self.logger.critical(msg)
1002996
raise
1003997

1004998
except PermissionError as ex:
1005-
print(str(ex))
1006999
traceback_str = traceback.format_exc()
10071000
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
1008-
print(msg)
10091001
self.logger.critical(str(ex))
10101002
self.logger.critical(msg)
10111003
raise
10121004

10131005
except Exception as ex:
1014-
print(str(ex))
10151006
traceback_str = traceback.format_exc()
10161007
msg = f'Error: HIP_RA_X Failed to write the output file. Exiting....\n{traceback_str}'
1017-
print(msg)
10181008
self.logger.critical(str(ex))
10191009
self.logger.critical(msg)
10201010
raise

0 commit comments

Comments
 (0)