system_info.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. """
  2. System Information Panel
  3. Displays performance metrics and model accuracy statistics.
  4. """
  5. from PyQt5.QtWidgets import QGroupBox, QHBoxLayout, QVBoxLayout, QLabel
  6. from PyQt5.QtGui import QFont
  7. from resources.styles import GROUP_BOX_STYLE, HEADER_LABEL_STYLE, STATUS_LABEL_STYLE
  8. class SystemInfoPanel(QGroupBox):
  9. """
  10. Panel displaying system information and statistics.
  11. Shows:
  12. - Performance metrics (processing time, throughput, uptime)
  13. - Model accuracy statistics (calculated from confidence scores)
  14. Note: Memory usage is displayed in SystemStatusPanel, not here.
  15. """
  16. def __init__(self):
  17. """Initialize the system information panel."""
  18. super().__init__("System Information")
  19. self.setStyleSheet(GROUP_BOX_STYLE)
  20. self.init_ui()
  21. def init_ui(self):
  22. """Initialize the UI components."""
  23. layout = QHBoxLayout()
  24. # Performance Metrics (left side)
  25. perf_layout = QVBoxLayout()
  26. perf_label = QLabel("Performance Metrics:")
  27. perf_label.setFont(QFont("Arial", 16, QFont.Bold))
  28. perf_label.setStyleSheet(HEADER_LABEL_STYLE)
  29. perf_layout.addWidget(perf_label)
  30. # Performance metrics
  31. self.metrics = {
  32. 'processing_time': QLabel("• Average Processing Time: --"),
  33. 'throughput': QLabel("• Daily Throughput: 0 fruits analyzed"),
  34. 'uptime': QLabel("• System Uptime: 0h 0m")
  35. }
  36. for metric_label in self.metrics.values():
  37. metric_label.setStyleSheet(STATUS_LABEL_STYLE)
  38. perf_layout.addWidget(metric_label)
  39. layout.addLayout(perf_layout)
  40. # Model Accuracy (right side)
  41. accuracy_layout = QVBoxLayout()
  42. accuracy_header = QLabel("Model Accuracy (Last 100 Tests):")
  43. accuracy_header.setFont(QFont("Arial", 16, QFont.Bold))
  44. accuracy_header.setStyleSheet(HEADER_LABEL_STYLE)
  45. accuracy_layout.addWidget(accuracy_header)
  46. # Accuracy metrics (mapped from model_type returned by DataManager)
  47. # Model types: 'audio', 'defect', 'locule', 'maturity', 'shape'
  48. self.accuracies = {
  49. 'audio': QLabel("• Ripeness Classification: --"),
  50. 'defect': QLabel("• Defect Detection: --"),
  51. 'locule': QLabel("• Locule Detection: --"),
  52. 'maturity': QLabel("• Maturity Assessment: --"),
  53. 'shape': QLabel("• Shape Analysis: --")
  54. }
  55. for accuracy_label in self.accuracies.values():
  56. accuracy_label.setStyleSheet(STATUS_LABEL_STYLE)
  57. accuracy_layout.addWidget(accuracy_label)
  58. layout.addLayout(accuracy_layout)
  59. self.setLayout(layout)
  60. def update_processing_time(self, avg_time: float):
  61. """
  62. Update average processing time.
  63. Args:
  64. avg_time: Average processing time in seconds
  65. """
  66. self.metrics['processing_time'].setText(f"• Average Processing Time: {avg_time:.1f}s per fruit")
  67. def update_throughput(self, count: int):
  68. """
  69. Update daily throughput.
  70. Args:
  71. count: Number of fruits analyzed today
  72. """
  73. self.metrics['throughput'].setText(f"• Daily Throughput: {count:,} fruits analyzed")
  74. def update_uptime(self, hours: int, minutes: int):
  75. """
  76. Update system uptime.
  77. Args:
  78. hours: Uptime hours
  79. minutes: Uptime minutes
  80. """
  81. self.metrics['uptime'].setText(f"• System Uptime: {hours}h {minutes}m")
  82. def update_accuracy(self, model: str, accuracy: float):
  83. """
  84. Update model accuracy.
  85. Args:
  86. model: Model name from DataManager ('audio', 'defect', 'locule', 'maturity', 'shape')
  87. accuracy: Accuracy percentage (0-100)
  88. """
  89. if model in self.accuracies:
  90. label_map = {
  91. 'audio': f"• Ripeness Classification: {accuracy:.1f}%",
  92. 'defect': f"• Defect Detection: {accuracy:.1f}%",
  93. 'locule': f"• Locule Detection: {accuracy:.1f}%",
  94. 'maturity': f"• Maturity Assessment: {accuracy:.1f}%",
  95. 'shape': f"• Shape Analysis: {accuracy:.1f}%"
  96. }
  97. self.accuracies[model].setText(label_map[model])