maturity_results_panel.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. """
  2. Maturity Results Panel
  3. Panel for displaying multispectral maturity classification results with confidence bars.
  4. """
  5. from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QProgressBar, QSizePolicy
  6. from PyQt5.QtCore import Qt
  7. from PyQt5.QtGui import QFont
  8. class MaturityResultsPanel(QWidget):
  9. """
  10. Panel for displaying maturity analysis results.
  11. """
  12. def __init__(self, parent=None):
  13. super().__init__(parent)
  14. self.init_ui()
  15. def init_ui(self):
  16. """Initialize the panel UI."""
  17. # Set size policy to expand equally
  18. self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
  19. layout = QVBoxLayout(self)
  20. layout.setContentsMargins(0, 0, 0, 0)
  21. layout.setSpacing(0)
  22. # Main panel container with card styling
  23. self.setStyleSheet("""
  24. QWidget {
  25. background-color: white;
  26. border: 1px solid #ddd;
  27. }
  28. """)
  29. # Header
  30. header = QWidget()
  31. header.setFixedHeight(25)
  32. header.setStyleSheet("background-color: #8e44ad;")
  33. header_layout = QHBoxLayout(header)
  34. header_layout.setContentsMargins(10, 0, 0, 0)
  35. title = QLabel("Maturity Analysis Results")
  36. title.setStyleSheet("color: white; font-weight: bold; font-size: 16px;")
  37. header_layout.addWidget(title)
  38. # Current Classification
  39. classification_label = QLabel("Current Classification:")
  40. classification_label.setStyleSheet("font-weight: bold; font-size: 12px; margin: 8px 10px 5px 10px; color: #2c3e50;")
  41. classification_frame = QWidget()
  42. classification_frame.setStyleSheet("background-color: #95a5a6;")
  43. classification_frame.setMinimumHeight(45)
  44. classification_layout = QVBoxLayout(classification_frame)
  45. classification_layout.setAlignment(Qt.AlignCenter)
  46. classification_layout.setContentsMargins(5, 5, 5, 5)
  47. self.class_display = QLabel("—")
  48. self.class_display.setAlignment(Qt.AlignCenter)
  49. self.class_display.setStyleSheet("color: white; font-weight: bold; font-size: 18px;")
  50. classification_layout.addWidget(self.class_display)
  51. # Confidence Scores
  52. confidence_label = QLabel("Confidence Scores:")
  53. confidence_label.setStyleSheet("font-weight: bold; font-size: 11px; margin: 8px 10px 5px 10px; color: #2c3e50;")
  54. # Create progress bars for each category
  55. categories = [
  56. ("Immature", 0, "#95a5a6"),
  57. ("Mature", 0, "#27ae60"),
  58. ("Overmature", 0, "#e74c3c")
  59. ]
  60. confidence_layout = QVBoxLayout()
  61. confidence_layout.setSpacing(4)
  62. self.confidence_bars = {}
  63. for name, value, color in categories:
  64. category_frame = QWidget()
  65. category_layout = QHBoxLayout(category_frame)
  66. category_layout.setContentsMargins(10, 0, 10, 0)
  67. category_layout.setSpacing(8)
  68. name_label = QLabel(f"{name}:")
  69. name_label.setFixedWidth(80)
  70. name_label.setStyleSheet("font-size: 10px; color: #2c3e50;")
  71. progress = QProgressBar()
  72. progress.setRange(0, 100)
  73. progress.setValue(int(value))
  74. progress.setTextVisible(False)
  75. progress.setStyleSheet(f"""
  76. QProgressBar {{
  77. background-color: #ecf0f1;
  78. border: 1px solid #bdc3c7;
  79. border-radius: 0px;
  80. height: 15px;
  81. }}
  82. QProgressBar::chunk {{
  83. background-color: {color};
  84. }}
  85. """)
  86. value_label = QLabel(f"{value}%")
  87. value_label.setFixedWidth(45)
  88. value_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
  89. value_label.setStyleSheet("font-size: 12px; color: #2c3e50;")
  90. category_layout.addWidget(name_label)
  91. category_layout.addWidget(progress)
  92. category_layout.addWidget(value_label)
  93. confidence_layout.addWidget(category_frame)
  94. self.confidence_bars[name] = (progress, value_label)
  95. # Processing time
  96. self.info_label = QLabel("")
  97. self.info_label.setStyleSheet("color: #7f8c8d; font-size: 12px; margin: 8px 10px 5px 10px;")
  98. layout.addWidget(header)
  99. layout.addWidget(classification_label)
  100. layout.addWidget(classification_frame)
  101. layout.addWidget(confidence_label)
  102. layout.addLayout(confidence_layout)
  103. layout.addWidget(self.info_label)
  104. layout.addStretch()
  105. def update_results(self, classification: str, probabilities: dict,
  106. processing_time: float = 0, model_version: str = "MaturityNet v1.0"):
  107. """
  108. Update the results display.
  109. Args:
  110. classification: Predicted class name
  111. probabilities: Dictionary of class probabilities (0-1)
  112. processing_time: Processing time in seconds
  113. model_version: Model version string
  114. """
  115. # Map class names to display names
  116. class_mapping = {
  117. "Immature": "Immature",
  118. "Mature": "Mature",
  119. "Overmature": "Overmature"
  120. }
  121. display_class = class_mapping.get(classification, classification)
  122. # Update classification display
  123. self.class_display.setText(display_class.upper())
  124. # Set color based on classification
  125. class_colors = {
  126. "Immature": "#95a5a6",
  127. "Mature": "#27ae60",
  128. "Overmature": "#e74c3c"
  129. }
  130. bg_color = class_colors.get(classification, "#95a5a6")
  131. self.class_display.parent().setStyleSheet(f"background-color: {bg_color};")
  132. self.class_display.setStyleSheet("""
  133. color: white;
  134. font-weight: bold;
  135. font-size: 18px;
  136. """)
  137. # Update confidence bars
  138. for class_name, (progress_bar, value_label) in self.confidence_bars.items():
  139. # Try to find matching probability (handle case variations)
  140. prob = 0
  141. for key, value in probabilities.items():
  142. if key.lower() == class_name.lower():
  143. prob = value
  144. break
  145. percentage = prob * 100
  146. # Update progress bar
  147. progress_bar.setValue(int(percentage))
  148. # Update value label
  149. value_label.setText(f"{percentage:.1f}%")
  150. # Highlight primary class
  151. if class_name == display_class:
  152. value_label.setStyleSheet("font-size: 12px; font-weight: bold; color: #2c3e50;")
  153. else:
  154. value_label.setStyleSheet("font-size: 12px; color: #2c3e50;")
  155. # Update info label
  156. self.info_label.setText(
  157. f"Processing Time: {processing_time:.2f}s | Model: {model_version}"
  158. )
  159. def clear_results(self):
  160. """Clear all results."""
  161. self.class_display.setText("—")
  162. self.class_display.setStyleSheet("""
  163. color: white;
  164. font-weight: bold;
  165. font-size: 18px;
  166. """)
  167. for progress_bar, value_label in self.confidence_bars.values():
  168. progress_bar.setValue(0)
  169. value_label.setText("0%")
  170. value_label.setStyleSheet("font-size: 12px; color: #2c3e50;")
  171. self.info_label.setText("")