class ShowController(Controller): #----------------------------------------------------------------------- # Constructor #----------------------------------------------------------------------- def __init__(self): self.customers = Customers() self.showView = self.loadView("show") self.core = Core() #----------------------------------------------------------------------- # Methods #----------------------------------------------------------------------- """ @return All customers in database """ def getCustomers(self): data = self.customers.getAll() return data """ Opens EditController @param id_customer Customer id that will be edited """ def btnEdit(self, id_customer): customer = self.customers.get(id_customer) c = self.core.openController("edit") c.main(customer, self.showView) """ Deletes the chosen customer and updates the ShowView @param id_customer Customer id that will be edited """ def btnDel(self, id_customer): self.customers.delete(id_customer) self.showView.update() messagebox.showinfo("Delete customer", "Customer deleted with success!") """ @Override """ def main(self): self.showView.main()
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: 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
class EditController(Controller): #----------------------------------------------------------------------- # Constructor #----------------------------------------------------------------------- def __init__(self): self.editView = self.loadView("edit") self.customers = Customers() #----------------------------------------------------------------------- # Methods #----------------------------------------------------------------------- """ @Override """ def main(self, customer, showView): self.showView = showView self.customer = customer self.editView.main() """ @return Customer being edited """ def getCustomer(self): return self.customer """ Saves customer edited @param fields Customer data edited """ def btnSave(self, fields): response = self.customers.update(fields) self.showView.attributes("-topmost", False) if response > 0: messagebox.showinfo("Update customer", "Customer updated with success!") else: messagebox.showerror("Update customer", "Error while updating") self.showView.attributes("-topmost", True) self.showView.update() self.editView.close() self.showView.attributes("-topmost", False)
class AddController(Controller): #----------------------------------------------------------------------- # Constructor #----------------------------------------------------------------------- def __init__(self): self.addView = self.loadView("add") self.customers = Customers() #----------------------------------------------------------------------- # Methods #----------------------------------------------------------------------- """ Clear all fields of AddView @param fields Fields to be cleared """ def btn_clear(self, fields): for field in fields: field.delete(0, END) """ Adds a new customer with field data @param fields Fields with customer data """ def btn_add(self, fields): response = self.customers.add(fields) if response > 0: messagebox.showinfo("Add customer", "Customer successfully added!") else: messagebox.showerror("Add customer", "Error while adding customer") self.addView.close() """ @Override """ def main(self): self.addView.main()
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 __init__(self): self.customers = Customers() self.showView = self.loadView("showTree")
def __init__(self): self.addView = self.loadView("add") self.customers = Customers()
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 __init__(self): self.customers = Customers() self.showView = self.loadView("show") self.core = Core()
def __init__(self): self.editView = self.loadView("edit") self.customers = Customers()