コード例 #1
0
        public void TestInsertLogLearnData()
        {
            var newData = new LogVocabularyScoreData();

            newData.AppSession    = GenericHelper.GetTimestampForNow();
            newData.Timestamp     = GenericHelper.GetTimestampForNow();
            newData.Stage         = 1;
            newData.LearningBlock = 1;
            newData.PlaySession   = 1;
            newData.MiniGameCode  = MiniGameCode.Assessment_LetterAny;

            newData.VocabularyDataType = RandomHelper.GetRandomEnum <VocabularyDataType>();

            switch (newData.VocabularyDataType)
            {
            case VocabularyDataType.Letter:
                newData.ElementId = RandomHelper.GetRandom(dbManager.GetAllLetterData()).GetId();
                break;

            case VocabularyDataType.Word:
                newData.ElementId = RandomHelper.GetRandom(dbManager.GetAllWordData()).GetId();
                break;

            case VocabularyDataType.Phrase:
                newData.ElementId = RandomHelper.GetRandom(dbManager.GetAllPhraseData()).GetId();
                break;
            }

            newData.Score = RND.Range(-1f, 1f);

            this.dbManager.Insert(newData);
            PrintOutput("Inserted new LogVocabularyScoreData: " + newData.ToString());
        }
コード例 #2
0
        public void LogLearn(int appSession, JourneyPosition pos, MiniGameCode miniGameCode, List <LearnResultParameters> resultsList)
        {
            var currentJourneyContents = AppManager.I.Teacher.VocabularyAi.CurrentJourneyContents;

            // No logging if we do not have contents (for example through a direct Play)
            if (currentJourneyContents == null)
            {
                return;
            }

            var learnRules = GetLearnRules(miniGameCode);

            // Retrieve previous scores
            string query = string.Format("SELECT * FROM " + typeof(VocabularyScoreData).Name);
            var    previousScoreDataList = db.Query <VocabularyScoreData>(query);

            // Prepare log data
            var logDataList   = new List <LogVocabularyScoreData>();
            var scoreDataList = new List <VocabularyScoreData>();

            foreach (var result in resultsList)
            {
                if (result.elementId == null)
                {
                    Debug.LogError("LogAI: Logging a result with a NULL elementId. Skipped.");
                    continue;
                }
                if (result.nCorrect == 0 && result.nWrong == 0)
                {
                    Debug.LogError("LogAI: Logging a result with no correct nor wrong hits. Skipped.");
                    continue;
                }

                float score        = 0f;
                float successRatio = result.nCorrect * 1f / (result.nCorrect + result.nWrong);
                switch (learnRules.voteLogic)
                {
                case MiniGameLearnRules.VoteLogic.Threshold:
                    // Uses a binary threshold
                    float threshold = learnRules.logicParameter;
                    score = successRatio > threshold ? 1f : -1f;
                    break;

                case MiniGameLearnRules.VoteLogic.SuccessRatio:
                    // Uses directly the success ratio to drive the vote
                    score = Mathf.InverseLerp(-1f, 1f, successRatio);
                    break;
                }
                score *= learnRules.minigameImportanceWeight;
                score += learnRules.minigameVoteSkewOffset;

                var logData = new LogVocabularyScoreData(appSession, pos, miniGameCode, result.dataType, result.elementId, score);
                logDataList.Add(logData);

                // We also update the score for that data element
                var scoreData = GetVocabularyScoreDataWithMovingAverage(result.dataType, result.elementId, score, previousScoreDataList, ConfigAI.ScoreMovingAverageWindow);
                scoreDataList.Add(scoreData);

                // Check whether the vocabulary data was in the journey (and can thus be unlocked)
                if (!UNLOCK_AT_PLAYSESSION_END)
                {
                    if (!scoreData.Unlocked)
                    {
                        IVocabularyData data = null;
                        bool            containedInJourney = false;
                        switch (result.dataType)
                        {
                        case VocabularyDataType.Letter:
                            data = AppManager.I.DB.GetLetterDataById(result.elementId);
                            containedInJourney = currentJourneyContents.Contains(data as LetterData);
                            break;

                        case VocabularyDataType.Word:
                            data = AppManager.I.DB.GetWordDataById(result.elementId);
                            containedInJourney = currentJourneyContents.Contains(data as WordData);
                            break;

                        case VocabularyDataType.Phrase:
                            data = AppManager.I.DB.GetPhraseDataById(result.elementId);
                            containedInJourney = currentJourneyContents.Contains(data as PhraseData);
                            break;
                        }

                        if (containedInJourney)
                        {
                            scoreData.Unlocked = true;
                        }
                    }
                }
            }

            db.InsertAll(logDataList);
            db.InsertOrReplaceAll(scoreDataList);
        }