PopulationFilter Library

Provides a convenient interface for creating population filters for GlobalAnalytics functions. PopulationFilters filter the population space before performing the analytic calculations.

PopulationFilter types

There are four different PopulationFilter types that are created with PopulationFilter Constructors:

  • NumericPopulationFilter
  • StringPopulationFilter
  • DatePopulationFilter
  • BooleanPopulationFilter

These filters can then be passed as parameters to relevant GlobalAnalytics functions directly or after the application of PopulationFilter Operators.

 

Unlike the Filter Library, an operating condition must be specified. A good workaround for this is to use the "not_equal_to" operator, as this will only return Populations which have used the tag, as long as the value is not equal to the one used in the filter.

 

In addition, multiple filters can be combined through the '&' operator to further constrain queries.

PopulationFilter operators

Below is a table of the available PopulationFilter Operators: 

Type  Available Operators 
All PopulationFilter types



equal_to
not_equal_to
& (logical AND operation)

NumericPopulationFilter and DatePopulationFilter




greater_than
greater_than_or_equal
less_than
less_than_or_equal

 

 

Import

To use this library and its functions, you must use the import line at the beginning of your Base Python code.

import PopulationFilter

 

Construct a NumericPopulationFilter 

PopulationFilter.numeric_tag(name)

Represents a tag with numeric values.

Credit cost: 0

Parameters

  • namestr|unicode Name of tag, including stream name (eg. "raw.score")

Return Value

NumericPopulationFilter

Example

  • import PopulationFilter
    
    # must be used with an operation condition, such as 'equal_to'
    num_tag = PopulationFilter.numeric_tag('raw.bpm')

Exceptions

None

Construct a StringPopulationFilter

PopulationFilter.string_tag(name)

Represents a tag with string values.

Credit cost: 0

Parameters

  • namestr|unicode Name of tag, including stream name (eg. "raw.city")

Return Value

StringPopulationFilter

Example

  • import PopulationFilter
    
    #  must be used with an operation condition, such as 'equal_to'
    str_tag = PopulationFilter.string_tag('raw.name')

Exceptions

None

Construct a DatePopulationFilter

PopulationFilter.date_tag(name)

Represents a tag with date values.

Credit cost: 0

Parameters

  • namestr|unicode Name of tag, including stream name (eg. "raw.birthday")

Return Value

DatePopulationFilter

Example

  • import PopulationFilter
    
    # must be used with an operation condition, such as 'equal_to'
    my_date = PopulationFilter.date_tag('raw.birthday')

 

Construct a BooleanPopulationFilter

PopulationFilter.boolean_tag(name)

Represents a tag with a boolean value.

Credit cost: 0

Parameters

  • namestr|unicode Name of tag, including stream name (eg. "raw.allowed_to_do_that")

Return Value

BooleanPopulationFilter

Example

  • import PopulationFilter
    
    # must be used with an operation condition, such as 'equal_to'
    bool_tag = PopulationFilter.boolean_tag('raw.friendly')

Exceptions

None

Assert equal to value

filter.equal_to(value)

Specifies that a tag (or boolean expression of tags) is equal to another value.

Credit cost: 0

Parameters

  • filter: NumericPopulationFilterStringPopulationFilterBooleanPopulationFilter, or DatePopulationFilter
  • value: value to match, must be same type as PopulationFilter instance. e.g. DateTime for DatePopulationFilter, true|false for BooleanPopulationFilter

Return Value

BooleanPopulationFilter

Example

import PopulationFilter

# asserts 'raw.bpm' == 120
PopulationFilter.numeric_tag('raw.bpm').equal_to(120)

Exceptions

None


Assert not equal to value

filter.not_equal_to(value)

Opposite of PopulationFilter.equal_to

Credit cost: 0

Parameters

  • filter: NumericPopulationFilterStringPopulationFilterBooleanPopulationFilter, or DatePopulationFilter
  • value: value to not match, must be same type as PopulationFilter instance. e.g. DateTime for DatePopulationFilter, true|false for BooleanPopulationFilter

Return Value

BooleanPopulationFilter

Example

  • import PopulationFilter
    
    # asserts 'raw.name' != "Joe"
    PopulationFilter.string_tag('raw.name').not_equal_to("Joe")

Exceptions

None

Combine filters

filter1 & filter2

Represents a boolean AND operation

Credit cost: 0

Parameters

  • filter1:  BooleanPopulationFilter
  • filter2:  BooleanPopulationFilter

Return Value

BooleanPopulationFilter

Example

  • import PopulationFilter
    
    # asserts 'age' > 20 and 'bpm' > 80
    age_filter = PopulationFilter.numeric_tag('age').greater_than(20)
    bpm_filter = PopulationFilter.numeric_tag('bpm').greater_than(80)
    comb_filter = age_filter & bpm_filter

Exceptions

None


Assert greater than value

filter.greater_than(value)

Asserts that a numeric tag is greater than the given value.

Credit cost: 0

Parameters

  • filter: NumericPopulationFilter or DatePopulationFilter
  • value:int|float|datetime value to be greater than

Return Value

BooleanPopulationFilter

Example

  • import PopulationFilter
    
    # asserts 'raw.bpm' > 120
    PopulationFilter.numeric_tag('raw.bpm').greater_than(12)

 

Assert greater than or equal to value

filter.greater_than_or_equal(value)

Asserts that a numeric tag is greater than or equal to the given value.

Credit cost: 0

Parameters

  • filter: NumericPopulationFilter or DatePopulationFilter
  • value:int|float|datetime value to be greater than or equal to

Return Value

BooleanPopulationFilter

Example

  • import PopulationFilter
    from datetime import datetime, timedelta
    # asserts 'reservation_data.check_out' is at or later than 4 days ago now = datetime.utcnow()
    min_check_out = now - timedelta(days = 4)
    PopulationFilter.date_tag("reservation_data.check_out").greater_than_or_equal(min_check_out)

Exceptions

None


Assert less than value

filter.less_than(value)

Asserts that a numeric tag is less than the given value.

Credit cost: 0

Parameters

  • filter: NumericPopulationFilter or DatePopulationFilter
  • value:int|float|datetime value to be less than

Return Value

BooleanPopulationFilter

Example

  • import PopulationFilter
    
    # asserts 'raw.bpm' < 200
    PopulationFilter.numeric_tag('raw.bpm').less_than(200)

 

Assert less than or equal to value

filter.less_than_or_equal(value)

Asserts that a numeric tag is less than or equal to the given value.

Credit cost: 0

Parameters

  • filter: NumericPopulationFilter or DatePopulationFilter
  • value:int|float|datetime value to be less than or equal to

Return Value

BooleanPopulationFilter

Example

  • import PopulationFilter
    
    # asserts 'raw.bpm' <= 200
    PopulationFilter.numeric_tag('raw.bpm').less_than_or_equal(200)

Exceptions

None