helpers
¶
Functions:
-
camel_to_snake–Converts CamelCase to snake_case.
-
flatten_dict–Recursively flattens a nested dictionary using a separator for keys.
-
format_time–Formats elapsed time in seconds to a string in hh:mm:ss format.
-
parse_numbers–Parses a mix of single numbers and ranges (e.g., '1,3:5,7' → [1, 3, 4, 5, 7])
-
unflatten_dict–Rebuilds a deeply nested dictionary from flattened keys.
camel_to_snake
¶
camel_to_snake(name: str) -> str
Converts CamelCase to snake_case.
Parameters:
-
(name¶str) –The CamelCase string to convert
Returns:
-
str–The converted snake_case string
Source code in src/fpga_profile_reco/utils/helpers.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
flatten_dict
¶
flatten_dict(d: dict, parent_key: str = '', sep='/') -> dict
Recursively flattens a nested dictionary using a separator for keys. Used to make it suitable to be saved as npz files.
Parameters:
-
(d¶dict) –The dictionary to flatten
-
(parent_key¶str, default:'') –The parent key to be used in the flattened dictionary
-
(sep¶str, default:'/') –The separator to be used between keys
Returns:
-
items(dict) –The flattened dictionary
Source code in src/fpga_profile_reco/utils/helpers.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
format_time
¶
format_time(elapsed: int | float) -> str
Formats elapsed time in seconds to a string in hh:mm:ss format.
Parameters:
-
(elapsed¶int or float) –The elapsed time in seconds to format
Returns:
-
str–The formatted time string in hh:mm:ss format
Source code in src/fpga_profile_reco/utils/helpers.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
parse_numbers
¶
parse_numbers(value: str) -> list[int]
Parses a mix of single numbers and ranges (e.g., '1,3:5,7' → [1, 3, 4, 5, 7])
Parameters:
-
(value¶str) –The string containing the numbers and ranges
Returns:
-
numbers(list) –The list of specified numbers
Source code in src/fpga_profile_reco/utils/helpers.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
unflatten_dict
¶
Rebuilds a deeply nested dictionary from flattened keys. Used to restore the original structure of a dictionary saved as npz file.
Parameters:
Returns:
-
nested_dict(dict) –The nested dictionary
Source code in src/fpga_profile_reco/utils/helpers.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |