Operator SelectCustomers

# Operator `SelectCustomers`

Toolkits > com.ibm.streamsx.topology.pysamples 1.1.0 > com.ibm.streamsx.topology.pysamples.primitives > SelectCustomers

Score customers using a model. Customers that are a good match are submitted to port 0 ('MATCH') while customers that are a near match are submitted to port 1 ('NEAR_MATCH').

Customers that are not a good or near match are not submitted to any port.

## Python

    @spl.primitive(output_ports=['MATCH', 'NEAR_MATCH'])
    class SelectCustomers(spl.PrimitiveOperator):
        """Score customers using a model.
        Customers that are a good match are submitted to port 0 ('MATCH')
        while customers that are a near match are submitted to port 1 ('NEAR_MATCH').

        Customers that are not a good or near match are not submitted to any port.
        """
        def __init__(self, match, near_match):
            self.match = match
            self.near_match = near_match

        @spl.input_port()
        def customers(self, **tuple_):
            customer_score = self.score(tuple_)
            if customer_score >= self.match:
                self.submit('MATCH', tuple_)
            elif customer_score >= self.near_match:
                self.submit('NEAR_MATCH', tuple_)

        def score(self, **customer):
            # Real scoring omitted
            score = random.random()
            return score

## Summary

Ports
  This operator has 1 input port and 2 output ports.
Windowing
  This operator does not accept any windowing configurations.
Parameters
  This operator supports 2 parameters.

  Required: match, near_match

Metrics
  This operator does not report any metrics.

## Properties

Implementation
  C++
Threading
  `Always` - Operator always provides a single threaded execution context.

Input Ports

Ports (0)

  customers

  Properties
    - Optional: false
    - ControlPort: false
    - TupleMutationAllowed: false
    - WindowingMode: NonWindowed
    - WindowPunctuationInputMode: Oblivious

Output Ports

Assignments
  This operator does not allow assignments to output attributes.

Ports (0)

  __SPLPY__OUTPORT_DESCRIPTION__SPLPY__

  Properties
    - Optional: false
    - TupleMutationAllowed: false
    - WindowPunctuationOutputMode: Free

Ports (1)

  __SPLPY__OUTPORT_DESCRIPTION__SPLPY__

  Properties
    - Optional: false
    - TupleMutationAllowed: false
    - WindowPunctuationOutputMode: Free

Parameters

This operator supports 2 parameters.

Required: match, near_match

`match`
  Properties
    - Type
    - Cardinality: 1
    - Optional: false
    - ExpressionMode: AttributeFree

`near_match`
  Properties
    - Type
    - Cardinality: 1
    - Optional: false
    - ExpressionMode: AttributeFree

Libraries

`SPLPY header`
  Include Path: `../../opt/.splpy/include`
`Python libraries.`
  Command: ../../opt/.splpy/common/pyversion3.sh