public void InstanceOk()
        {
            clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new
                                                                        clsMostRecommendedFilmsCollection();

            Assert.IsNotNull(AllMostRecommendedFilms);
        }
        public void CountPropertyOk()
        {
            clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new
                                                                        clsMostRecommendedFilmsCollection();
            Int32 count = 10;

            AllMostRecommendedFilms.Count = count;
            Assert.AreEqual(AllMostRecommendedFilms.Count, count);
        }
        void GetMostRecommendedFilms()
        {
            clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new clsMostRecommendedFilmsCollection();

            foreach (clsMostRecommendedFilms aMostRecommendedFilm in AllMostRecommendedFilms.AllMostRecommendedFilms)
            {
                pnlMostRecommendedFilms.Controls.Add(anImdbApi.GetImdbInformationWithOptions(aMostRecommendedFilm.FilmId, "", 0, favourite, displayOverlay));
            }
            pnlMostRecommendedFilms.Visible = true;
        }
        public void ThisMostRecommendedFilmOk()
        {
            clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new
                                                                        clsMostRecommendedFilmsCollection();
            clsMostRecommendedFilms TestItem = new clsMostRecommendedFilms();

            TestItem.FilmId           = 41569;
            TestItem.TimesRecommended = 2005;
            AllMostRecommendedFilms.ThisMostRecommendedFilm = TestItem;
            Assert.AreEqual(AllMostRecommendedFilms.ThisMostRecommendedFilm, TestItem);
        }
        public void AddMethodOk()
        {
            clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new
                                                                        clsMostRecommendedFilmsCollection();
            clsMostRecommendedFilms TestItem = new clsMostRecommendedFilms();

            TestItem.FilmId           = 174055;
            TestItem.TimesRecommended = 2017;
            AllMostRecommendedFilms.ThisMostRecommendedFilm = TestItem;
            AllMostRecommendedFilms.Add();
            AllMostRecommendedFilms.ThisMostRecommendedFilm.Find(TestItem.FilmId);
            Assert.AreEqual(AllMostRecommendedFilms.ThisMostRecommendedFilm, TestItem);
        }
        public void AllMostRecommendedFilmsOk()
        {
            clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new
                                                                        clsMostRecommendedFilmsCollection();
            List <clsMostRecommendedFilms> TestList = new List <clsMostRecommendedFilms>();
            clsMostRecommendedFilms        TestItem = new clsMostRecommendedFilms();

            TestItem.FilmId           = 1200;
            TestItem.TimesRecommended = 1986;
            TestList.Add(TestItem);
            AllMostRecommendedFilms.AllMostRecommendedFilms = TestList;
            Assert.AreEqual(AllMostRecommendedFilms.AllMostRecommendedFilms, TestList);
        }
        public void IncreaseTimesRecommendedOk()
        {
            clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new
                                                                        clsMostRecommendedFilmsCollection();
            clsMostRecommendedFilms TestItem = new clsMostRecommendedFilms();

            TestItem.FilmId = 41569;
            AllMostRecommendedFilms.ThisMostRecommendedFilm = TestItem;
            AllMostRecommendedFilms.IncreaseTimesRecommended();
            AllMostRecommendedFilms.ThisMostRecommendedFilm.Find(TestItem.FilmId);
            Int32 count = 0;

            Assert.AreEqual(AllMostRecommendedFilms.ThisMostRecommendedFilm.TimesRecommended, count);
        }
        void GenerateRecommendations(int genreId)
        {
            //create a new instance of the MLContext class
            MLContext mlContext = new MLContext();

            (IDataView trainingDataView, IDataView testDataView) = LoadData(mlContext);
            ITransformer model = BuildAndTrainModel(mlContext, trainingDataView);

            //create an instance of the class which represents the IDataView/ DataViewRow schema
            DataViewSchema modelSchema;

            //find the saved model
            var path = Server.MapPath(@"~/Model.zip");

            //load the saved model
            ITransformer trainedModel = mlContext.Model.Load(path,
                                                             out modelSchema);

            //create a prediction engine for film recommendations
            var predictionEngine = mlContext.Model.CreatePredictionEngine <clsFilmRating, MovieRatingPrediction>(trainedModel);

            var     tempUserId = Session["UserId"];
            Single  userId;
            Boolean signedIn = false;

            //check if user is signed in
            if (tempUserId == null)
            {
                userId = 1;
            }
            else
            {
                userId   = Convert.ToSingle(tempUserId);
                signedIn = true;
            }

            //get all films from the database
            clsFilmGenreCollection AllFilms = new clsFilmGenreCollection();

            AllFilms.GetAllFilmsByGenre(genreId);

            List <clsFilmPrediction> AllPredictions  = new List <clsFilmPrediction>();
            clsFilmPrediction        aFilmPrediction = new clsFilmPrediction();

            foreach (clsFilmGenre aFilm in AllFilms.AllFilmsByGenre)
            {
                var potentialRecommendation = new clsFilmRating {
                    UserId = userId, FilmId = aFilm.FilmId
                };
                var movieRatingPrediction = predictionEngine.Predict(potentialRecommendation);
                //if a rating is high enough, add it to film predictions
                if (Math.Round(movieRatingPrediction.Score, 1) > 4.4)
                {
                    aFilmPrediction        = new clsFilmPrediction();
                    aFilmPrediction.FilmId = aFilm.FilmId;
                    aFilmPrediction.Score  = movieRatingPrediction.Score;

                    AllPredictions.Add(aFilmPrediction);
                }
            }

            //sort them by score
            AllPredictions.Sort();

            //get the ten best recommendations
            var topTenPredictions = AllPredictions.Take(10);

            clsFilmRecommendationCollection FilmRecommendations  = new clsFilmRecommendationCollection();
            clsFilmRecommendation           aRecommendationToAdd = new clsFilmRecommendation();

            clsMostRecommendedFilmsCollection AllMostRecommendedFilms = new clsMostRecommendedFilmsCollection();
            clsMostRecommendedFilms           aMostRecommendedFilm    = new clsMostRecommendedFilms();

            foreach (clsFilmPrediction aTopTenPrediction in topTenPredictions)
            {
                if (signedIn)
                {
                    //save the recommendations for future use
                    aRecommendationToAdd        = new clsFilmRecommendation();
                    aRecommendationToAdd.FilmId = aTopTenPrediction.FilmId;
                    aRecommendationToAdd.UserId = Convert.ToInt32(userId);
                    FilmRecommendations.ThisFilmRecommendation = aRecommendationToAdd;
                    FilmRecommendations.Add();
                }

                aMostRecommendedFilm = new clsMostRecommendedFilms();
                AllMostRecommendedFilms.ThisMostRecommendedFilm.FilmId = aTopTenPrediction.FilmId;

                if (AllMostRecommendedFilms.ThisMostRecommendedFilm.Find(aTopTenPrediction.FilmId) == true)
                {
                    AllMostRecommendedFilms.IncreaseTimesRecommended();
                }
                else
                {
                    AllMostRecommendedFilms.Add();
                }
                //get imdb information for film
                pnlRecommendations.Controls.Add(anImdbApi.GetImdbInformation(aTopTenPrediction.FilmId));
            }
            pnlRecommendations.Visible = true;

            //save the model for later use
            mlContext.Model.Save(trainedModel, modelSchema, path);
        }