HeshamAI commited on
Commit
105f16e
·
verified ·
1 Parent(s): b211971

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -341,8 +341,11 @@ class DicomAnalyzer:
341
  wb = openpyxl.Workbook()
342
  ws = wb.active
343
  red_font = openpyxl.styles.Font(color="FF0000")
 
 
344
  #Define headers
345
  headers = ['Area', 'Mean', 'StdDev', 'Min', 'Max']
 
346
 
347
  column_groups = [
348
  ('B', 'C', 'D', 'E', 'F'), ('H', 'I', 'J', 'K', 'L'),
@@ -358,7 +361,7 @@ class DicomAnalyzer:
358
  for i, header in enumerate(headers):
359
  cell = ws[f"{cols[i]}1"]
360
  cell.value = header
361
-
362
 
363
 
364
  row_pairs = [
@@ -372,7 +375,8 @@ class DicomAnalyzer:
372
  for i, size in enumerate(phantom_sizes):
373
  header_cell = ws.cell(row=row_pairs[i][0]-1, column=1, value=size)
374
  header_cell.font = red_font
375
-
 
376
  result_idx = 0
377
  current_col_group = 0
378
  current_row_pair = 0
@@ -401,6 +405,13 @@ class DicomAnalyzer:
401
  current_col_group = 0
402
  current_row_pair += 1
403
 
 
 
 
 
 
 
 
404
  wb.save(output_path)
405
  return output_path, f"Results saved successfully ({result_idx} measurements)"
406
 
@@ -409,12 +420,19 @@ class DicomAnalyzer:
409
  return None, f"Error saving results: {str(e)}"
410
 
411
  def _write_result_to_cells(self, ws, result, cols, row):
 
 
412
  ws[f"{cols[0]}{row}"] = float(result['Area (mm²)'])
413
  ws[f"{cols[1]}{row}"] = float(result['Mean'])
414
  ws[f"{cols[2]}{row}"] = float(result['StdDev'])
415
  ws[f"{cols[3]}{row}"] = float(result['Min'])
416
  ws[f"{cols[4]}{row}"] = float(result['Max'])
417
 
 
 
 
 
 
418
  def format_results(self):
419
  if not self.results:
420
  return "No measurements yet"
 
341
  wb = openpyxl.Workbook()
342
  ws = wb.active
343
  red_font = openpyxl.styles.Font(color="FF0000")
344
+ center_alignment = openpyxl.styles.Alignment(horizontal='center')
345
+
346
  #Define headers
347
  headers = ['Area', 'Mean', 'StdDev', 'Min', 'Max']
348
+
349
 
350
  column_groups = [
351
  ('B', 'C', 'D', 'E', 'F'), ('H', 'I', 'J', 'K', 'L'),
 
361
  for i, header in enumerate(headers):
362
  cell = ws[f"{cols[i]}1"]
363
  cell.value = header
364
+ cell.alignment = center_alignment # Center align the headers
365
 
366
 
367
  row_pairs = [
 
375
  for i, size in enumerate(phantom_sizes):
376
  header_cell = ws.cell(row=row_pairs[i][0]-1, column=1, value=size)
377
  header_cell.font = red_font
378
+ header_cell.alignment = center_alignment # Center align the phantom sizes
379
+
380
  result_idx = 0
381
  current_col_group = 0
382
  current_row_pair = 0
 
405
  current_col_group = 0
406
  current_row_pair += 1
407
 
408
+ # Center align all data cells
409
+ for cols in column_groups:
410
+ for col in cols:
411
+ for row in range(2, 31): # Adjust range based on your data
412
+ cell = ws[f"{col}{row}"]
413
+ cell.alignment = center_alignment
414
+
415
  wb.save(output_path)
416
  return output_path, f"Results saved successfully ({result_idx} measurements)"
417
 
 
420
  return None, f"Error saving results: {str(e)}"
421
 
422
  def _write_result_to_cells(self, ws, result, cols, row):
423
+ """Helper method to write a single result to worksheet cells"""
424
+ center_alignment = openpyxl.styles.Alignment(horizontal='center')
425
  ws[f"{cols[0]}{row}"] = float(result['Area (mm²)'])
426
  ws[f"{cols[1]}{row}"] = float(result['Mean'])
427
  ws[f"{cols[2]}{row}"] = float(result['StdDev'])
428
  ws[f"{cols[3]}{row}"] = float(result['Min'])
429
  ws[f"{cols[4]}{row}"] = float(result['Max'])
430
 
431
+ for i, value in enumerate(['Area (mm²)', 'Mean', 'StdDev', 'Min', 'Max']):
432
+ cell = ws[f"{cols[i]}{row}"]
433
+ cell.value = float(result[value])
434
+ cell.alignment = center_alignment
435
+
436
  def format_results(self):
437
  if not self.results:
438
  return "No measurements yet"