recommendationservice: exclude input ids

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-06-26 14:01:05 -07:00 committed by Simon Zeltser
parent 2041bdcb48
commit 9889e4904d

View file

@ -12,13 +12,17 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
# fetch list of products from product catalog stub
cat_response = stub.ListProducts(demo_pb2.Empty())
num_prodcuts = len(cat_response.products)
num_return = min(max_responses, num_prodcuts)
product_ids = [x.id for x in cat_response.products]
filtered_products = list(set(product_ids)-set(request.product_ids))
num_products = len(filtered_products)
num_return = min(max_responses, num_products)
# sample list of indicies to return
indices = random.sample(range(num_prodcuts), num_return)
indices = random.sample(range(num_products), num_return)
# fetch product ids from indices
prod_list = [cat_response.products[i].id for i in indices]
prod_list = [filtered_products[i] for i in indices]
print("handling request: {}".format(prod_list))
# build and return response