Exemple #1
0
        public void TimesRecommendedPropertyOk()
        {
            clsMostRecommendedFilms aMostRecommendedFilm = new clsMostRecommendedFilms();
            Int32 timesRecommended = 1974;

            aMostRecommendedFilm.TimesRecommended = timesRecommended;
            Assert.AreEqual(aMostRecommendedFilm.TimesRecommended, timesRecommended);
        }
Exemple #2
0
        public void FilmIdPropertyOk()
        {
            clsMostRecommendedFilms aMostRecommendedFilm = new clsMostRecommendedFilms();
            Int32 filmId = 2459;

            aMostRecommendedFilm.FilmId = filmId;
            Assert.AreEqual(aMostRecommendedFilm.FilmId, filmId);
        }
Exemple #3
0
        public void FindMethodOk()
        {
            bool found;
            clsMostRecommendedFilms aMostRecommendedFilm = new clsMostRecommendedFilms();
            Int32 filmId = 1;

            found = aMostRecommendedFilm.Find(filmId);
            Assert.IsTrue(found);
        }
        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);
        }
Exemple #8
0
        public void CompareToMethodNewTimesRecommendedLowerOk()
        {
            clsMostRecommendedFilms aMostRecommendedFilm = new clsMostRecommendedFilms();

            aMostRecommendedFilm.TimesRecommended = 2012;

            clsMostRecommendedFilms aSecondMostRecommendedFilm = new clsMostRecommendedFilms();

            aSecondMostRecommendedFilm.TimesRecommended = 1994;

            Int32 result = aMostRecommendedFilm.CompareTo(aSecondMostRecommendedFilm);

            Assert.AreEqual(result, -1);
        }
        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);
        }
Exemple #10
0
        public void InstanceOk()
        {
            clsMostRecommendedFilms aMostRecommendedFilm = new clsMostRecommendedFilms();

            Assert.IsNotNull(aMostRecommendedFilm);
        }