示例#1
0
        public UserPointsModel Get()
        {
            var userId = GetUser();



            var userPoints = Context.UsersPoints.Where(a => a.User.Id == userId).FirstOrDefault();

            if (userId == null || userPoints == null)
            {
                return(new UserPointsModel
                {
                    MaxListeningPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(0)),
                    MaxSpeakingPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(0)),
                    MaxWritingPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(0)),
                    ProgressLevelPercentage = PointsLevel.GetProgress(0),
                    ListeningProgressPercentage = 0,
                    SpeakingProgressPercentage = 0,
                    WritingProgressPercentage = 0
                });
            }

            var avgPoints = (int)((userPoints.WritingPoints + userPoints.SpeakingPoints + userPoints.ListeningPoints) / 3);
            var userLevel = PointsLevel.GetLevel(avgPoints);

            return(new UserPointsModel
            {
                MaxListeningPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(userPoints.ListeningPoints ?? 0)),
                MaxSpeakingPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(userPoints.SpeakingPoints ?? 0)),
                MaxWritingPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(userPoints.WritingPoints ?? 0)),
                UserLevel = (int)userLevel,
                ProgressLevelPercentage = PointsLevel.GetProgress(avgPoints),
                ListeningProgressPercentage = PointsLevel.GetProgress(userPoints.ListeningPoints ?? 0),
                SpeakingProgressPercentage = PointsLevel.GetProgress(userPoints.SpeakingPoints ?? 0),
                WritingProgressPercentage = PointsLevel.GetProgress(userPoints.WritingPoints ?? 0)
            });



            //userPoints.ProgressLevelPercentage = (int)((avgPoints / (float)PointsLevel.GetMaxLevelPoints(userLevel)) * 100);
            //userPoints.MaxListeningPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(userPoints.ListeningPoints));
            //userPoints.MaxSpeakingPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(userPoints.SpeakingPoints));
            //userPoints.MaxWritingPoints = PointsLevel.GetMaxLevelPoints(PointsLevel.GetLevel(userPoints.WritingPoints));
            //userPoints.UserLevel = (int)userLevel;
            //return userPoints;
        }
示例#2
0
        public int GetUserLevel()
        {
            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)
            {
                return((int)Enums.Level.Elementary);
            }

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

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

            return((int)level);
        }
        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);
        }