public void RatingPropertyOk()
        {
            clsFilmRating aFilmRating = new clsFilmRating();
            Single        rating      = 4.5F;

            aFilmRating.Rating = rating;
            Assert.AreEqual(aFilmRating.Rating, rating);
        }
        public void UserIdPropertyOk()
        {
            clsFilmRating aFilmRating = new clsFilmRating();
            Single        userId      = 1;

            aFilmRating.UserId = userId;
            Assert.AreEqual(aFilmRating.UserId, userId);
        }
        public void FilmIdPropertyOk()
        {
            clsFilmRating aFilmRating = new clsFilmRating();
            Single        filmId      = 1;

            aFilmRating.FilmId = filmId;
            Assert.AreEqual(aFilmRating.FilmId, filmId);
        }
        public void FindMethodOk()
        {
            clsFilmRating aFilmRating = new clsFilmRating();
            Boolean       found;
            Int32         filmId = 1;
            Int32         userId = 1;

            found = aFilmRating.Find(filmId, userId);
            Assert.IsTrue(found);
        }
Esempio n. 5
0
        public void ThisFilmRatingPropertyOk()
        {
            clsFilmRatingCollection AllFilmRatings = new clsFilmRatingCollection();
            clsFilmRating           TestFilmRating = new clsFilmRating();

            TestFilmRating.FilmId         = 2459;
            TestFilmRating.UserId         = 4;
            TestFilmRating.Rating         = 5;
            AllFilmRatings.ThisFilmRating = TestFilmRating;
            Assert.AreEqual(AllFilmRatings.ThisFilmRating, TestFilmRating);
        }
Esempio n. 6
0
        public void AddMethodOk()
        {
            clsFilmRatingCollection AllFilmRatings = new clsFilmRatingCollection();
            clsFilmRating           TestItem       = new clsFilmRating();

            TestItem.FilmId = 5;
            TestItem.UserId = 2;
            TestItem.Rating = 4.5F;
            AllFilmRatings.ThisFilmRating = TestItem;
            AllFilmRatings.Add();
            AllFilmRatings.ThisFilmRating.Find(TestItem.FilmId, TestItem.UserId);
            Assert.AreEqual(AllFilmRatings.ThisFilmRating, TestItem);
        }
Esempio n. 7
0
        public void CountMatchesList()
        {
            clsFilmRatingCollection FilmRatings = new clsFilmRatingCollection();
            List <clsFilmRating>    TestList    = new List <clsFilmRating>();
            clsFilmRating           TestItem    = new clsFilmRating();

            TestItem.FilmId = 1;
            TestItem.UserId = 1;
            TestItem.Rating = 5;
            TestList.Add(TestItem);
            FilmRatings.AllFilmRatings = TestList;
            Assert.AreEqual(FilmRatings.Count, TestList.Count);
        }
Esempio n. 8
0
        public void DeleteMethodOk()
        {
            clsFilmRatingCollection AllFilmRatings = new clsFilmRatingCollection();
            clsFilmRating           TestItem       = new clsFilmRating();

            TestItem.FilmId = 2459;
            TestItem.UserId = 2;
            TestItem.Rating = 5;
            AllFilmRatings.ThisFilmRating = TestItem;
            AllFilmRatings.Add();
            AllFilmRatings.ThisFilmRating.Find(TestItem.FilmId, TestItem.UserId);
            AllFilmRatings.Delete();
            Boolean found = AllFilmRatings.ThisFilmRating.Find(TestItem.FilmId, TestItem.UserId);

            Assert.IsFalse(found);
        }
Esempio n. 9
0
        public void UpdateMethodOk()
        {
            clsFilmRatingCollection AllFilmRatings = new clsFilmRatingCollection();
            clsFilmRating           testItem       = new clsFilmRating();
            Single filmId = 2;
            Single userId = 2;

            testItem.FilmId = filmId;
            testItem.UserId = userId;
            testItem.Rating = 4f;
            AllFilmRatings.ThisFilmRating = testItem;
            AllFilmRatings.Add();

            testItem.FilmId = filmId;
            testItem.UserId = userId;
            testItem.Rating = 5f;
            AllFilmRatings.ThisFilmRating = testItem;
            AllFilmRatings.Update();

            AllFilmRatings.ThisFilmRating.Find(filmId, userId);
            Assert.AreEqual(AllFilmRatings.ThisFilmRating, testItem);
        }
        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);
        }
        public void InstanceOk()
        {
            clsFilmRating aFilmRating = new clsFilmRating();

            Assert.IsNotNull(aFilmRating);
        }