MCPcopy
hub / github.com/tanelpoder/0xtools / parse_s10_value

Method parse_s10_value

xtop/core/time_utils.py:33–56  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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:

Callers 4

extract_time_bucketsMethod · 0.80
sort_keyMethod · 0.80
get_missing_bucketsMethod · 0.80
test_parse_s10_valueMethod · 0.80

Calls

no outgoing calls

Tested by 1

test_parse_s10_valueMethod · 0.64