Пример #1
0
        public void RecommendFilter()
        {
            Person p = PersonRepository.GetPersonByName("Ana");
            Filter f = new Filter();

            f.YearFrom = 2005;
            var res = Recommender.FilterResults(p.Profile.LikedMovies, f);

            Assert.AreEqual(0, res.Count());
        }
Пример #2
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));
        }