Skip to content

omni.OmniFilterDefinition

Defines an Omni dashboard filter. Used to populate an OmniFilterSet and generate the filter search params for an embedded dashboard URL.

Parameters:

Name Type Description Default
field str

Name of the Omni field a filter exists for. Generally a dot-path representing a dimension in a view.

required
type Type

Type of the value to be filtered on.

required
operator Operator

Type of filter operation to perform.

equals

Attributes:

Name Type Description
field str

Name of the Omni field a filter exists for. Generally a dot-path representing a dimension in a view.

type Type

Type of the value to be filtered on.

operator Operator

Type of filter operation to perform.

Source code in src/omni/embed.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
@dataclass
class OmniFilterDefinition:
    """Defines an Omni dashboard filter. Used to populate an OmniFilterSet and generate the filter search params
    for an embedded dashboard URL.

    Args:
        field: Name of the Omni field a filter exists for. Generally a dot-path representing a dimension in a view.
        type: Type of the value to be filtered on.
        operator: Type of filter operation to perform.

    Attributes:
        field: Name of the Omni field a filter exists for. Generally a dot-path representing a dimension in a view.
        type: Type of the value to be filtered on.
        operator: Type of filter operation to perform.

    """

    class Type(Enum):
        """Omni Filter Type Options

        Attributes:
            number: number
            string: string
        """

        number = "number"
        string = "string"

    class Operator(Enum):
        """Omni Filter Operator Options

        Attributes:
            equals: EQUALS
            less_than: LESS_THAN
            greater_than: GREATER_THAN
            less_than_or_equal = LESS_THAN_OR_EQUAL
            greater_than_or_equal = GREATER_THAN_OR_EQUAL
            contains = CONTAINS
            between = BETWEEN
            starts_with = STARTS_WITH
            ends_with = ENDS_WITH
        """

        equals = "EQUALS"
        less_than = "LESS_THAN"
        greater_than = "GREATER_THAN"
        less_than_or_equal = "LESS_THAN_OR_EQUAL"
        greater_than_or_equal = "GREATER_THAN_OR_EQUAL"
        contains = "CONTAINS"
        between = "BETWEEN"
        starts_with = "STARTS_WITH"
        ends_with = "ENDS_WITH"

    field: str
    type: Type
    operator: Operator = Operator.equals
    is_negative: bool = False

    def get_filter_search_param_info(
        self, values: str | int | float | list[str | int | float]
    ) -> tuple[str, list[str]]:
        """Returns the key and value to be used in a query string for an Omni Dashboard.

        Args:
            values: Value or list of values to filter on.

        Returns:
            : Key and value to use in the filter search params when building an embedded dashboard URL.
        """
        if not isinstance(values, list):
            values = [values]
        filter_key = f"f--{self.field}"

        is_inclusive = False

        operator_kind = self.operator.value

        if self.operator == self.Operator.greater_than_or_equal:
            is_inclusive = True
            operator_kind = self.Operator.greater_than.value
        elif self.operator == self.Operator.less_than_or_equal:
            is_inclusive = True
            operator_kind = self.Operator.less_than.value

        filter_value_param = {
            "is_negative": self.is_negative,
            "kind": operator_kind,
            "type": self.type.value,
            "values": values,
        }

        if self.type == self.Type.number:
            filter_value_param["is_inclusive"] = is_inclusive

        filter_value = [json.dumps(filter_value_param)]
        return filter_key, filter_value

Operator

Bases: Enum

Omni Filter Operator Options

Attributes:

Name Type Description
equals

EQUALS

less_than

LESS_THAN

greater_than

GREATER_THAN

Source code in src/omni/embed.py
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
class Operator(Enum):
    """Omni Filter Operator Options

    Attributes:
        equals: EQUALS
        less_than: LESS_THAN
        greater_than: GREATER_THAN
        less_than_or_equal = LESS_THAN_OR_EQUAL
        greater_than_or_equal = GREATER_THAN_OR_EQUAL
        contains = CONTAINS
        between = BETWEEN
        starts_with = STARTS_WITH
        ends_with = ENDS_WITH
    """

    equals = "EQUALS"
    less_than = "LESS_THAN"
    greater_than = "GREATER_THAN"
    less_than_or_equal = "LESS_THAN_OR_EQUAL"
    greater_than_or_equal = "GREATER_THAN_OR_EQUAL"
    contains = "CONTAINS"
    between = "BETWEEN"
    starts_with = "STARTS_WITH"
    ends_with = "ENDS_WITH"

Type

Bases: Enum

Omni Filter Type Options

Attributes:

Name Type Description
number

number

string

string

Source code in src/omni/embed.py
236
237
238
239
240
241
242
243
244
245
class Type(Enum):
    """Omni Filter Type Options

    Attributes:
        number: number
        string: string
    """

    number = "number"
    string = "string"

get_filter_search_param_info(values)

Returns the key and value to be used in a query string for an Omni Dashboard.

Parameters:

Name Type Description Default
values str | int | float | list[str | int | float]

Value or list of values to filter on.

required

Returns:

Type Description
tuple[str, list[str]]

Key and value to use in the filter search params when building an embedded dashboard URL.

Source code in src/omni/embed.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
def get_filter_search_param_info(
    self, values: str | int | float | list[str | int | float]
) -> tuple[str, list[str]]:
    """Returns the key and value to be used in a query string for an Omni Dashboard.

    Args:
        values: Value or list of values to filter on.

    Returns:
        : Key and value to use in the filter search params when building an embedded dashboard URL.
    """
    if not isinstance(values, list):
        values = [values]
    filter_key = f"f--{self.field}"

    is_inclusive = False

    operator_kind = self.operator.value

    if self.operator == self.Operator.greater_than_or_equal:
        is_inclusive = True
        operator_kind = self.Operator.greater_than.value
    elif self.operator == self.Operator.less_than_or_equal:
        is_inclusive = True
        operator_kind = self.Operator.less_than.value

    filter_value_param = {
        "is_negative": self.is_negative,
        "kind": operator_kind,
        "type": self.type.value,
        "values": values,
    }

    if self.type == self.Type.number:
        filter_value_param["is_inclusive"] = is_inclusive

    filter_value = [json.dumps(filter_value_param)]
    return filter_key, filter_value