// GET: MonAn public ActionResult ChiTietMonAn(string id) { var model = MonAnQueries.FindFood(id); CartViewModel cart = (CartViewModel)Session[ConstantsVariable.CART]; List <MonAnViewModel> recommendedFoods = RecommendedFoodQueries.Loc_CollaborativeFiltering(cart, id, 4); ViewBag.RecommendedFoods = recommendedFoods; return(View(model)); }
public static List <MonAnViewModel> Loc_CollaborativeFiltering(CartViewModel cart, string idChoosenFood, int quantity_Recommended) { var dsDatKHChinh = GetChoosingFoods(cart); var bestCustomer = FindTheBestCollaborator(dsDatKHChinh, FindListHoaDon(idChoosenFood)); //Lay Ds rate bang duc lo Dictionary <string, double> R_result = new Dictionary <string, double>(); foreach (var item in dsDatKHChinh) { double sim; if (item.Quantity == 0) { sim = bestCustomer.FirstOrDefault(t => t.ID == item.ID).Quantity; } else { sim = item.Quantity; } R_result.Add(item.ID, sim); } //------------------------ var res = R_result.OrderByDescending(t => t.Value).Select(t => t.Key).ToList(); int indexChoosenFood = res.FindIndex(t => t == idChoosenFood); res.RemoveAt(indexChoosenFood); var collection = res.Take(quantity_Recommended).ToList(); List <MonAnViewModel> recommendedResult = new List <MonAnViewModel>(); if (collection.Count > 0) { foreach (var item in collection) { recommendedResult.Add(MonAnQueries.FindFood(item)); } } return(recommendedResult); }