def test_raise_exception(self): token = TestConstants.REST_RECOMM_TOKEN decoded = decode(token, Constants.SECRET) customer_id = decoded['_id'] print(customer_id) #self.assertRaises(ValueError, final, customer_id, Reviews.all(token), Restaurants.all(token)) self.assertRaises(ValueError, final, {"_id": '1234'}, Reviews.all(token), Restaurants.all(token))
def test_recommendation_output(self): token = TestConstants.REST_RECOMM_TOKEN decoded = decode(token, Constants.SECRET) customer_id = decoded['_id'] restaurant_id = final(Customers.by_id(customer_id, token), Reviews.all(token), Restaurants.all(token)) print(restaurant_id) self.assertEqual(TestConstants.REST_RECOMM_OUTPUT, restaurant_id)
def main(customer_id, token): try: restaurants_id = final(Customers.by_id(customer_id, token), Reviews.all(token), Restaurants.all(token)) restaurants_data = map(lambda e: Restaurants.by_id(e, token), restaurants_id) except Exception as error: answer = dict({ Constants.SUCCESS: "false", Constants.ERROR: error.__str__() }) return answer answer = dict({ Constants.SUCCESS: "true", Constants.DATA: restaurants_data }) return answer
def main(customer_id, token): try: x = Customers.by_id(customer_id, token) if x is None: answer = dict({ Constants.SUCCESS: "false", Constants.ERROR: "This customer ain't around!" }) return answer restaurants = filter_res(Customers.by_id(customer_id, token), Reviews.all(token), token) except Exception as error: answer = dict({ Constants.SUCCESS: "false", Constants.ERROR: error.__str__() }) return answer answer = dict({Constants.SUCCESS: "true", Constants.DATA: restaurants}) return answer
return mean_dic def filter_res(customer, reviews, foods): fav_res = get_fav_res(customer, reviews) res_top = restaurant_top(reviews, fav_res) filtered_res = [] menu_fav = [] for food in foods: if food["restaurant_id"] == fav_res: menu_fav.append(food["name"]) for food in foods: if menu_fav.count(food["name"]) and res_top.count( food["restaurant_id"]): filtered_res.append(food["restaurant_id"]) res_dic = score_mean(reviews, list(set(filtered_res))) sorted_top = sorted(res_dic, key=lambda item: res_dic[item], reverse=True) for s in sorted_top: print(res_dic[s]) return sorted_top[0:9] result = filter_res(Customers.by_id('5e8d959a9220ac402a589b57'), Reviews.all(), Foods.all()) for r in result: print(Restaurant.by_id(r))