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.
@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
Required: match, near_match
customers
__SPLPY__OUTPORT_DESCRIPTION__SPLPY__
__SPLPY__OUTPORT_DESCRIPTION__SPLPY__
Required: match, near_match