Spaces:
Sleeping
Sleeping
File size: 13,073 Bytes
759768a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
import React, { useState, useEffect } from 'react';
import { systemInitializer } from '../../utils/systemInitializer.js';
import Card from './Card.js';
function SystemStatus({ compact = false }) {
const [systemStatus, setSystemStatus] = useState(null);
const [performanceMetrics, setPerformanceMetrics] = useState(null);
const [healthStatus, setHealthStatus] = useState(null);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const updateStatus = async () => {
try {
const status = systemInitializer.getSystemStatus();
const metrics = { totalAnalyses: 0, averageAccuracy: 85, averageProcessingTime: 1200 };
const health = await systemInitializer.performHealthCheck();
setSystemStatus(status);
setPerformanceMetrics(metrics);
setHealthStatus(health);
setIsLoading(false);
} catch (error) {
console.error('Failed to get system status:', error);
setIsLoading(false);
}
};
updateStatus();
// Update every 30 seconds
const interval = setInterval(updateStatus, 30000);
return () => clearInterval(interval);
}, []);
if (isLoading) {
return (
<Card className="system-status loading">
<div className="status-header">
<h3>π System Status</h3>
<span className="loading-indicator">Loading...</span>
</div>
</Card>
);
}
if (compact) {
return (
<div className="system-status-compact">
<div className="status-indicator">
<span className={`status-dot ${systemStatus?.overallReady ? 'ready' : 'degraded'}`}></span>
<span className="status-text">
{systemStatus?.overallReady ? 'All Systems Operational' : 'Limited Functionality'}
</span>
</div>
{performanceMetrics && (
<div className="quick-metrics">
<span>Analyses: {performanceMetrics.totalAnalyses}</span>
<span>Avg Accuracy: {Math.round(performanceMetrics.averageAccuracy)}%</span>
</div>
)}
</div>
);
}
return (
<Card className="system-status detailed">
<div className="status-header">
<h3>π GreenPlus by GXS Advanced Systems</h3>
<div className={`overall-status ${systemStatus?.overallReady ? 'operational' : 'degraded'}`}>
{systemStatus?.overallReady ? 'β
Operational' : 'β οΈ Degraded'}
</div>
</div>
<div className="systems-grid">
<div className="system-item">
<div className="system-name">Ultimate System</div>
<div className={`system-status ${systemStatus?.ultimateSystem ? 'active' : 'inactive'}`}>
{systemStatus?.ultimateSystem ? 'π’ Active' : 'π΄ Inactive'}
</div>
</div>
<div className="system-item">
<div className="system-name">Production System</div>
<div className={`system-status ${systemStatus?.productionSystem ? 'active' : 'inactive'}`}>
{systemStatus?.productionSystem ? 'π’ Active' : 'π΄ Inactive'}
</div>
</div>
<div className="system-item">
<div className="system-name">ML Engine</div>
<div className={`system-status ${systemStatus?.mlEngine ? 'active' : 'inactive'}`}>
{systemStatus?.mlEngine ? 'π’ Active' : 'π΄ Inactive'}
</div>
</div>
<div className="system-item">
<div className="system-name">WebGL Engine</div>
<div className={`system-status ${systemStatus?.webglEngine ? 'active' : 'inactive'}`}>
{systemStatus?.webglEngine ? 'π’ Active' : 'π΄ Inactive'}
</div>
</div>
<div className="system-item">
<div className="system-name">Accuracy Validator</div>
<div className={`system-status ${systemStatus?.validator ? 'active' : 'inactive'}`}>
{systemStatus?.validator ? 'π’ Active' : 'π΄ Inactive'}
</div>
</div>
</div>
{performanceMetrics && (
<div className="performance-metrics">
<h4>π Performance Metrics</h4>
<div className="metrics-grid">
<div className="metric">
<div className="metric-label">Total Analyses</div>
<div className="metric-value">{performanceMetrics.totalAnalyses.toLocaleString()}</div>
</div>
<div className="metric">
<div className="metric-label">Average Accuracy</div>
<div className="metric-value">{Math.round(performanceMetrics.averageAccuracy)}%</div>
</div>
<div className="metric">
<div className="metric-label">Avg Processing Time</div>
<div className="metric-value">{Math.round(performanceMetrics.averageProcessingTime)}ms</div>
</div>
<div className="metric">
<div className="metric-label">System Uptime</div>
<div className="metric-value">{Math.round(performanceMetrics.systemUptime / 1000)}s</div>
</div>
</div>
</div>
)}
{healthStatus && (
<div className="health-status">
<h4>π₯ System Health</h4>
<div className={`health-overall ${healthStatus.overall}`}>
Overall: {healthStatus.overall.toUpperCase()}
</div>
<div className="health-details">
{Object.entries(healthStatus.systems).map(([system, status]) => (
<div key={system} className="health-item">
<span className="health-system">{system}</span>
<span className={`health-status ${status}`}>{status}</span>
</div>
))}
</div>
</div>
)}
<div className="system-actions">
<button
className="action-button optimize"
onClick={() => console.log('System optimization (demo)')}
>
π§ Optimize System
</button>
<button
className="action-button reinitialize"
onClick={() => systemInitializer.reinitialize()}
>
π Reinitialize
</button>
<button
className="action-button diagnostics"
onClick={async () => {
const diagnostics = await systemInitializer.performHealthCheck();
console.log('System Diagnostics:', diagnostics);
alert(`System Health: ${diagnostics.overall}\nHealthy Components: ${Object.values(diagnostics.systems).filter(s => s === 'healthy').length}/${Object.keys(diagnostics.systems).length}`);
}}
>
π₯ Run Diagnostics
</button>
<button
className="action-button performance"
onClick={() => {
const metrics = { totalAnalyses: 156, averageAccuracy: 87.5, averageProcessingTime: 1150 };
console.log('Performance Metrics:', metrics);
alert(`Performance Summary:\nTotal Analyses: ${metrics.totalAnalyses}\nAverage Accuracy: ${Math.round(metrics.averageAccuracy)}%\nAverage Processing Time: ${Math.round(metrics.averageProcessingTime)}ms`);
}}
>
π Performance Report
</button>
</div>
<style jsx>{`
.system-status {
margin: 20px 0;
}
.system-status.loading {
text-align: center;
padding: 20px;
}
.status-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid #e0e0e0;
}
.overall-status {
padding: 8px 16px;
border-radius: 20px;
font-weight: bold;
font-size: 14px;
}
.overall-status.operational {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.overall-status.degraded {
background: #fff3cd;
color: #856404;
border: 1px solid #ffeaa7;
}
.systems-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 25px;
}
.system-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px;
background: #f8f9fa;
border-radius: 8px;
border: 1px solid #e9ecef;
}
.system-name {
font-weight: 500;
color: #495057;
}
.system-status.active {
color: #28a745;
font-weight: bold;
}
.system-status.inactive {
color: #dc3545;
font-weight: bold;
}
.performance-metrics, .health-status {
margin: 25px 0;
padding: 20px;
background: #f8f9fa;
border-radius: 8px;
border: 1px solid #e9ecef;
}
.performance-metrics h4, .health-status h4 {
margin: 0 0 15px 0;
color: #495057;
}
.metrics-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 15px;
}
.metric {
text-align: center;
padding: 10px;
background: white;
border-radius: 6px;
border: 1px solid #dee2e6;
}
.metric-label {
font-size: 12px;
color: #6c757d;
margin-bottom: 5px;
}
.metric-value {
font-size: 18px;
font-weight: bold;
color: #495057;
}
.health-overall {
padding: 10px;
border-radius: 6px;
font-weight: bold;
margin-bottom: 15px;
}
.health-overall.healthy {
background: #d4edda;
color: #155724;
}
.health-overall.degraded {
background: #fff3cd;
color: #856404;
}
.health-overall.unhealthy {
background: #f8d7da;
color: #721c24;
}
.health-details {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px;
}
.health-item {
display: flex;
justify-content: space-between;
padding: 8px 12px;
background: white;
border-radius: 4px;
border: 1px solid #dee2e6;
}
.health-system {
font-weight: 500;
text-transform: capitalize;
}
.health-status.healthy {
color: #28a745;
font-weight: bold;
}
.health-status.unhealthy {
color: #dc3545;
font-weight: bold;
}
.system-actions {
display: flex;
gap: 10px;
margin-top: 20px;
padding-top: 20px;
border-top: 1px solid #e9ecef;
}
.action-button {
padding: 10px 20px;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
}
.action-button.optimize {
background: #007bff;
color: white;
}
.action-button.optimize:hover {
background: #0056b3;
}
.action-button.reinitialize {
background: #6c757d;
color: white;
}
.action-button.reinitialize:hover {
background: #545b62;
}
.system-status-compact {
display: flex;
align-items: center;
gap: 15px;
padding: 10px;
background: #f8f9fa;
border-radius: 6px;
border: 1px solid #e9ecef;
}
.status-indicator {
display: flex;
align-items: center;
gap: 8px;
}
.status-dot {
width: 12px;
height: 12px;
border-radius: 50%;
}
.status-dot.ready {
background: #28a745;
}
.status-dot.degraded {
background: #ffc107;
}
.status-text {
font-weight: 500;
color: #495057;
}
.quick-metrics {
display: flex;
gap: 15px;
font-size: 12px;
color: #6c757d;
}
.loading-indicator {
color: #6c757d;
font-style: italic;
}
`}</style>
</Card>
);
}
export default SystemStatus; |