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 test_recommendation_output1(self): token = TestConstants.SEARCH_BY_REST_TOKEN decoded = decode(token, Constants.SECRET) customer_id = decoded['_id'] restaurant_prefix = "Ram" orders = Orders.all(token) reviews= Reviews.by_customer_id(customer_id, token) restaurants = Restaurants.all(token) self.assertEqual("5ebcf11126e32517c46effff", final(reviews, restaurants, orders, customer_id, restaurant_prefix, token)[0]["id"])
def main(customer_id, restaurant_prefix, token): try: restaurants_data = final(Reviews.by_customer_id(customer_id, token), Restaurants.all(token), Orders.all(token), customer_id, restaurant_prefix, token) 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: 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))
def setup_test_data(): dt1 = DealType.create(deal_type="HMO") dt2 = DealType.create(deal_type="Land Development") dt3 = DealType.create(deal_type="R2R - HMO") dt4 = DealType.create(deal_type="R2R - SA") dt5 = DealType.create(deal_type="Buy to let") dt6 = DealType.create(deal_type="Commercial to Residentual") dt7 = DealType.create(deal_type="Lease Option") dt8 = DealType.create(deal_type="Other") dt9 = DealType.create(deal_type="Apartment Block") faq1 = FAQ.create(question="Question A", answer="Answer AA" ) faq2 = FAQ.create(question="Question B", answer="Answer BB" ) faq3 = FAQ.create(question="Question C", answer="Answer CC" ) bedroom_not_applicable = Bedrooms.create(description="Not Applicable" ) bedroomstudio = Bedrooms.create(description="Studio" ) bedroom1 = Bedrooms.create(description="1 Bed" ) bedroom2 = Bedrooms.create(description="2 Bed" ) bedroom3 = Bedrooms.create(description="3 Bed" ) bedroom4 = Bedrooms.create(description="4 Bed" ) bedroom5 = Bedrooms.create(description="5 Bed" ) bedroom6 = Bedrooms.create(description="6 Bed" ) bedroom7 = Bedrooms.create(description="7 Bed" ) bedroom8 = Bedrooms.create(description="8 Bed" ) bedrooom_other = Bedrooms.create(description="More than 8" ) desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed metus bibendum enim semper tempor vitae et neque. Integer lobortis lacus tortor. Fusce finibus hendrerit nunc sed vehicula. Sed dapibus lectus nec imperdiet faucibus. Mauris aliquet arcu nec quam aliquam, quis pharetra ipsum dapibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam imperdiet ornare purus, vitae suscipit risus cursus ac. Etiam scelerisque imperdiet nibh, non condimentum nisl aliquam non. Donec quis nunc in diam convallis vulputate sed in purus. Aliquam venenatis ultrices imperdiet. Suspendisse consectetur leo id nisl consequat, in vestibulum tortor vehicula. Vestibulum eget elit condimentum, bibendum sem luctus, venenatis mi. Nam pellentesque molestie urna ut congue." inv1 = User.create(name="Richard", surname="Smit", telephone="07540388001", email="*****@*****.**" , password="******", activated=True, is_admin=True, disabled=False) inv2 = User.create(name="John", surname="Haagensen", telephone="07540388001", email="*****@*****.**" , password="******", activated=True, disabled=True) dl1 = Deal.create(description=desc, title='Cheap SA', created=datetime.datetime(2018, 6, 13, 00, 00), created_by=inv1, deal_type=dt1, sourcing_fee=2000, roi=10, document="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg" , county="Surrey", city="Shepperton", address_line_1="304 Laleham Road", address_line_2="laleham road", postcode='tw17 0jq', comparables = "xxxx", key_features = "Feature 1, Feature 2, Feature 3", show_address=True) dl2 = Deal.create(description=desc, title='2 Year D2V', created=datetime.datetime.now(), created_by=inv1, deal_type=dt2 , county="Berkshire", city="Reading") dl3 = Deal.create(description=desc, title='HMO D2V', created=datetime.datetime.now(), created_by=inv2, deal_type=dt2 , county="Berkshire", city="London") dq1 = DealQuestion.create(question="Is this D2V?", deal=dl1.uuid , asked_by=inv1.uuid) dqa1 = DealQuestionAnswer.create(answer="Yes it is", deal_question=dq1.uuid , answered_by=inv2.uuid) dq2 = DealQuestion.create(question="Can we view the property?", deal=dl1.uuid , asked_by=inv1.uuid) dqa2 = DealQuestionAnswer.create(answer="No", deal_question=dq2.uuid , answered_by=inv2.uuid) msg = Message.create(message_from=inv2, message_to=inv1, message="hello there" ) df = DealPhoto.create(filename="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg", deal=dl1.uuid ) df2 = DealPhoto.create(filename="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg", deal=dl1.uuid ) df3 = DealPhoto.create(filename="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg", deal=dl1.uuid ) df4 = DealPhoto.create(filename="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg", deal=dl1.uuid ) fav = Favourites.create(deal=dl1.uuid , user=inv1.uuid) rev1 = Reviews.create(stars=3, comment="test" , user=inv1.uuid) rev2 = Reviews.create(stars=5, comment="test", user=inv1.uuid) batch = BatchCSV.create(Filename="96249887-e751-4a1f-9b3d-05d5a24ecc46.csv" , Uploaded_By=inv1)