PauloFN commited on
Commit
4cc9779
·
1 Parent(s): bc8e11c

update pdf generation strings

Browse files
Files changed (1) hide show
  1. services/pdf_service.py +29 -9
services/pdf_service.py CHANGED
@@ -9,6 +9,12 @@ import logging
9
  logging.basicConfig(level=logging.INFO)
10
  logger = logging.getLogger(__name__)
11
 
 
 
 
 
 
 
12
  class PdfService:
13
  """
14
  A service to generate PDF reports.
@@ -36,8 +42,8 @@ class PdfService:
36
 
37
  # Metadata
38
  p.setFont("Helvetica", 12)
39
- p.drawString(72, height - 108, f"Ship ID: {metadata.ship_id}")
40
- p.drawString(72, height - 126, f"Timestamp: {metadata.timestamp.strftime('%Y-%m-%d %H:%M:%S')}")
41
  p.drawString(72, height - 144, f"Latitude: {metadata.latitude}")
42
  p.drawString(72, height - 162, f"Longitude: {metadata.longitude}")
43
 
@@ -51,22 +57,28 @@ class PdfService:
51
  # ML Results
52
  p.setFont("Helvetica-Bold", 14)
53
  y_position = height - 270
54
- p.drawString(72, y_position, "ML Results")
55
  y_position -= 18
56
  p.setFont("Helvetica", 12)
57
 
58
  # Highlight draft from ML results
59
  if 'draft' in ml_results:
60
  p.setFont("Helvetica-Bold", 12) # Highlight
61
- p.drawString(90, y_position, f"ML Draft: {ml_results['draft']:.2f} meters")
62
  p.setFont("Helvetica", 12) # Reset font
63
  y_position -= 18
64
 
65
  # Add other ML results (excluding arrays and images)
66
  for key, value in ml_results.items():
67
- if key in ['pose_results', 'segment_results', 'original_image', 'pose_image_result', 'segment_image_result', 'final_image_result']:
 
 
68
  continue
69
- p.drawString(90, y_position, f"{key.replace('_', ' ').title()}: {value}")
 
 
 
 
70
  y_position -= 18
71
 
72
  # Images
@@ -104,7 +116,7 @@ class PdfService:
104
  if 'extracted_mark_image' in ml_results and ml_results['extracted_mark_image'] is not None:
105
  original_img_bytes = get_image_bytes(ml_results['extracted_mark_image'])
106
  if original_img_bytes:
107
- p.drawString(current_x, y_image_row + image_height + 5, "Extracted Mark Image:") # Label above image
108
  p.drawImage(ImageReader(BytesIO(original_img_bytes)), current_x, y_image_row, width=image_width, height=image_height, preserveAspectRatio=True)
109
  current_x += image_width + 20 # Move x for next image
110
 
@@ -112,7 +124,7 @@ class PdfService:
112
  if 'pose_image_result' in ml_results and ml_results['pose_image_result'] is not None:
113
  pose_img_bytes = get_image_bytes(ml_results['pose_image_result'])
114
  if pose_img_bytes:
115
- p.drawString(current_x, y_image_row + image_height + 5, "Pose Image Result:")
116
  p.drawImage(ImageReader(BytesIO(pose_img_bytes)), current_x, y_image_row, width=image_width, height=image_height, preserveAspectRatio=True)
117
  current_x += image_width + 20
118
 
@@ -120,13 +132,21 @@ class PdfService:
120
  if 'segment_image_result' in ml_results and ml_results['segment_image_result'] is not None:
121
  segment_img_bytes = get_image_bytes(ml_results['segment_image_result'])
122
  if segment_img_bytes:
123
- p.drawString(current_x, y_image_row + image_height + 5, "Segment Image Result:")
124
  p.drawImage(ImageReader(BytesIO(segment_img_bytes)), current_x, y_image_row, width=image_width, height=image_height, preserveAspectRatio=True)
125
  # No need to update current_x as it's the last image in the row
126
 
127
  # Update y_position for content after images
128
  y_position = y_image_row - 20 # Adjust y_position to be below the images
129
 
 
 
 
 
 
 
 
 
130
  p.showPage()
131
  p.save()
132
 
 
9
  logging.basicConfig(level=logging.INFO)
10
  logger = logging.getLogger(__name__)
11
 
12
+ STRINGS = {
13
+ "meter_value": "Marca Métrica",
14
+ "last_valid_keypoint":"Último keypoint válido",
15
+ "cm_distance":"Distância água<->marca",
16
+ }
17
+
18
  class PdfService:
19
  """
20
  A service to generate PDF reports.
 
42
 
43
  # Metadata
44
  p.setFont("Helvetica", 12)
45
+ p.drawString(72, height - 108, f"ID: {metadata.ship_id}")
46
+ p.drawString(72, height - 126, f"Data: {metadata.timestamp.strftime('%Y-%m-%d %H:%M:%S')}")
47
  p.drawString(72, height - 144, f"Latitude: {metadata.latitude}")
48
  p.drawString(72, height - 162, f"Longitude: {metadata.longitude}")
49
 
 
57
  # ML Results
58
  p.setFont("Helvetica-Bold", 14)
59
  y_position = height - 270
60
+ p.drawString(72, y_position, "Resultados de ML")
61
  y_position -= 18
62
  p.setFont("Helvetica", 12)
63
 
64
  # Highlight draft from ML results
65
  if 'draft' in ml_results:
66
  p.setFont("Helvetica-Bold", 12) # Highlight
67
+ p.drawString(90, y_position, f"Draft Predito: {ml_results['draft']:.2f} meters")
68
  p.setFont("Helvetica", 12) # Reset font
69
  y_position -= 18
70
 
71
  # Add other ML results (excluding arrays and images)
72
  for key, value in ml_results.items():
73
+ if key in ['pose_results', 'segment_results', 'original_image',
74
+ 'pose_image_result', 'segment_image_result', 'final_image_result',
75
+ 'extracted_mark_image', 'draft']:
76
  continue
77
+ try:
78
+ new_key = STRINGS[key]
79
+ except:
80
+ new_key = key.replace('_', ' ').title()
81
+ p.drawString(90, y_position, f"{new_key}: {value:.3f}")
82
  y_position -= 18
83
 
84
  # Images
 
116
  if 'extracted_mark_image' in ml_results and ml_results['extracted_mark_image'] is not None:
117
  original_img_bytes = get_image_bytes(ml_results['extracted_mark_image'])
118
  if original_img_bytes:
119
+ p.drawString(current_x, y_image_row + image_height + 5, "Segmento Extraído p/ OCR") # Label above image
120
  p.drawImage(ImageReader(BytesIO(original_img_bytes)), current_x, y_image_row, width=image_width, height=image_height, preserveAspectRatio=True)
121
  current_x += image_width + 20 # Move x for next image
122
 
 
124
  if 'pose_image_result' in ml_results and ml_results['pose_image_result'] is not None:
125
  pose_img_bytes = get_image_bytes(ml_results['pose_image_result'])
126
  if pose_img_bytes:
127
+ p.drawString(current_x, y_image_row + image_height + 5, "Estimação de Pose")
128
  p.drawImage(ImageReader(BytesIO(pose_img_bytes)), current_x, y_image_row, width=image_width, height=image_height, preserveAspectRatio=True)
129
  current_x += image_width + 20
130
 
 
132
  if 'segment_image_result' in ml_results and ml_results['segment_image_result'] is not None:
133
  segment_img_bytes = get_image_bytes(ml_results['segment_image_result'])
134
  if segment_img_bytes:
135
+ p.drawString(current_x, y_image_row + image_height + 5, "Segmentação de Imagem")
136
  p.drawImage(ImageReader(BytesIO(segment_img_bytes)), current_x, y_image_row, width=image_width, height=image_height, preserveAspectRatio=True)
137
  # No need to update current_x as it's the last image in the row
138
 
139
  # Update y_position for content after images
140
  y_position = y_image_row - 20 # Adjust y_position to be below the images
141
 
142
+ # p.setFont("Helvetica-Bold", 14)
143
+ # y_position -= 18
144
+ # p.drawString(72, y_position, "Observações")
145
+ # y_position -= 18
146
+ # p.setFont("Helvetica", 12)
147
+ # p.drawString(72, y_position, "")
148
+
149
+
150
  p.showPage()
151
  p.save()
152