Esempio n. 1
0
        // ---------------------------------------------------------------------------------------------
        public DistractorDTO KickTheStudent(int userId, List <Pad> lastEmoStates)
        {
            //// TODO usunąć mock ***************************************************
            //Random rnd = new Random();
            //Func<EmoState> losuj = () => {
            //    var los = rnd.Next(1, 4);
            //    if (los == 1) return EmoState.BORED;
            //    if (los == 2) return EmoState.OK;
            //    if (los == 3) return EmoState.FRUSTRATED;
            //    return EmoState.UNDEFINED;
            //};
            //List<Pad> mockEmoStates = new List<Pad>(5);
            //string mocki = "";
            //for (int i = 0; i < 5; i++) {
            //    mockEmoStates.Add(new Pad("", losuj()));
            //    mocki += " " + i + ". " + mockEmoStates[mockEmoStates.Count() - 1].state.ToString();
            //}
            //lastEmoStates = mockEmoStates;
            //// ********************************************************************


            if (lastEmoStates.Count() < 5)
            {
                _logger.Debug("User: "******"|" + "Not providing a distractor as not enough (" + lastEmoStates.Count() + ") emotional states gathered yet");
                return(null);
            }

            EmoState emoStateNow = GetCurrentEmoState(lastEmoStates);



            // wybór DYSTRAKTORA ......................................................
            if (emoStateNow == EmoState.UNDEFINED || emoStateNow == EmoState.OK)
            {
                return(null);
            }

            DistractorType distrType;

            if (emoStateNow == EmoState.BORED)
            {
                distrType = DistractorType.KICK;
            }
            else
            {
                distrType = DistractorType.REWARD;
            }

            var distractor = _distractorService.NextDistractor(userId, distrType);


            // logging current emo-states
            string states = "";

            lastEmoStates.ForEach(delegate(Pad pad) { states += pad.state + ","; });
            _logger.Info("User: "******"|" + "Providing a \"" + distrType + "\" distractor for user with last emotional states: " + states);


            return(DistractorMapper.GetDTO(distractor));
        }
Esempio n. 2
0
        // ---------------------------------------------------------------------------------------------
        public ModuleAndDistractorDTO PrevModule(int userId, int currentModuleId)
        {
            user       user          = _userService.GetUserEntity(userId);
            distractor newDistractor = null;

            // pobranie listy modułów dotychczas wysłanych do tego użytkownika
            List <edumodule> prevModules = user.edumodule.ToList();

            ModuleService.SortGroupPosition(ref prevModules);

            // ustalenie pozycji aktualnego modułu na liście obejrzanych modułów
            int idx = prevModules.FindIndex(mod => mod.id == currentModuleId);

            if (idx > 0)
            {
                return new ModuleAndDistractorDTO()
                       {
                           module     = _moduleService.GetDTOWithQuestions(prevModules[idx - 1], userId),
                           distractor = newDistractor == null ? null : DistractorMapper.GetDTO(newDistractor)
                       }
            }
            ;

            return(null);
        }
Esempio n. 3
0
        // MOCK
        // =============================================================================================
        public DistractorDTO MockDistractor(int userId, DistractorType distrType)
        {
            // backing time of last use for all distractors of the user
            var userDistractors = _userService.GetUserEntity(userId).user_distractor.ToList();

            foreach (var ud in userDistractors)
            {
                ud.time_last_used = ud.time_last_used.AddMinutes(-10);
            }

            // picking next distractor of required type
            var distractor = NextDistractor(userId, distrType);

            return(DistractorMapper.GetDTO(distractor));
        }
Esempio n. 4
0
        // ---------------------------------------------------------------------------------------------
        public ModuleAndDistractorDTO NextModule(int userId, int currentModuleId, List <Pad> lastEmoStates)
        {
            edumodule  newModule;
            distractor newDistractor = null;
            user       user          = _userService.GetUserEntity(userId);


            // pobranie listy modułów dotychczas wysłanych do tego użytkownika
            List <edumodule> prevModules = user.edumodule.ToList();

            ModuleService.SortGroupPosition(ref prevModules);


            // jeśli kolejny moduł będzie wysłany po raz pierwszy - zostanie
            // dopisany do modułów tego użytkownika
            var addToUserModules = true;


            // To jest PIERWSZY moduł pobierany przez tego użytkownika
            if (prevModules.Count() == 0)
            {
                newModule = _moduleRepository.Get(1);
            }


            // To już nie pierwszy lecz KOLEJNY moduł
            else
            {
                var difficultyAndDistractor = PickNextDiffAndDistract(userId, lastEmoStates);

                // ustalenie pozycji aktualnego modułu na liście obejrzanych modułów
                int idx = prevModules.FindIndex(mod => mod.id == currentModuleId);


                // aktualnie użytkownik ogląda któryś z wczesniej pobranych
                // => pobranie następnego, który oglądał po aktualnym
                if (idx < prevModules.Count() - 1 && idx > -1)
                {
                    newModule        = prevModules[idx + 1];
                    addToUserModules = false;
                }

                // aktualnie użytkownik ogląda ostatni z pobranych =>
                // dostosowanie trudności do stanu emocjonalnego i dotychczasowych wyników użytkownika
                else
                {
                    var nextDifficulty = difficultyAndDistractor.Item1;
                    newModule = PickNextModule(currentModuleId, nextDifficulty, userId);
                }

                // pobranie następnego dystraktora (distractorService sprawdzi czy już można)
                var nextDistractorType = difficultyAndDistractor.Item2;
                newDistractor = _distractorService.NextDistractor(userId, nextDistractorType);
            }

            // zapisanie kolejnego modułu na liście wysłanych użytkownikowi
            // oraz zapamiętanie nowego ostatniego modułu użytkownika
            if (addToUserModules && newModule != null)
            {
                user.edumodule.Add(newModule);
                user.last_module = newModule.id;
                _userService.SaveChanges();
            }


            return(new ModuleAndDistractorDTO()
            {
                module = newModule == null ? null : _moduleService.GetDTOWithQuestions(newModule, userId),
                distractor = newDistractor == null ? null : DistractorMapper.GetDTO(newDistractor)
            });
        }