Пример #1
0
        public ActionResult Recommendations()
        {
            var model = new RecommendationsModel(
                CurrentPage, Site.IsEnglish, false, Services.ContentService);

            return(CurrentTemplate(model));
        }
Пример #2
0
        public async Task <SpotifyRecommendations> GetRecommendationsAsync(RecommendationsModel criteria)
        {
            string endpoint = GetRecommendationUri(criteria);

            SpotifyRecommendations spotRecs = await GetFromSpotifyAsync <SpotifyRecommendations>(endpoint);

            return(spotRecs);
        }
Пример #3
0
        //index page, when it loads it passes the list of my recommendations to the view
        public IActionResult Index()
        {
            List <string> Recs = new List <string>();

            foreach (RecommendationsModel r in RecommendationsModel.GetRecs())
            {
                Recs.Add(string.Format("<div class='description'><h3>#{0}</h3><h4><u>{1}</u></h4><p><u>Drew's Favorite Dish</u>: {2}</p><p><u>Address</u>: {3}</p><p><u>Phone</u>: <a href='tel:{4}'>{4}</a></p>{5}</div><div class='img-container'><img class='img' src='img/{6}' alt='yummm'></div>", r.RecNo, r.RecName, r.RecFav, r.RecAddress, r.RecPhone, r.RecWeb, r.RecPhoto));
            }
            return(View(Recs));
        }
 private void setupRecommendations()
 {
     try
     {
         divRecommended.Visible = true;
         List <DvdInfo> dvdList = new RecommendationsModel().getRecommendations(user, 4);           //Throws NoRecordException()
         addTilesToRow(dvdList, recommened);
         if (dvdList.Count > 0)
         {
             divRecommended.Visible = true;
         }
         else
         {
             divRecommended.Visible = false;
         }
     }
     catch (NoRecordException)
     {
         divRecommended.Visible = false;
     }
 }
Пример #5
0
        private string GetRecommendationUri(RecommendationsModel recModel)
        {
            var criteria = recModel.criteria;
            var endpoint = new StringBuilder("recommendations");

            endpoint.Append($"?seed_artists={criteria.seed_artists}");
            endpoint.Append($"&seed_tracks={criteria.seed_tracks}");
            endpoint.Append($"&seed_genres={criteria.seed_genres}");
            endpoint.Append($"&limit={criteria.limit}");
            endpoint.Append($"&market={criteria.market}");

            endpoint.Append($"&target_danceability={criteria.target_danceability}");
            endpoint.Append($"&target_energy={criteria.target_energy}");
            endpoint.Append($"&target_popularity={criteria.target_popularity}");
            if (criteria.target_tempo > 0)
            {
                endpoint.Append($"&target_tempo={criteria.target_tempo}");
            }
            endpoint.Append($"&target_valence={criteria.target_valence}");

            return(endpoint.ToString());
        }
        public async Task <ActionResult> Index(RenderModel model)
        {
            var newRecSearch = new RecommendationsModel(model.Content, model.CurrentCulture);
            SearchCriteriaModel criteriaSpotify = GetCriteriaClass(model);

            newRecSearch.criteria.seed_tracks  = string.Join(",", criteriaSpotify.FavouriteTracks.Select(x => x.TrackID).ToList());
            newRecSearch.criteria.seed_artists = "";
            newRecSearch.criteria.market       = "SE";
            newRecSearch.criteria.limit        = 50;

            var query = Request.QueryString;

            if (query != null && query.Count > 0)
            {
                criteriaSpotify.target_popularity   = int.Parse(query["target_popularity"]);
                criteriaSpotify.target_danceability = Single.Parse(query["target_danceability"]);
                criteriaSpotify.target_energy       = Single.Parse(query["target_energy"]);
                criteriaSpotify.target_tempo        = int.Parse(query["target_tempo"]);
                criteriaSpotify.target_valence      = Single.Parse(query["target_valence"]);
                criteriaSpotify.seed_genres         = query["seed_genres"].ToString();
            }
            _mySession.CSession["SearchCriteriaModel"] = criteriaSpotify;

            newRecSearch.criteria.seed_genres         = criteriaSpotify.seed_genres;
            newRecSearch.criteria.target_popularity   = criteriaSpotify.target_popularity;
            newRecSearch.criteria.target_danceability = criteriaSpotify.target_danceability;
            newRecSearch.criteria.target_energy       = criteriaSpotify.target_energy;
            newRecSearch.criteria.target_tempo        = criteriaSpotify.target_tempo;
            newRecSearch.criteria.target_valence      = criteriaSpotify.target_valence;

            var recResults = await _spotService.GetRecommendationsAsync(newRecSearch);

            ViewBag.Recommendations = recResults;
            ViewBag.GenreList       = _spotService.genres;

            return(View("Recommendations", criteriaSpotify));
        }
        public RecommendationsModel Get()
        {
            string userId = GetUser();


            var points = Context.UsersPoints.Where(v => v.User.Id == userId)
                         .Select(s => new { s.ListeningPoints, s.WritingPoints, s.SpeakingPoints }).FirstOrDefault();

            if (userId == null || points == null)
            {
                var video = _videoModelBuilder.Build(Context.Videos.OrderBy(o => o.Level).ThenBy(o => o.Id).FirstOrDefault());
                return(new RecommendationsModel
                {
                    ListeningRecommendation = video,
                    WritingRecommendation = video,
                    SpeakingRecommendation = video
                });
            }

            Enums.Level listeningLevel = PointsLevel.GetLevel((int)points.ListeningPoints);
            Enums.Level writingLevel   = PointsLevel.GetLevel((int)points.WritingPoints);
            Enums.Level speakingLevel  = PointsLevel.GetLevel((int)points.SpeakingPoints);


            var videoForListening = (from a in Context.Videos.Where(l => l.Level >= (int)listeningLevel)
                                     join b in Context.UserProgress
                                     .Where(w => w.User.Id == userId)
                                     on a equals b.Video into joined
                                     from j in joined.DefaultIfEmpty().Where(v => v.ListeningModulePassed != true || v.ListeningModulePassed == null)
                                     select new VideoModel
            {
                Id = a.Id,
                Language = a.Language,
                Level = a.Level,
                Thumbnail = a.Thumbnail,
                Title = a.Title,
                Url = a.Url,
                ListeningModulePassed = j.ListeningModulePassed,
                WritingModulePassed = j.WritingModulePassed
            }).OrderBy(o => o.Level).ThenByDescending(o => o.WritingModulePassed).ThenBy(o => o.Id).FirstOrDefault();

            var videoForWriting = (from a in Context.Videos.Where(l => l.Level >= (int)writingLevel)
                                   join b in Context.UserProgress
                                   .Where(w => w.User.Id == userId)
                                   on a equals b.Video into joined
                                   from j in joined.DefaultIfEmpty().Where(v => v.WritingModulePassed != true || v.WritingModulePassed == null)
                                   select new VideoModel
            {
                Id = a.Id,
                Language = a.Language,
                Level = a.Level,
                Thumbnail = a.Thumbnail,
                Title = a.Title,
                Url = a.Url,
                ListeningModulePassed = j.ListeningModulePassed,
                WritingModulePassed = j.WritingModulePassed
            }).OrderBy(o => o.Level).ThenByDescending(o => o.ListeningModulePassed).ThenBy(o => o.Id).FirstOrDefault();


            var videoForSpeaking = (from a in Context.Videos.Where(l => l.Level >= (int)speakingLevel)
                                    join b in Context.UserProgress
                                    .Where(w => w.User.Id == userId)
                                    on a equals b.Video into joined
                                    from j in joined.DefaultIfEmpty().Where(v => v.SpeakingModulePassed != true || v.SpeakingModulePassed == null)
                                    select new VideoModel
            {
                Id = a.Id,
                Language = a.Language,
                Level = a.Level,
                Thumbnail = a.Thumbnail,
                Title = a.Title,
                Url = a.Url,
                ListeningModulePassed = j.ListeningModulePassed,
                WritingModulePassed = j.WritingModulePassed
            }).OrderBy(o => o.Level).ThenByDescending(o => o.ListeningModulePassed).ThenByDescending(o => o.WritingModulePassed).ThenBy(o => o.Id).FirstOrDefault();

            int arithmeticMean = ((int)points.ListeningPoints + (int)points.WritingPoints) / 2;

            Enums.Level level = PointsLevel.GetLevel(arithmeticMean);

            RecommendationsModel recommendations = new RecommendationsModel
            {
                ListeningRecommendation = videoForListening,
                WritingRecommendation   = videoForWriting,
                SpeakingRecommendation  = videoForSpeaking
            };



            return(recommendations);
        }
Пример #8
0
        private void setDvdTiles(String search)
        {
            String type = Request.QueryString["type"];

            dvdInfoService = new DvdInfoService();
            List <DvdInfo> dvdContent = null;

            String searchtext = "";

            if (Request.QueryString["search"] != null)
            {
                searchtext = Request.QueryString["search"];
            }

            String labelText   = "";
            String genre_id    = Request.QueryString["genre"];
            String category_id = Request.QueryString["cat"];

            String year     = Request.QueryString["year"];
            String director = Request.QueryString["director"];
            String actor    = Request.QueryString["actor"];
            String related  = Request.QueryString["related"];

            try
            {
                if (type != null)
                {
                    switch (type)
                    {
                    case "popular":
                        labelText  = "Most popular DVDs";
                        dvdContent = new DvdInfoService().getMostPopularDvds(16);               //Throws NoRecordException

                        break;

                    case "recommended":
                        if (Session["user"] != null)
                        {
                            labelText  = "Recommended for you";
                            dvdContent = new RecommendationsModel().getRecommendations(((Customer)Session["user"]), 16);              //Throws NoRecordException
                        }
                        break;

                    case "recent":
                        labelText  = "Recent releases";
                        dvdContent = new DvdInfoService().getLatestDvds(16);                    //Throws NoRecordException

                        break;
                    }
                }
                else if (genre_id != null)
                {
                    labelText  = new GenreService().getByID(genre_id).name + " DVDs";                       //Throws NoRecordException
                    dvdContent = dvdInfoService.searchDvdWithTextAndGenre(searchtext, genre_id);            //Throws NoRecordException
                }
                else if (category_id != null)
                {
                    labelText  = new CategoryService().getByID(category_id).name + " DVDs";                 //Throws NoRecordException
                    dvdContent = dvdInfoService.searchDvdWithTextAndCategory(searchtext, category_id);      //Throws NoRecordException
                }
                else if (year != null)
                {
                    labelText  = "Dvd's from " + year;
                    dvdContent = dvdInfoService.searchDvdFromYear(year);                                    //Throws NoRecordException
                }
                else if (director != null)
                {
                    labelText  = "Dvd's from " + director;
                    dvdContent = dvdInfoService.searchDvdFromDirector(director);                            //Throws NoRecordException
                }
                else if (actor != null)
                {
                    labelText  = "Dvd's with " + actor;
                    dvdContent = dvdInfoService.searchDvdWithActor(actor);                                   //Throws NoRecordException
                }
                else if (related != null)
                {
                    labelText  = "Related dvds for " + dvdInfoService.getByID(related).name;                //Throws NoRecordException
                    dvdContent = dvdInfoService.getRelatedDvds(related, 16);                                //Throws NoRecordException
                }
                else
                {
                    labelText  = "Catalog";
                    dvdContent = dvdInfoService.searchDvdWithText(searchtext);                              //Throws NoRecordException
                }

                //set header text
                if (!searchtext.Equals(""))
                {
                    labelText += " matching '" + searchtext + "'";
                }


                foreach (DvdInfo d in dvdContent)
                {
                    if (search != null && checkMatches(d, search))
                    {
                        dvdInfoUserControl dvdInfo = (dvdInfoUserControl)Page.LoadControl("dvdInfoUserControl.ascx");
                        dvdInfo.ChoiceComplete += new dvdInfoUserControl.delChoiceComplete(dvdInfo_ChoiceComplete);
                        dvdInfo.id              = d.dvd_info_id;
                        foreach (KeyValuePair <int, String> k in d.media)
                        {
                            if (k.Key == 1)
                            {
                                dvdInfo.imageUrl = k.Value;
                            }
                        }
                        dvdInfo.title      = d.name;
                        dvdInfo.buy_price  = d.buy_price;
                        dvdInfo.rent_price = d.rent_price;
                        catalogContent.Controls.Add(dvdInfo);
                    }
                    else if (search == null)
                    {
                        dvdInfoUserControl dvdInfo = (dvdInfoUserControl)Page.LoadControl("dvdInfoUserControl.ascx");
                        dvdInfo.ChoiceComplete += new dvdInfoUserControl.delChoiceComplete(dvdInfo_ChoiceComplete);
                        dvdInfo.id              = d.dvd_info_id;
                        foreach (KeyValuePair <int, String> k in d.media)
                        {
                            if (k.Key == 1)
                            {
                                dvdInfo.imageUrl = k.Value;
                            }
                        }
                        dvdInfo.title      = d.name;
                        dvdInfo.buy_price  = d.buy_price;
                        dvdInfo.rent_price = d.rent_price;
                        catalogContent.Controls.Add(dvdInfo);
                    }
                }
                lblHeader.Text = labelText;
            }
            catch (NoRecordException)
            {
                lblHeader.Text = labelText;
                lblStatus.Text = "Could not find any results matching your criteria.";
            }
        }