Update app.py
Browse files
app.py
CHANGED
|
@@ -274,6 +274,42 @@ class DicomAnalyzer:
|
|
| 274 |
except Exception as e:
|
| 275 |
print(f"Error updating display: {str(e)}")
|
| 276 |
return self.original_display
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
def add_formulas_to_template(self, ws, row_pair, col_group, red_font):
|
| 278 |
try:
|
| 279 |
base_col = col_group[1] # Mean column
|
|
@@ -495,6 +531,7 @@ class DicomAnalyzer:
|
|
| 495 |
self.marks.pop()
|
| 496 |
return self.update_display(), self.format_results()
|
| 497 |
|
|
|
|
| 498 |
def create_interface():
|
| 499 |
print("Creating interface...")
|
| 500 |
analyzer = DicomAnalyzer()
|
|
|
|
| 274 |
except Exception as e:
|
| 275 |
print(f"Error updating display: {str(e)}")
|
| 276 |
return self.original_display
|
| 277 |
+
|
| 278 |
+
def save_results(self):
|
| 279 |
+
"""
|
| 280 |
+
Basic save function for raw results with improved error handling and logging
|
| 281 |
+
"""
|
| 282 |
+
try:
|
| 283 |
+
if not self.results:
|
| 284 |
+
logger.warning("Attempted to save with no results")
|
| 285 |
+
return None, "No results to save"
|
| 286 |
+
|
| 287 |
+
df = pd.DataFrame(self.results)
|
| 288 |
+
columns_order = ['Area (mm²)', 'Mean', 'StdDev', 'Min', 'Max', 'Point']
|
| 289 |
+
df = df[columns_order]
|
| 290 |
+
|
| 291 |
+
timestamp = time.strftime("%Y%m%d_%H%M%S")
|
| 292 |
+
output_file = f"analysis_results_{timestamp}.xlsx"
|
| 293 |
+
|
| 294 |
+
with pd.ExcelWriter(output_file, engine='openpyxl') as writer:
|
| 295 |
+
df.to_excel(writer, index=False, sheet_name='Results')
|
| 296 |
+
|
| 297 |
+
worksheet = writer.sheets['Results']
|
| 298 |
+
for idx, col in enumerate(df.columns):
|
| 299 |
+
max_length = max(
|
| 300 |
+
df[col].astype(str).apply(len).max(),
|
| 301 |
+
len(str(col))
|
| 302 |
+
) + 2
|
| 303 |
+
worksheet.column_dimensions[get_column_letter(idx + 1)].width = max_length
|
| 304 |
+
|
| 305 |
+
logger.info(f"Results saved successfully to {output_file}")
|
| 306 |
+
return output_file, f"Results saved successfully to {output_file}"
|
| 307 |
+
|
| 308 |
+
except Exception as e:
|
| 309 |
+
error_msg = f"Error saving results: {str(e)}"
|
| 310 |
+
logger.error(error_msg)
|
| 311 |
+
logger.error(traceback.format_exc())
|
| 312 |
+
return None, error_msg
|
| 313 |
def add_formulas_to_template(self, ws, row_pair, col_group, red_font):
|
| 314 |
try:
|
| 315 |
base_col = col_group[1] # Mean column
|
|
|
|
| 531 |
self.marks.pop()
|
| 532 |
return self.update_display(), self.format_results()
|
| 533 |
|
| 534 |
+
# Interface Creation and Main Execution
|
| 535 |
def create_interface():
|
| 536 |
print("Creating interface...")
|
| 537 |
analyzer = DicomAnalyzer()
|