afscgap.param
Description of request parameters to be used with any implementing backend.
(c) 2025 Regents of University of California / The Eric and Wendy Schmidt Center for Data Science and the Environment at UC Berkeley.
This file is part of afscgap released under the BSD 3-Clause License. See LICENSE.md.
1""" 2Description of request parameters to be used with any implementing backend. 3 4(c) 2025 Regents of University of California / The Eric and Wendy Schmidt Center 5for Data Science and the Environment at UC Berkeley. 6 7This file is part of afscgap released under the BSD 3-Clause License. See 8LICENSE.md. 9""" 10from afscgap.typesdef import OPT_FLOAT 11from afscgap.typesdef import OPT_INT 12from afscgap.typesdef import OPT_STR 13 14 15class Param: 16 """Interface for a backend-agnotic parameter.""" 17 18 def __init__(self): 19 """Create a new parameter.""" 20 raise NotImplementedError('Use implementor.') 21 22 def get_is_ignorable(self) -> bool: 23 """Determine if this parameter can be ignored during filtering operations. 24 25 Returns: 26 True if ignorable and false otherwise. 27 """ 28 raise NotImplementedError('Use implementor.') 29 30 def get_data_type(self) -> str: 31 """Get the data type of field on which this parameter operates. 32 33 Returns: 34 Data type of the field like "str". 35 """ 36 raise NotImplementedError('Use implementor.') 37 38 def get_filter_type(self) -> str: 39 """Get the type of filter being applied by this parameter. 40 41 Returns: 42 Get the type of filter like "equals" being applied. 43 """ 44 raise NotImplementedError('Use implementor.') 45 46 47class FieldParam: 48 """Parameter which operates on a specific field.""" 49 50 def __init__(self, field: str, param: Param): 51 """Create a new field-specific parameter.""" 52 self._field = field 53 self._param = param 54 55 def get_field(self) -> str: 56 """Get the name of the field on which this parameter operates. 57 58 Returns: 59 Name of the field on which this parameter operates. 60 """ 61 return self._field 62 63 def get_param(self) -> Param: 64 """Get the parameter to apply to this field. 65 66 Returns: 67 Object describing the parameter to apply to this field. 68 """ 69 return self._param 70 71 72class EmptyParam(Param): 73 """Parameter indicating that all records should be included.""" 74 75 def __init__(self): 76 """Create a parameter which matches all records.""" 77 pass 78 79 def get_is_ignorable(self) -> bool: 80 return True 81 82 def get_data_type(self) -> str: 83 return 'None' 84 85 def get_filter_type(self) -> str: 86 return 'empty' 87 88 89class StrEqualsParam(Param): 90 """Parameter which requires a field to have a specific string value.""" 91 92 def __init__(self, value: str): 93 """Create a new string equals parameter. 94 95 Args: 96 value: The string value that the field must have in order for its parent record to be 97 included in the results set. 98 """ 99 self._value = value 100 101 def get_value(self) -> str: 102 """Get the value that needs to be matched. 103 104 Returns: 105 String value that must be matched in order ofr a record to be included. 106 """ 107 return self._value 108 109 def get_is_ignorable(self) -> bool: 110 return False 111 112 def get_data_type(self) -> str: 113 return 'str' 114 115 def get_filter_type(self) -> str: 116 return 'equals' 117 118 119class StrRangeParam(Param): 120 """Parameter which requires a field to fall within an alphanumeric range.""" 121 122 def __init__(self, low: OPT_STR, high: OPT_STR): 123 """Create a new string range parameter. 124 125 Args: 126 low: The minimum value that a field may have for its record to be included or None if 127 no minimum to be enforced. 128 high: The maximum value that a field may have for its record to be incldued or None if 129 no maximum to be enforced. 130 """ 131 self._low = low 132 self._high = high 133 134 def get_low(self) -> OPT_STR: 135 """Get the minimum allowed value. 136 137 Returns: 138 The minimum value that a field may have for its record to be included or None if no 139 minimum to be enforced. 140 """ 141 return self._low 142 143 def get_high(self) -> OPT_STR: 144 """Get the maximum allowed value. 145 146 Returns: 147 The maximum value that a field may have for its record to be incldued or None if no 148 maximum to be enforced. 149 """ 150 return self._high 151 152 def get_is_ignorable(self) -> bool: 153 return False 154 155 def get_data_type(self) -> str: 156 return 'str' 157 158 def get_filter_type(self) -> str: 159 return 'range' 160 161 162class IntEqualsParam(Param): 163 """Parameter which requires a field to have a specific integer value.""" 164 165 def __init__(self, value: int): 166 """Create a new int equals parameter. 167 168 Args: 169 value: The int value that the field must have in order for its parent record to be 170 included in the results set. 171 """ 172 self._value = value 173 174 def get_value(self) -> int: 175 """Get the value that needs to be matched. 176 177 Returns: 178 Integer value that must be matched in order ofr a record to be included. 179 """ 180 return self._value 181 182 def get_is_ignorable(self) -> bool: 183 return False 184 185 def get_data_type(self) -> str: 186 return 'int' 187 188 def get_filter_type(self) -> str: 189 return 'equals' 190 191 192class IntRangeParam(Param): 193 """Parameter which requires a field to fall within an range defined by up to two integers.""" 194 195 def __init__(self, low: OPT_INT, high: OPT_INT): 196 """Create a new integer range parameter. 197 198 Args: 199 low: The minimum value that a field may have for its record to be included or None if 200 no minimum to be enforced. 201 high: The maximum value that a field may have for its record to be incldued or None if 202 no maximum to be enforced. 203 """ 204 self._low = low 205 self._high = high 206 207 def get_low(self) -> OPT_INT: 208 """Get the minimum allowed value. 209 210 Returns: 211 The minimum value that a field may have for its record to be included or None if no 212 minimum to be enforced. 213 """ 214 return self._low 215 216 def get_high(self) -> OPT_INT: 217 """Get the maximum allowed value. 218 219 Returns: 220 The maximum value that a field may have for its record to be incldued or None if no 221 maximum to be enforced. 222 """ 223 return self._high 224 225 def get_is_ignorable(self) -> bool: 226 return False 227 228 def get_data_type(self) -> str: 229 return 'int' 230 231 def get_filter_type(self) -> str: 232 return 'range' 233 234 235class FloatEqualsParam(Param): 236 """Parameter which requires a field to have a specific floating point value.""" 237 238 def __init__(self, value: float): 239 """Create a new float equals parameter. 240 241 Args: 242 value: The float value that the field must have in order for its parent record to be 243 included in the results set. 244 """ 245 self._value = value 246 247 def get_value(self) -> float: 248 """Get the value that needs to be matched. 249 250 Returns: 251 Float value that must be matched in order ofr a record to be included. 252 """ 253 return self._value 254 255 def get_is_ignorable(self) -> bool: 256 return False 257 258 def get_data_type(self) -> str: 259 return 'float' 260 261 def get_filter_type(self) -> str: 262 return 'equals' 263 264 265class FloatRangeParam(Param): 266 """Parameter which requires a field to fall within an range defined by up to two floats.""" 267 268 def __init__(self, low: OPT_FLOAT, high: OPT_FLOAT): 269 """Create a new float range parameter. 270 271 Args: 272 low: The minimum value that a field may have for its record to be included or None if 273 no minimum to be enforced. 274 high: The maximum value that a field may have for its record to be incldued or None if 275 no maximum to be enforced. 276 """ 277 self._low = low 278 self._high = high 279 280 def get_low(self) -> OPT_FLOAT: 281 """Get the minimum allowed value. 282 283 Returns: 284 The minimum value that a field may have for its record to be included or None if no 285 minimum to be enforced. 286 """ 287 return self._low 288 289 def get_high(self) -> OPT_FLOAT: 290 """Get the maximum allowed value. 291 292 Returns: 293 The maximum value that a field may have for its record to be incldued or None if no 294 maximum to be enforced. 295 """ 296 return self._high 297 298 def get_is_ignorable(self) -> bool: 299 return False 300 301 def get_data_type(self) -> str: 302 return 'float' 303 304 def get_filter_type(self) -> str: 305 return 'range'
16class Param: 17 """Interface for a backend-agnotic parameter.""" 18 19 def __init__(self): 20 """Create a new parameter.""" 21 raise NotImplementedError('Use implementor.') 22 23 def get_is_ignorable(self) -> bool: 24 """Determine if this parameter can be ignored during filtering operations. 25 26 Returns: 27 True if ignorable and false otherwise. 28 """ 29 raise NotImplementedError('Use implementor.') 30 31 def get_data_type(self) -> str: 32 """Get the data type of field on which this parameter operates. 33 34 Returns: 35 Data type of the field like "str". 36 """ 37 raise NotImplementedError('Use implementor.') 38 39 def get_filter_type(self) -> str: 40 """Get the type of filter being applied by this parameter. 41 42 Returns: 43 Get the type of filter like "equals" being applied. 44 """ 45 raise NotImplementedError('Use implementor.')
Interface for a backend-agnotic parameter.
19 def __init__(self): 20 """Create a new parameter.""" 21 raise NotImplementedError('Use implementor.')
Create a new parameter.
23 def get_is_ignorable(self) -> bool: 24 """Determine if this parameter can be ignored during filtering operations. 25 26 Returns: 27 True if ignorable and false otherwise. 28 """ 29 raise NotImplementedError('Use implementor.')
Determine if this parameter can be ignored during filtering operations.
Returns:
True if ignorable and false otherwise.
31 def get_data_type(self) -> str: 32 """Get the data type of field on which this parameter operates. 33 34 Returns: 35 Data type of the field like "str". 36 """ 37 raise NotImplementedError('Use implementor.')
Get the data type of field on which this parameter operates.
Returns:
Data type of the field like "str".
39 def get_filter_type(self) -> str: 40 """Get the type of filter being applied by this parameter. 41 42 Returns: 43 Get the type of filter like "equals" being applied. 44 """ 45 raise NotImplementedError('Use implementor.')
Get the type of filter being applied by this parameter.
Returns:
Get the type of filter like "equals" being applied.
48class FieldParam: 49 """Parameter which operates on a specific field.""" 50 51 def __init__(self, field: str, param: Param): 52 """Create a new field-specific parameter.""" 53 self._field = field 54 self._param = param 55 56 def get_field(self) -> str: 57 """Get the name of the field on which this parameter operates. 58 59 Returns: 60 Name of the field on which this parameter operates. 61 """ 62 return self._field 63 64 def get_param(self) -> Param: 65 """Get the parameter to apply to this field. 66 67 Returns: 68 Object describing the parameter to apply to this field. 69 """ 70 return self._param
Parameter which operates on a specific field.
51 def __init__(self, field: str, param: Param): 52 """Create a new field-specific parameter.""" 53 self._field = field 54 self._param = param
Create a new field-specific parameter.
56 def get_field(self) -> str: 57 """Get the name of the field on which this parameter operates. 58 59 Returns: 60 Name of the field on which this parameter operates. 61 """ 62 return self._field
Get the name of the field on which this parameter operates.
Returns:
Name of the field on which this parameter operates.
73class EmptyParam(Param): 74 """Parameter indicating that all records should be included.""" 75 76 def __init__(self): 77 """Create a parameter which matches all records.""" 78 pass 79 80 def get_is_ignorable(self) -> bool: 81 return True 82 83 def get_data_type(self) -> str: 84 return 'None' 85 86 def get_filter_type(self) -> str: 87 return 'empty'
Parameter indicating that all records should be included.
Determine if this parameter can be ignored during filtering operations.
Returns:
True if ignorable and false otherwise.
90class StrEqualsParam(Param): 91 """Parameter which requires a field to have a specific string value.""" 92 93 def __init__(self, value: str): 94 """Create a new string equals parameter. 95 96 Args: 97 value: The string value that the field must have in order for its parent record to be 98 included in the results set. 99 """ 100 self._value = value 101 102 def get_value(self) -> str: 103 """Get the value that needs to be matched. 104 105 Returns: 106 String value that must be matched in order ofr a record to be included. 107 """ 108 return self._value 109 110 def get_is_ignorable(self) -> bool: 111 return False 112 113 def get_data_type(self) -> str: 114 return 'str' 115 116 def get_filter_type(self) -> str: 117 return 'equals'
Parameter which requires a field to have a specific string value.
93 def __init__(self, value: str): 94 """Create a new string equals parameter. 95 96 Args: 97 value: The string value that the field must have in order for its parent record to be 98 included in the results set. 99 """ 100 self._value = value
Create a new string equals parameter.
Arguments:
- value: The string value that the field must have in order for its parent record to be included in the results set.
102 def get_value(self) -> str: 103 """Get the value that needs to be matched. 104 105 Returns: 106 String value that must be matched in order ofr a record to be included. 107 """ 108 return self._value
Get the value that needs to be matched.
Returns:
String value that must be matched in order ofr a record to be included.
Determine if this parameter can be ignored during filtering operations.
Returns:
True if ignorable and false otherwise.
120class StrRangeParam(Param): 121 """Parameter which requires a field to fall within an alphanumeric range.""" 122 123 def __init__(self, low: OPT_STR, high: OPT_STR): 124 """Create a new string range parameter. 125 126 Args: 127 low: The minimum value that a field may have for its record to be included or None if 128 no minimum to be enforced. 129 high: The maximum value that a field may have for its record to be incldued or None if 130 no maximum to be enforced. 131 """ 132 self._low = low 133 self._high = high 134 135 def get_low(self) -> OPT_STR: 136 """Get the minimum allowed value. 137 138 Returns: 139 The minimum value that a field may have for its record to be included or None if no 140 minimum to be enforced. 141 """ 142 return self._low 143 144 def get_high(self) -> OPT_STR: 145 """Get the maximum allowed value. 146 147 Returns: 148 The maximum value that a field may have for its record to be incldued or None if no 149 maximum to be enforced. 150 """ 151 return self._high 152 153 def get_is_ignorable(self) -> bool: 154 return False 155 156 def get_data_type(self) -> str: 157 return 'str' 158 159 def get_filter_type(self) -> str: 160 return 'range'
Parameter which requires a field to fall within an alphanumeric range.
123 def __init__(self, low: OPT_STR, high: OPT_STR): 124 """Create a new string range parameter. 125 126 Args: 127 low: The minimum value that a field may have for its record to be included or None if 128 no minimum to be enforced. 129 high: The maximum value that a field may have for its record to be incldued or None if 130 no maximum to be enforced. 131 """ 132 self._low = low 133 self._high = high
Create a new string range parameter.
Arguments:
- low: The minimum value that a field may have for its record to be included or None if no minimum to be enforced.
- high: The maximum value that a field may have for its record to be incldued or None if no maximum to be enforced.
135 def get_low(self) -> OPT_STR: 136 """Get the minimum allowed value. 137 138 Returns: 139 The minimum value that a field may have for its record to be included or None if no 140 minimum to be enforced. 141 """ 142 return self._low
Get the minimum allowed value.
Returns:
The minimum value that a field may have for its record to be included or None if no minimum to be enforced.
144 def get_high(self) -> OPT_STR: 145 """Get the maximum allowed value. 146 147 Returns: 148 The maximum value that a field may have for its record to be incldued or None if no 149 maximum to be enforced. 150 """ 151 return self._high
Get the maximum allowed value.
Returns:
The maximum value that a field may have for its record to be incldued or None if no maximum to be enforced.
Determine if this parameter can be ignored during filtering operations.
Returns:
True if ignorable and false otherwise.
163class IntEqualsParam(Param): 164 """Parameter which requires a field to have a specific integer value.""" 165 166 def __init__(self, value: int): 167 """Create a new int equals parameter. 168 169 Args: 170 value: The int value that the field must have in order for its parent record to be 171 included in the results set. 172 """ 173 self._value = value 174 175 def get_value(self) -> int: 176 """Get the value that needs to be matched. 177 178 Returns: 179 Integer value that must be matched in order ofr a record to be included. 180 """ 181 return self._value 182 183 def get_is_ignorable(self) -> bool: 184 return False 185 186 def get_data_type(self) -> str: 187 return 'int' 188 189 def get_filter_type(self) -> str: 190 return 'equals'
Parameter which requires a field to have a specific integer value.
166 def __init__(self, value: int): 167 """Create a new int equals parameter. 168 169 Args: 170 value: The int value that the field must have in order for its parent record to be 171 included in the results set. 172 """ 173 self._value = value
Create a new int equals parameter.
Arguments:
- value: The int value that the field must have in order for its parent record to be included in the results set.
175 def get_value(self) -> int: 176 """Get the value that needs to be matched. 177 178 Returns: 179 Integer value that must be matched in order ofr a record to be included. 180 """ 181 return self._value
Get the value that needs to be matched.
Returns:
Integer value that must be matched in order ofr a record to be included.
Determine if this parameter can be ignored during filtering operations.
Returns:
True if ignorable and false otherwise.
193class IntRangeParam(Param): 194 """Parameter which requires a field to fall within an range defined by up to two integers.""" 195 196 def __init__(self, low: OPT_INT, high: OPT_INT): 197 """Create a new integer range parameter. 198 199 Args: 200 low: The minimum value that a field may have for its record to be included or None if 201 no minimum to be enforced. 202 high: The maximum value that a field may have for its record to be incldued or None if 203 no maximum to be enforced. 204 """ 205 self._low = low 206 self._high = high 207 208 def get_low(self) -> OPT_INT: 209 """Get the minimum allowed value. 210 211 Returns: 212 The minimum value that a field may have for its record to be included or None if no 213 minimum to be enforced. 214 """ 215 return self._low 216 217 def get_high(self) -> OPT_INT: 218 """Get the maximum allowed value. 219 220 Returns: 221 The maximum value that a field may have for its record to be incldued or None if no 222 maximum to be enforced. 223 """ 224 return self._high 225 226 def get_is_ignorable(self) -> bool: 227 return False 228 229 def get_data_type(self) -> str: 230 return 'int' 231 232 def get_filter_type(self) -> str: 233 return 'range'
Parameter which requires a field to fall within an range defined by up to two integers.
196 def __init__(self, low: OPT_INT, high: OPT_INT): 197 """Create a new integer range parameter. 198 199 Args: 200 low: The minimum value that a field may have for its record to be included or None if 201 no minimum to be enforced. 202 high: The maximum value that a field may have for its record to be incldued or None if 203 no maximum to be enforced. 204 """ 205 self._low = low 206 self._high = high
Create a new integer range parameter.
Arguments:
- low: The minimum value that a field may have for its record to be included or None if no minimum to be enforced.
- high: The maximum value that a field may have for its record to be incldued or None if no maximum to be enforced.
208 def get_low(self) -> OPT_INT: 209 """Get the minimum allowed value. 210 211 Returns: 212 The minimum value that a field may have for its record to be included or None if no 213 minimum to be enforced. 214 """ 215 return self._low
Get the minimum allowed value.
Returns:
The minimum value that a field may have for its record to be included or None if no minimum to be enforced.
217 def get_high(self) -> OPT_INT: 218 """Get the maximum allowed value. 219 220 Returns: 221 The maximum value that a field may have for its record to be incldued or None if no 222 maximum to be enforced. 223 """ 224 return self._high
Get the maximum allowed value.
Returns:
The maximum value that a field may have for its record to be incldued or None if no maximum to be enforced.
Determine if this parameter can be ignored during filtering operations.
Returns:
True if ignorable and false otherwise.
236class FloatEqualsParam(Param): 237 """Parameter which requires a field to have a specific floating point value.""" 238 239 def __init__(self, value: float): 240 """Create a new float equals parameter. 241 242 Args: 243 value: The float value that the field must have in order for its parent record to be 244 included in the results set. 245 """ 246 self._value = value 247 248 def get_value(self) -> float: 249 """Get the value that needs to be matched. 250 251 Returns: 252 Float value that must be matched in order ofr a record to be included. 253 """ 254 return self._value 255 256 def get_is_ignorable(self) -> bool: 257 return False 258 259 def get_data_type(self) -> str: 260 return 'float' 261 262 def get_filter_type(self) -> str: 263 return 'equals'
Parameter which requires a field to have a specific floating point value.
239 def __init__(self, value: float): 240 """Create a new float equals parameter. 241 242 Args: 243 value: The float value that the field must have in order for its parent record to be 244 included in the results set. 245 """ 246 self._value = value
Create a new float equals parameter.
Arguments:
- value: The float value that the field must have in order for its parent record to be included in the results set.
248 def get_value(self) -> float: 249 """Get the value that needs to be matched. 250 251 Returns: 252 Float value that must be matched in order ofr a record to be included. 253 """ 254 return self._value
Get the value that needs to be matched.
Returns:
Float value that must be matched in order ofr a record to be included.
Determine if this parameter can be ignored during filtering operations.
Returns:
True if ignorable and false otherwise.
266class FloatRangeParam(Param): 267 """Parameter which requires a field to fall within an range defined by up to two floats.""" 268 269 def __init__(self, low: OPT_FLOAT, high: OPT_FLOAT): 270 """Create a new float range parameter. 271 272 Args: 273 low: The minimum value that a field may have for its record to be included or None if 274 no minimum to be enforced. 275 high: The maximum value that a field may have for its record to be incldued or None if 276 no maximum to be enforced. 277 """ 278 self._low = low 279 self._high = high 280 281 def get_low(self) -> OPT_FLOAT: 282 """Get the minimum allowed value. 283 284 Returns: 285 The minimum value that a field may have for its record to be included or None if no 286 minimum to be enforced. 287 """ 288 return self._low 289 290 def get_high(self) -> OPT_FLOAT: 291 """Get the maximum allowed value. 292 293 Returns: 294 The maximum value that a field may have for its record to be incldued or None if no 295 maximum to be enforced. 296 """ 297 return self._high 298 299 def get_is_ignorable(self) -> bool: 300 return False 301 302 def get_data_type(self) -> str: 303 return 'float' 304 305 def get_filter_type(self) -> str: 306 return 'range'
Parameter which requires a field to fall within an range defined by up to two floats.
269 def __init__(self, low: OPT_FLOAT, high: OPT_FLOAT): 270 """Create a new float range parameter. 271 272 Args: 273 low: The minimum value that a field may have for its record to be included or None if 274 no minimum to be enforced. 275 high: The maximum value that a field may have for its record to be incldued or None if 276 no maximum to be enforced. 277 """ 278 self._low = low 279 self._high = high
Create a new float range parameter.
Arguments:
- low: The minimum value that a field may have for its record to be included or None if no minimum to be enforced.
- high: The maximum value that a field may have for its record to be incldued or None if no maximum to be enforced.
281 def get_low(self) -> OPT_FLOAT: 282 """Get the minimum allowed value. 283 284 Returns: 285 The minimum value that a field may have for its record to be included or None if no 286 minimum to be enforced. 287 """ 288 return self._low
Get the minimum allowed value.
Returns:
The minimum value that a field may have for its record to be included or None if no minimum to be enforced.
290 def get_high(self) -> OPT_FLOAT: 291 """Get the maximum allowed value. 292 293 Returns: 294 The maximum value that a field may have for its record to be incldued or None if no 295 maximum to be enforced. 296 """ 297 return self._high
Get the maximum allowed value.
Returns:
The maximum value that a field may have for its record to be incldued or None if no maximum to be enforced.
Determine if this parameter can be ignored during filtering operations.
Returns:
True if ignorable and false otherwise.