public async Task <IActionResult> Edit(int id, [Bind("ClusterResulterID,BookID,ClusterRes")] ClusterResulter clusterResulter) { if (id != clusterResulter.ClusterResulterID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(clusterResulter); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClusterResulterExists(clusterResulter.ClusterResulterID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(clusterResulter)); }
public async Task <IActionResult> Create([Bind("ClusterResulterID,BookID,ClusterRes")] ClusterResulter clusterResulter) { if (ModelState.IsValid) { _context.Add(clusterResulter); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(clusterResulter)); }
public JsonResult Related(int?id) { //for testing only!! //Clear DB before retrain //var rows = from o in _context.ClusterResulter // select o; //foreach (var row in rows) //{ // _context.ClusterResulter.Remove(row); //} //_context.SaveChanges(); //Getting The detaled book var book = _context.Books.Find(id); //(cach) Check if allready have previos prediction var clusterResult = _context.ClusterResulter .Where(b => b.BookID == id) .FirstOrDefault(); IQueryable <ClusterResulter> crs; if (clusterResult != null) { //create list of recomandation for join Recomandation crs = _context.ClusterResulter.Where(b => b.ClusterRes == clusterResult.ClusterRes); } else { //Create Dataset file from all the books Using BookService BookService bookService = new BookService(_context); bookService.ReconvertAllBooks(); //Clear DB before retrain var rows = from o in _context.ClusterResulter select o; foreach (var row in rows) { _context.ClusterResulter.Remove(row); } _context.SaveChanges(); //_context.ClusterResulter.RemoveRange(); //_context.SaveChanges(); //Train Modal BookClustering bc = new BookClustering(); //Get all Books var books = _context.Books.ToList();; //Predict for each Book and create DB ClusterResulter foreach (Book tmpBook in books) { //Preparing ClusterResulter for DB ClusterResulter cr = new ClusterResulter(); //ADding BookID to ClusterResulter cr.BookID = tmpBook.BookId; // Prepare BookItem as BookData (featuresSet) BookData bd = bookService.CreateBookData(tmpBook); //Train & Predict ClusterPrediction cp = bc.Predict(bd); cr.ClusterRes = Convert.ToInt32(cp.PredictedClusterId); //Save Result in DB _context.ClusterResulter.Add(cr); } _context.SaveChanges(); //Get Book Prediction Class ClusterPrediction cp_final = bc.Predict(bookService.CreateBookData(book)); int predId = Convert.ToInt32(cp_final.PredictedClusterId); //Get relevant predictions crs = _context.ClusterResulter .Where(b => b.ClusterRes == predId); } var recomended = from bk in _context.Books join cr in crs on bk.BookId equals cr.BookID where cr.BookID != id select new { Id = bk.BookId, Title = bk.Title, Quantity = bk.Quantity, URL = bk.ImageUrl, Result = cr.ClusterRes }; return(Json(recomended)); }