""" 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