Safely parse S10 values that might be float or string. Args: s10_val: Value that could be int, float, string, or None Returns: Integer value of S10, defaulting to 0
(s10_val: Any)
| 31 | |
| 32 | @staticmethod |
| 33 | def parse_s10_value(s10_val: Any) -> int: |
| 34 | """ |
| 35 | Safely parse S10 values that might be float or string. |
| 36 | |
| 37 | Args: |
| 38 | s10_val: Value that could be int, float, string, or None |
| 39 | |
| 40 | Returns: |
| 41 | Integer value of S10, defaulting to 0 |
| 42 | """ |
| 43 | if s10_val is None or s10_val == '': |
| 44 | return 0 |
| 45 | |
| 46 | try: |
| 47 | # Handle strings like "0." or "10.0" |
| 48 | if isinstance(s10_val, str) and s10_val != '00': |
| 49 | return int(float(s10_val)) |
| 50 | elif isinstance(s10_val, (int, float)): |
| 51 | return int(s10_val) |
| 52 | else: |
| 53 | return 0 |
| 54 | except (ValueError, TypeError): |
| 55 | logger.warning(f"Could not parse S10 value: {s10_val}") |
| 56 | return 0 |
| 57 | |
| 58 | @staticmethod |
| 59 | def extract_time_buckets(row: Dict, granularity: str) -> str: |
no outgoing calls