Skip to content

Commit

Permalink
Fix recommendation logic not to recommend the selected product (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
mviitane authored Oct 8, 2022
1 parent 0fdcad7 commit b27fa7d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/recommendationservice/recommendation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,25 @@ def Watch(self, request, context):
def get_product_list(request_product_ids):
with tracer.start_as_current_span("get_product_list") as span:
max_responses = 5
# fetch list of products from product catalog stub

# Formulate the list of characters to list of strings
request_product_ids_str = ''.join(request_product_ids)
request_product_ids = request_product_ids_str.split(',')

# Fetch list of products from product catalog stub
cat_response = product_catalog_stub.ListProducts(demo_pb2.Empty())
product_ids = [x.id for x in cat_response.products]
span.set_attribute("app.products.count", len(product_ids))

# Create a filtered list of products excluding the products received as input
filtered_products = list(set(product_ids) - set(request_product_ids))
num_products = len(filtered_products)
span.set_attribute("app.filtered_products.count", num_products)

num_return = min(max_responses, num_products)
# sample list of indicies to return

# Sample list of indicies to return
indices = random.sample(range(num_products), num_return)
# fetch product ids from indices
# Fetch product ids from indices
prod_list = [filtered_products[i] for i in indices]
return prod_list

Expand Down

0 comments on commit b27fa7d

Please sign in to comment.