public static List <string> reccQuery(string topic, string familiar) { List <string> lessonlistid = new List <string>(); Search.Search s = new Search.Search(); var l1 = new Lesson(); var lList = l1.RetrieveAllLessons(); var reccList = s.reccQuery(lList, topic, familiar); for (var i = 0; i < reccList.Count; i++) { lessonlistid.Add(reccList[i].id); System.Diagnostics.Debug.WriteLine("id = " + reccList[i].id); } return(lessonlistid); }
protected void Page_Load(object sender, EventArgs e) { lesson = new List <Lesson>(); Lesson l1 = new Lesson(); user = new List <User>(); User u1 = new User(); var searchQS = ""; var filterQS = ""; var lvlQS = ""; var priceQS = ""; var ratingQS = ""; var categoryQS = ""; user = u1.Get4RandomTeachers(); try { searchQS = Request.QueryString["search"].ToString(); } catch { searchQS = null; } try { filterQS = Request.QueryString["filter"].ToString(); lvlQS = Request.QueryString["lvlFilter"].ToString(); priceQS = Request.QueryString["priceFilter"].ToString(); ratingQS = Request.QueryString["ratingFilter"].ToString(); //System.Diagnostics.Debug.WriteLine(categoryQS); } catch { filterQS = null; lvlQS = null; priceQS = null; ratingQS = null; } try { categoryQS = Request.QueryString["cate"].ToString(); System.Diagnostics.Debug.WriteLine(categoryQS); } catch { categoryQS = null; } if (searchQS == null) { headerText.Text = "Showing: Shop"; //System.Diagnostics.Debug.WriteLine("SEARCH IS NULL"); // if user didnt search anything, itll check if user is logged in // if user is logged in and has data saved for him, he will have his recc lessons shown else itll be random if (Session["id"] != null) { try { //Find the top 5 using machine learning MLContext mlContext = new MLContext(); (IDataView trainingDataView, IDataView testDataView) = LoadData(mlContext); ITransformer model = BuildAndTrainModel(mlContext, trainingDataView); EvaluateModel(mlContext, testDataView, model); //UseModelForSinglePrediction(mlContext, model); var top5recc = UseModelForBest5Prediction(mlContext, model); SaveModel(mlContext, trainingDataView.Schema, model); for (var i = 0; i < top5recc.Count; i++) { System.Diagnostics.Debug.WriteLine(top5recc[i].ToString()); l1 = l1.GetLessonById(top5recc[i].ToString()); var lesson_rating = (double.Parse(l1.rating_1) * 1 + double.Parse(l1.rating_2) * 2 + double.Parse(l1.rating_3) * 3 + double.Parse(l1.rating_4) * 4 + double.Parse(l1.rating_5) * 5) / (double.Parse(l1.rating_1) + double.Parse(l1.rating_2) + double.Parse(l1.rating_3) + double.Parse(l1.rating_4) + double.Parse(l1.rating_5)); lesson.Add(new Lesson() { title = l1.title, price = l1.price, image_url = l1.image_url, difficulty = l1.difficulty, duration = l1.duration, rating_1 = lesson_rating.ToString(), }); } } catch { List <int> lessonId = new List <int>(); l1 = new Lesson(); for (var j = 0; j < 8; j++) { //System.Diagnostics.Debug.WriteLine("Starting While Loop"); while (true) { int rando = RandomNumber(1, l1.GetLengthOfDB()); l1 = l1.GetLessonById(rando.ToString()); var lesson_rating = (double.Parse(l1.rating_1) * 1 + double.Parse(l1.rating_2) * 2 + double.Parse(l1.rating_3) * 3 + double.Parse(l1.rating_4) * 4 + double.Parse(l1.rating_5) * 5) / (double.Parse(l1.rating_1) + double.Parse(l1.rating_2) + double.Parse(l1.rating_3) + double.Parse(l1.rating_4) + double.Parse(l1.rating_5)); //System.Diagnostics.Debug.WriteLine("Random Number " + rando); if (lessonId.Contains(rando) == false) { //System.Diagnostics.Debug.WriteLine("Lesson contain" + lesson.Contains(l1)); lesson.Add(new Lesson() { title = l1.title, price = l1.price, image_url = l1.image_url, difficulty = l1.difficulty, duration = l1.duration, rating_1 = lesson_rating.ToString(), }); lessonId.Add(rando); break; } } } } } else if (filterQS != null || lvlQS != null || priceQS != null || ratingQS != null) { List <String> fQS = filterQS.Split(',').ToList(); List <String> levelQS = lvlQS.Split(',').ToList(); List <String> pQS = priceQS.Split(',').ToList(); List <String> rQS = ratingQS.Split(',').ToList(); List <String> rfQS = new List <String>(); for (var i = 0; i < fQS.Count; i++) { rfQS.Add(fQS[i].Replace("%", " ")); } Search.Search filterRet = new Search.Search(); Lesson tempLesson = new Lesson(); List <Lesson> lList = new List <Lesson>(); lList = tempLesson.RetrieveAllLessons(); for (var i = 0; i < lList.Count; i++) { System.Diagnostics.Debug.WriteLine("========= " + lList[i].id + " ========"); } lesson = filterRet.filterQuery(lList, rfQS, levelQS, pQS, rQS); } else if (categoryQS != null) { Search.Search categoryRet = new Search.Search(); Lesson tempLesson = new Lesson(); List <Lesson> lList = new List <Lesson>(); lList = tempLesson.RetrieveAllLessons(); System.Diagnostics.Debug.WriteLine("========= CATEGORY: " + categoryQS + " ========"); categoryQS = categoryQS.Replace("%", " "); categoryQS = categoryQS.Replace("AND", "&"); headerText.Text = categoryQS; lesson = categoryRet.retCategories(lList, categoryQS); } else { List <int> lessonId = new List <int>(); l1 = new Lesson(); for (var j = 0; j < 8; j++) { //System.Diagnostics.Debug.WriteLine("Starting While Loop"); while (true) { int rando = RandomNumber(1, l1.GetLengthOfDB()); l1 = l1.GetLessonById(rando.ToString()); System.Diagnostics.Debug.WriteLine("Random Number " + rando); if (lessonId.Contains(rando) == false) { System.Diagnostics.Debug.WriteLine("Lesson contain" + lesson.Contains(l1)); var lesson_rating = (double.Parse(l1.rating_1) * 1 + double.Parse(l1.rating_2) * 2 + double.Parse(l1.rating_3) * 3 + double.Parse(l1.rating_4) * 4 + double.Parse(l1.rating_5) * 5) / (double.Parse(l1.rating_1) + double.Parse(l1.rating_2) + double.Parse(l1.rating_3) + double.Parse(l1.rating_4) + double.Parse(l1.rating_5)); lesson.Add(new Lesson() { title = l1.title, price = l1.price, image_url = l1.image_url, difficulty = l1.difficulty, duration = l1.duration, rating_1 = lesson_rating.ToString(), }); lessonId.Add(rando); break; } } } } } else { var query = searchQS; //System.Diagnostics.Debug.WriteLine("SEARCH IS NOT NULL"); //System.Diagnostics.Debug.WriteLine(Session["search"]); headerText.Text = "Showing: " + query; Search.Search searchRet = new Search.Search(); Lesson tempLesson = new Lesson(); List <Lesson> lList = new List <Lesson>(); lList = tempLesson.RetrieveAllLessons(); for (var i = 0; i < lList.Count; i++) { System.Diagnostics.Debug.WriteLine("=========" + lList[i].id + "========"); } lesson = searchRet.searchQuery(lList, query); if (lesson.Count == 0) { notFoundLbl.Visible = true; } } }