Spaces:
Running
Running
| """ | |
| 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 |