def describe(): product_name = request.values["product_name"].replace("_", " ") if product_name not in products: return nice_json({}) dic = df.loc[df['product_name'] == product_name].to_dict() for key, val in dic.items(): dic[key] = val[next(iter(val))] return nice_json(dic)
def similar_foods(): # product_name = request.form.get('product_name') calories = float(request.form.get('calories')) cholesterol = float(request.form.get('cholesterol')) carbohydrates = float(request.form.get('carbohydrates')) fat = float(request.form.get('fat')) fiber = float(request.form.get('fiber')) proteins = float(request.form.get('proteins')) # TODO Check if any parameter is None print(calories); print(carbohydrates); print (nutrition_values_df.head()) knn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree', metric="euclidean").fit(nutrition_values_df) distances, indices = knn.kneighbors([[(NUT_DAILY_VALUES["calories"] - calories) / NUT_DAILY_VALUES["calories"] , (NUT_DAILY_VALUES["carbohydrates"] - carbohydrates) / NUT_DAILY_VALUES["carbohydrates"] , (NUT_DAILY_VALUES["proteins"] - proteins) / NUT_DAILY_VALUES["proteins"] , (NUT_DAILY_VALUES["fat"] - fat) / NUT_DAILY_VALUES["fat"]]], #NUT_DAILY_VALUES["fiber"] - fiber, #NUT_DAILY_VALUES["cholesterol"] - cholesterol]], n_neighbors=3) recommended_products = [nutrition_df.loc[i]['product_name'] for i in indices[0]] response_dict = { "recommended": recommended_products } return nice_json(response_dict)
def hello(): return nice_json({ "uri": "/", "subresource_uris": { "showtimes": "/showtimes", "showtime": "/showtimes/<date>" } })
def hello(): return nice_json({ "uri": "/", "subresource_uris": { "movies": "/movies", "movie": "/movies/<id>" } })
def showtimes_record(date): if date not in showtimes: raise NotFound print(showtimes[date]) return nice_json(showtimes[date])
def showtimes_list(): return nice_json(showtimes)
def movie_record(): return nice_json(movies)
def movie_info(movieid): if movieid not in movies: raise NotFound result = movies[movieid] result["uri"] = "/movies/{}".format(movieid) return nice_json(result)