#!/usr/bin/env python3 """Test BackBlaze calculation with different values""" import math from backblaze_tables import SMART_5_R, SMART_187_R, SMART_188_R, SMART_197_R, SMART_198_R def poisson_prob(rate): """Calculate P(at least 1 failure) = 1 - e^(-rate)""" return 1 - math.exp(-rate) def test_calculation(attr_value): """Test with a given attribute value""" # Scale monthly to annual (like snapraid does) afr_5 = (365.0 / 30.0) * SMART_5_R[min(attr_value, 255)] afr_187 = (365.0 / 30.0) * SMART_187_R[min(attr_value, 255)] afr_188 = (365.0 / 30.0) * SMART_188_R[min(attr_value, 255)] afr_197 = (365.0 / 30.0) * SMART_197_R[min(attr_value, 255)] afr_198 = (365.0 / 30.0) * SMART_198_R[min(attr_value, 255)] # Take maximum (like snapraid) max_afr = max(afr_5, afr_187, afr_188, afr_197, afr_198) # Apply Poisson prob = poisson_prob(max_afr) * 100 return max_afr, prob print("Testing different attribute values:") print("=" * 80) for test_val in [0, 50, 100, 150, 200, 255]: afr, prob = test_calculation(test_val) print(f"Attribute value {test_val:3d}: AFR={afr:.4f}, Probability={prob:.2f}%") print("\n" + "=" * 80) print("What we're seeing from /dev/sdc:") print(" All critical attributes: RAW_VALUE=0, VALUE=100") print(" SnapRAID reports: 81%") print(" Our calculation with value=0: ", end="") afr0, prob0 = test_calculation(0) print(f"{prob0:.2f}%") print(" Our calculation with value=100:", end="") afr100, prob100 = test_calculation(100) print(f"{prob100:.2f}%")