예제 #1
0
 public void TestRecommendReturnsCorrectWorkouts()
 {
     for (var i = 0; i < 5; i++)
     {
         var workout = recommender.Recommend(4);
         Assert.IsNotNull(workout);
         bool isWorkout29or31 = (workout.id == 29 || workout.id == 31) ? true : false;
         Assert.AreEqual(true, isWorkout29or31, "Workout id was not 29 or 31");
     }
 }
예제 #2
0
 public ActionResult Index(int?page)
 {
     if (User.Identity.IsAuthenticated)
     {
         var person    = PersonRepository.GetPersonByEmail(User.Identity.Name, true);
         var movies    = new List <MovieViewModel>();
         var BLLmovies = new List <BLL.Movie>();
         #region Getting recommended movies here
         BLLmovies = Recommender.Recommend(person).ToList();
         //BLLmovies = MovieProvider.RecommendMovies();
         foreach (var BLLmovie in BLLmovies)
         {
             if (BLLmovie.Title == "" || BLLmovie.PosterPath == null || BLLmovie.PosterPath == "")
             {
                 continue;
             }
             var movie = new MovieViewModel();
             movie.CastSimpleFromMovie(BLLmovie);
             movies.Add(movie);
         }
         #endregion
         int pageSize   = 9;
         int pageNumber = (page ?? 1);
         return(View("HomeLoggedIn", movies.ToPagedList(pageNumber, pageSize)));
     }
     else
     {
         return(View());
     }
 }
예제 #3
0
        public void TestRecommender()
        {
            Recommender             recommender = buildRecommender();
            IList <RecommendedItem> recommended = recommender.Recommend("test1", 1);

            Assert.IsNotNull(recommended);
            Assert.AreEqual(1, recommended.Count);
            RecommendedItem firstRecommended = recommended[0];

            Assert.AreEqual(new GenericItem <String>("2"), firstRecommended.Item);
            Assert.AreEqual(0.3, firstRecommended.Value);
        }
예제 #4
0
            public Recommendations GetValue(Object key)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Retrieving new recommendations for user ID '" + key + '\'');
                }
                int count = maxHowMany.Value;
                IList <RecommendedItem> items            = recommender.Recommend(key, count);
                ReadOnlyCollection <RecommendedItem> roc = new ReadOnlyCollection <RecommendedItem>(items);

                return(new Recommendations(roc));
            }
예제 #5
0
        public void TestBestRating()
        {
            Recommender             recommender = buildRecommender();
            IList <RecommendedItem> recommended = recommender.Recommend("test1", 1);

            Assert.IsNotNull(recommended);
            Assert.AreEqual(1, recommended.Count);
            RecommendedItem firstRecommended = recommended[0];

            // item one should be recommended because it has a greater rating/score
            Assert.AreEqual(new GenericItem <String>("2"), firstRecommended.Item);
            Assert.AreEqual(0.3, firstRecommended.Value, EPSILON);
        }
예제 #6
0
        public ActionResult Login(Login login, string ReturnUrl = "")
        {
            using (db)
            {
                string hashedPassword = Hasher.HashPassword(login.Username, login.Password);
                var    user           = db.users.Where(a => a.username.Equals(login.Username) && a.password.Equals(hashedPassword)).FirstOrDefault();

                ModelState.Remove("Password");
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(user.username, login.RememberMe);

                    var     recommender    = new Recommender(this.db);
                    workout recommendation = recommender.Recommend(user.id);
                    if (Session != null && recommendation != null)
                    {
                        Session["recommendedId"] = recommendation.id;
                    }

                    if (user.is_admin == 1)
                    {
                        return(RedirectToAction("Index", "AdminHome"));
                    }
                    //ReturnUrl = Request.QueryString["ReturnURL"];

                    if (!string.IsNullOrEmpty(ReturnUrl) && Url.IsLocalUrl(ReturnUrl))
                    {
                        return(Redirect(ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "MyProfile"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            return(View());
        }
예제 #7
0
 /// <summary>
 /// Gets the recommended workout id from the session if it exists
 /// </summary>
 private void setRecommendedWorkout(int id)
 {
     if (Session != null)
     {
         workout recWorkout    = null;
         var     recommendedId = Session["recommendedId"];
         if (recommendedId != null)
         {
             recWorkout = db.workouts.Find(recommendedId);
             Session["recommendedId"] = recWorkout.id;
         }
         else if (id > 0)
         {
             var recommender = new Recommender(this.db);
             recWorkout = recommender.Recommend(id);
             if (recWorkout != null)
             {
                 Session["recommendedId"] = recWorkout.id;
             }
         }
         ViewBag.recommended = recWorkout;
     }
 }
예제 #8
0
        public ActionResult Recommend(bool Profile, bool Friends, bool Community, int SGenres,
                                      int Actors, int Directors, bool Gender, int MaxAgeDifference, int MinimalFriendsTogether,
                                      int MinimalMoviesTogether, bool GenderComm, int MaxAgeDifferenceComm,
                                      int MinimalFriendsTogetherComm, int MinimalMoviesTogetherComm, List <string> Genres,
                                      string FilterDirectors, string FilterActors, int YearFrom, int YearTo, string IMDBRatingFrom,
                                      string IMDBRatingTo, int TomatoRatingFrom, int TomatoRatingTo, int MetascoreRatingFrom,
                                      int MetascoreRatingTo, int FBSharesFrom, int FBSharesTo, int FBLikesFrom, int FBLikesTo,
                                      int RuntimeFrom, int RuntimeTo, bool Filter)
        {
            var person    = PersonRepository.GetPersonByEmail(User.Identity.Name, true);
            var recMovies = Recommender.Recommend(person, Profile, Friends, Community, SGenres, Actors, Directors, Gender, MaxAgeDifference, MinimalFriendsTogether, MinimalMoviesTogether, GenderComm, MaxAgeDifferenceComm, MinimalFriendsTogetherComm, MinimalMoviesTogetherComm);

            if (Filter)
            {
                if (Genres == null)
                {
                    Genres = new List <string>();
                }
                var filter = new BLL.Models.Filter(Genres);
                filter.Actors = new List <string>();
                if (FilterActors != null && FilterActors.Length > 0)
                {
                    string[] rawActors = FilterActors.Split(',');
                    foreach (string actor in rawActors)
                    {
                        string fixedActor = actor.Trim();
                        filter.Actors.Add(fixedActor);
                    }
                }

                if (FilterDirectors != null && FilterDirectors.Length > 0)
                {
                    filter.Directors = new List <string>();
                    string[] rawDirectors = FilterDirectors.Split(',');
                    foreach (string director in rawDirectors)
                    {
                        string fixedDirector = director.Trim();
                        filter.Directors.Add(fixedDirector);
                    }
                }

                if (RuntimeFrom == MinMaxConstants.RuntimeMin)
                {
                    filter.RuntimeFrom = null;
                }
                else
                {
                    filter.RuntimeFrom = RuntimeFrom;
                }

                if (RuntimeTo == MinMaxConstants.RuntimeMax)
                {
                    filter.RuntimeTo = null;
                }
                else
                {
                    filter.RuntimeTo = RuntimeTo;
                }

                if (FBLikesFrom == MinMaxConstants.FBLikesMin)
                {
                    filter.FBLikesFrom = null;
                }
                else
                {
                    filter.FBLikesFrom = FBLikesFrom;
                }

                if (FBLikesTo == MinMaxConstants.FBLikesMax)
                {
                    filter.FBLikesTo = null;
                }
                else
                {
                    filter.FBLikesTo = FBLikesTo;
                }

                if (FBSharesFrom == MinMaxConstants.FBSharesMin)
                {
                    filter.FBSharesFrom = null;
                }
                else
                {
                    filter.FBSharesFrom = FBSharesFrom;
                }

                if (FBSharesTo == MinMaxConstants.FBSharesMax)
                {
                    filter.FBSharesTo = null;
                }
                else
                {
                    filter.FBSharesTo = FBSharesTo;
                }

                if (IMDBRatingFrom == MinMaxConstants.IMDBRatingMin.ToString())
                {
                    filter.IMDBRatingFrom = null;
                }
                else
                {
                    filter.IMDBRatingFrom = Convert.ToDouble(IMDBRatingFrom);
                }

                if (IMDBRatingTo == MinMaxConstants.IMDBRatingMax.ToString())
                {
                    filter.IMDBRatingTo = null;
                }
                else
                {
                    filter.IMDBRatingTo = Convert.ToDouble(IMDBRatingTo);
                }

                if (MetascoreRatingFrom == MinMaxConstants.MetascoreMin)
                {
                    filter.MetascoreRatingFrom = null;
                }
                else
                {
                    filter.MetascoreRatingFrom = MetascoreRatingFrom;
                }

                if (MetascoreRatingTo == MinMaxConstants.MetascoreMax)
                {
                    filter.MetascoreRatingTo = null;
                }
                else
                {
                    filter.MetascoreRatingTo = MetascoreRatingTo;
                }

                if (TomatoRatingFrom == MinMaxConstants.TomatoMin)
                {
                    filter.TomatoRatingFrom = null;
                }
                else
                {
                    filter.TomatoRatingFrom = TomatoRatingFrom;
                }

                if (TomatoRatingTo == MinMaxConstants.TomatoMax)
                {
                    filter.TomatoRatingTo = null;
                }
                else
                {
                    filter.TomatoRatingTo = TomatoRatingTo;
                }

                if (YearFrom == MinMaxConstants.YearMin)
                {
                    filter.YearFrom = null;
                }
                else
                {
                    filter.YearFrom = YearFrom;
                }

                if (YearTo == MinMaxConstants.YearMax)
                {
                    filter.YearTo = null;
                }
                else
                {
                    filter.YearTo = YearTo;
                }
                recMovies = Recommender.FilterResults(recMovies, filter);
            }
            var movies = new List <SimpleMovieViewModel>();
            int i      = 1;
            int j      = 1;

            foreach (var recmovie in recMovies)
            {
                var movie = new SimpleMovieViewModel();
                movie.CastSimpleFromMovie(recmovie);
                if (j > 9)
                {
                    i++;
                    j = 1;
                }
                else
                {
                    j++;
                }
                movie.htmlClass = i.ToString();
                movies.Add(movie);
            }
            return(View("RecommendResults", movies));
        }
        public IRStatistics Evaluate(RecommenderBuilder recommenderBuilder,
                                     DataModel dataModel,
                                     int at,
                                     double relevanceThreshold,
                                     double evaluationPercentage)
        {
            if (recommenderBuilder == null)
            {
                throw new ArgumentNullException("recommenderBuilder is null");
            }
            if (dataModel == null)
            {
                throw new ArgumentNullException("dataModel is null");
            }
            if (at < 1)
            {
                throw new ArgumentException("at must be at least 1");
            }
            if (double.IsNaN(evaluationPercentage) || evaluationPercentage <= 0.0 || evaluationPercentage > 1.0)
            {
                throw new ArgumentException("Invalid evaluationPercentage: " + evaluationPercentage);
            }
            if (double.IsNaN(relevanceThreshold))
            {
                throw new ArgumentException("Invalid relevanceThreshold: " + evaluationPercentage);
            }

            RunningAverage precision = new FullRunningAverage();
            RunningAverage recall    = new FullRunningAverage();

            foreach (User user in dataModel.GetUsers())
            {
                Object id = user.ID;
                if (random.NextDouble() < evaluationPercentage)
                {
                    ICollection <Item> relevantItems = new HashedSet <Item>(/* at */);
                    Preference[]       prefs         = user.GetPreferencesAsArray();

                    foreach (Preference pref in prefs)
                    {
                        if (pref.Value >= relevanceThreshold)
                        {
                            relevantItems.Add(pref.Item);
                        }
                    }
                    int numRelevantItems = relevantItems.Count;
                    if (numRelevantItems > 0)
                    {
                        ICollection <User> trainingUsers = new List <User>(dataModel.GetNumUsers());
                        foreach (User user2 in dataModel.GetUsers())
                        {
                            if (id.Equals(user2.ID))
                            {
                                ICollection <Preference> trainingPrefs = new List <Preference>();
                                prefs = user2.GetPreferencesAsArray();
                                foreach (Preference pref in prefs)
                                {
                                    if (!relevantItems.Contains(pref.Item))
                                    {
                                        trainingPrefs.Add(pref);
                                    }
                                }
                                if (trainingPrefs.Count > 0)
                                {
                                    User trainingUser = new GenericUser <String>(id.ToString(), trainingPrefs);
                                    trainingUsers.Add(trainingUser);
                                }
                            }
                            else
                            {
                                trainingUsers.Add(user2);
                            }
                        }
                        DataModel   trainingModel = new GenericDataModel(trainingUsers);
                        Recommender recommender   = recommenderBuilder.BuildRecommender(trainingModel);

                        try
                        {
                            trainingModel.GetUser(id);
                        }
                        catch (NoSuchElementException)
                        {
                            continue;                             // Oops we excluded all prefs for the user -- just move on
                        }

                        int intersectionSize = 0;
                        foreach (RecommendedItem recommendedItem in recommender.Recommend(id, at))
                        {
                            if (relevantItems.Contains(recommendedItem.Item))
                            {
                                intersectionSize++;
                            }
                        }
                        precision.AddDatum((double)intersectionSize / (double)at);
                        recall.AddDatum((double)intersectionSize / (double)numRelevantItems);
                    }
                }
            }

            return(new IRStatisticsImpl(precision.Average, recall.Average));
        }