Spaces:
Running
Running
File size: 571 Bytes
8913f77 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
"""
Utility helper functions for SEO Report Generator
"""
def safe_pct(n, d):
"""Calculate percentage with zero guard"""
try:
return round(100 * n / d, 1) if d else 0.0
except (TypeError, ZeroDivisionError):
return 0.0
def as_int(x, default=0):
"""Convert to integer with fallback"""
try:
return int(x)
except (ValueError, TypeError):
return default
def as_float(x, default=0.0):
"""Convert to float with fallback"""
try:
return float(x)
except (ValueError, TypeError):
return default |