Update app.py
Browse files
app.py
CHANGED
|
@@ -45,6 +45,43 @@ def debug_decorator(func):
|
|
| 45 |
logger.debug(f"Execution time: {end_time - start_time:.4f} seconds")
|
| 46 |
return wrapper
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
class DicomAnalyzer:
|
| 49 |
def __init__(self):
|
| 50 |
self.results = []
|
|
|
|
| 45 |
logger.debug(f"Execution time: {end_time - start_time:.4f} seconds")
|
| 46 |
return wrapper
|
| 47 |
|
| 48 |
+
def save_results(self):
|
| 49 |
+
"""
|
| 50 |
+
Basic save function for raw results with improved error handling and logging
|
| 51 |
+
"""
|
| 52 |
+
try:
|
| 53 |
+
if not self.results:
|
| 54 |
+
logger.warning("Attempted to save with no results")
|
| 55 |
+
return None, "No results to save"
|
| 56 |
+
|
| 57 |
+
df = pd.DataFrame(self.results)
|
| 58 |
+
columns_order = ['Area (mm²)', 'Mean', 'StdDev', 'Min', 'Max', 'Point']
|
| 59 |
+
df = df[columns_order]
|
| 60 |
+
|
| 61 |
+
timestamp = time.strftime("%Y%m%d_%H%M%S")
|
| 62 |
+
output_file = f"analysis_results_{timestamp}.xlsx"
|
| 63 |
+
|
| 64 |
+
with pd.ExcelWriter(output_file, engine='openpyxl') as writer:
|
| 65 |
+
df.to_excel(writer, index=False, sheet_name='Results')
|
| 66 |
+
|
| 67 |
+
worksheet = writer.sheets['Results']
|
| 68 |
+
for idx, col in enumerate(df.columns):
|
| 69 |
+
max_length = max(
|
| 70 |
+
df[col].astype(str).apply(len).max(),
|
| 71 |
+
len(str(col))
|
| 72 |
+
) + 2
|
| 73 |
+
worksheet.column_dimensions[get_column_letter(idx + 1)].width = max_length
|
| 74 |
+
|
| 75 |
+
logger.info(f"Results saved successfully to {output_file}")
|
| 76 |
+
return output_file, f"Results saved successfully to {output_file}"
|
| 77 |
+
|
| 78 |
+
except Exception as e:
|
| 79 |
+
error_msg = f"Error saving results: {str(e)}"
|
| 80 |
+
logger.error(error_msg)
|
| 81 |
+
logger.error(traceback.format_exc())
|
| 82 |
+
return None, error_msg
|
| 83 |
+
|
| 84 |
+
|
| 85 |
class DicomAnalyzer:
|
| 86 |
def __init__(self):
|
| 87 |
self.results = []
|