Files
serv_benchmark/backend/app/utils/scoring.py
gilles soulier c6a8e8e83d feat: Complete MVP implementation of Linux BenchTools
 Features:
- Backend FastAPI complete (25 Python files)
  - 5 SQLAlchemy models (Device, HardwareSnapshot, Benchmark, Link, Document)
  - Pydantic schemas for validation
  - 4 API routers (benchmark, devices, links, docs)
  - Authentication with Bearer token
  - Automatic score calculation
  - File upload support

- Frontend web interface (13 files)
  - 4 HTML pages (Dashboard, Devices, Device Detail, Settings)
  - 7 JavaScript modules
  - Monokai dark theme CSS
  - Responsive design
  - Complete CRUD operations

- Client benchmark script (500+ lines Bash)
  - Hardware auto-detection
  - CPU, RAM, Disk, Network benchmarks
  - JSON payload generation
  - Robust error handling

- Docker deployment
  - Optimized Dockerfile
  - docker-compose with 2 services
  - Persistent volumes
  - Environment variables

- Documentation & Installation
  - Automated install.sh script
  - README, QUICKSTART, DEPLOYMENT guides
  - Complete API documentation
  - Project structure documentation

📊 Stats:
- ~60 files created
- ~5000 lines of code
- Full MVP feature set implemented

🚀 Ready for production deployment!

🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 14:46:10 +01:00

74 lines
1.7 KiB
Python

"""
Linux BenchTools - Scoring Utilities
"""
from app.core.config import settings
def calculate_global_score(
cpu_score: float = None,
memory_score: float = None,
disk_score: float = None,
network_score: float = None,
gpu_score: float = None
) -> float:
"""
Calculate global score from component scores using configured weights.
Returns:
float: Global score (0-100)
"""
scores = []
weights = []
if cpu_score is not None:
scores.append(cpu_score)
weights.append(settings.SCORE_WEIGHT_CPU)
if memory_score is not None:
scores.append(memory_score)
weights.append(settings.SCORE_WEIGHT_MEMORY)
if disk_score is not None:
scores.append(disk_score)
weights.append(settings.SCORE_WEIGHT_DISK)
if network_score is not None:
scores.append(network_score)
weights.append(settings.SCORE_WEIGHT_NETWORK)
if gpu_score is not None:
scores.append(gpu_score)
weights.append(settings.SCORE_WEIGHT_GPU)
if not scores:
return 0.0
# Normalize weights if not all components are present
total_weight = sum(weights)
if total_weight == 0:
return 0.0
# Calculate weighted average
weighted_sum = sum(score * weight for score, weight in zip(scores, weights))
global_score = weighted_sum / total_weight
# Clamp to 0-100 range
return max(0.0, min(100.0, global_score))
def validate_score(score: float) -> bool:
"""
Validate that a score is within acceptable range.
Args:
score: Score value to validate
Returns:
bool: True if score is valid (0-100 or None)
"""
if score is None:
return True
return 0.0 <= score <= 100.0