public SelectionParameters(SelectionSeverity severity, int nRequired = 0, bool getMaxData = false, bool useJourney = true, PackListHistory packListHistory = PackListHistory.NoFilter, List <string> filteringIds = null) { this.nRequired = nRequired; this.getMaxData = getMaxData; this.severity = severity; this.useJourney = useJourney; this.packListHistory = packListHistory; this.filteringIds = filteringIds; }
public SelectionParameters(SelectionSeverity severity, int nRequired = 0, bool getMaxData = false, bool useJourney = true, JourneyFilter journeyFilter = JourneyFilter.CurrentJourney, PackListHistory packListHistory = PackListHistory.NoFilter, List <string> filteringIds = null, bool sortDataByDifficulty = false) { this.nRequired = nRequired; this.getMaxData = getMaxData; this.severity = severity; this.useJourney = useJourney; this.journeyFilter = journeyFilter; this.packListHistory = packListHistory; this.filteringIds = filteringIds; this.sortDataByDifficulty = sortDataByDifficulty; }
public QuestionBuilderParameters() { this.correctChoicesHistory = PackListHistory.RepeatWhenFull; this.wrongChoicesHistory = PackListHistory.RepeatWhenFull; this.useJourneyForCorrect = true; this.useJourneyForWrong = false; this.correctSeverity = SelectionSeverity.MayRepeatIfNotEnough; this.wrongSeverity = SelectionSeverity.MayRepeatIfNotEnough; this.letterFilters = new LetterFilters(); this.wordFilters = new WordFilters(); this.phraseFilters = new PhraseFilters(); }
public QuestionBuilderParameters() { this.correctChoicesHistory = PackListHistory.RepeatWhenFull; this.wrongChoicesHistory = PackListHistory.RepeatWhenFull; this.useJourneyForCorrect = true; this.useJourneyForWrong = true; this.correctSeverity = SelectionSeverity.MayRepeatIfNotEnough; this.wrongSeverity = SelectionSeverity.MayRepeatIfNotEnough; this.letterEqualityStrictness = LetterEqualityStrictness.LetterOnly; this.letterFilters = new LetterFilters(); this.wordFilters = new WordFilters(); this.phraseFilters = new PhraseFilters(); this.sortPacksByDifficulty = true; }
private List <T> WeightedDataSelect <T>(List <T> source_data_list, HashSet <T> currentPSData, int nToSelect, DbTables table, SelectionSeverity severity) where T : IData { // Given a (filtered) list of data, select some using weights List <ScoreData> score_data_list = dbManager.FindScoreDataByQuery("SELECT * FROM ScoreData WHERE TableName = '" + table.ToString() + "'"); string debugString = "-- Teacher Selection Weights"; List <float> weights_list = new List <float>(); foreach (var sourceData in source_data_list) { float cumulativeWeight = 0; debugString += "\n" + sourceData.GetId() + " ---"; // Get score data var score_data = score_data_list.Find(x => x.ElementId == sourceData.GetId()); float currentScore = 0; int daysSinceLastScore = 0; if (score_data != null) { var timespanFromLastScoreToNow = GenericUtilities.GetTimeSpanBetween(score_data.LastAccessTimestamp, GenericUtilities.GetTimestampForNow()); daysSinceLastScore = timespanFromLastScoreToNow.Days; currentScore = score_data.Score; } //UnityEngine.Debug.Log("Data " + id + " score: " + currentScore + " days " + daysSinceLastScore); // Score Weight [0,1]: higher the lower the score [-1,1] is var scoreWeight = 0.5f * (1 - currentScore); cumulativeWeight += scoreWeight * ConfigAI.data_scoreWeight; debugString += " \tScore: " + scoreWeight * ConfigAI.data_scoreWeight + "(" + scoreWeight + ")"; // RecentPlay Weight [1,0]: higher the more in the past we saw that data const float dayLinerWeightDecrease = 1f / ConfigAI.daysForMaximumRecentPlayMalus; float weightMalus = daysSinceLastScore * dayLinerWeightDecrease; float recentPlayWeight = 1f - UnityEngine.Mathf.Min(1, weightMalus); cumulativeWeight += recentPlayWeight * ConfigAI.data_recentPlayWeight; debugString += " \tRecent: " + recentPlayWeight * ConfigAI.data_recentPlayWeight + "(" + recentPlayWeight + ")"; // Current focus weight [1,0]: higher if the data is part of the current play session float currentPlaySessionWeight = currentPSData.Contains(sourceData) ? 1 : 0f; cumulativeWeight += currentPlaySessionWeight * ConfigAI.data_currentPlaySessionWeight; debugString += " \tCurrentPS: " + currentPlaySessionWeight * ConfigAI.data_currentPlaySessionWeight + "(" + currentPlaySessionWeight + ")"; // If the cumulative weight goes to the negatives, we give it a fixed weight if (cumulativeWeight <= 0) { cumulativeWeight = ConfigAI.data_minimumTotalWeight; continue; } // Save cumulative weight weights_list.Add(cumulativeWeight); debugString += " TOTw: " + cumulativeWeight; } if (ConfigAI.verboseDataSelection) { UnityEngine.Debug.Log(debugString); } // Select data from the list List <T> selected_data_list = new List <T>(); if (source_data_list.Count > 0) { int nToSelectFromCurrentList = 0; List <T> chosenData = null; switch (severity) { case SelectionSeverity.AsManyAsPossible: case SelectionSeverity.AllRequired: nToSelectFromCurrentList = UnityEngine.Mathf.Min(source_data_list.Count, nToSelect); chosenData = RandomHelper.RouletteSelectNonRepeating(source_data_list, weights_list, nToSelectFromCurrentList); selected_data_list.AddRange(chosenData); break; case SelectionSeverity.MayRepeatIfNotEnough: int nRemainingToSelect = nToSelect; while (nRemainingToSelect > 0) { var listCopy = new List <T>(source_data_list); nToSelectFromCurrentList = UnityEngine.Mathf.Min(source_data_list.Count, nRemainingToSelect); chosenData = RandomHelper.RouletteSelectNonRepeating(listCopy, weights_list, nToSelectFromCurrentList); selected_data_list.AddRange(chosenData); nRemainingToSelect -= nToSelectFromCurrentList; } break; } } return(selected_data_list); }
private List <T> WeightedDataSelect <T>(List <T> source_data_list, int nToSelect, SelectionSeverity severity) where T : IData { VocabularyDataType dataType = VocabularyDataType.Letter; if (typeof(T) == typeof(LetterData)) { dataType = VocabularyDataType.Letter; } else if (typeof(T) == typeof(WordData)) { dataType = VocabularyDataType.Word; } else if (typeof(T) == typeof(PhraseData)) { dataType = VocabularyDataType.Phrase; } // Given a (filtered) list of data, select some using weights var score_data_list = dbManager.Query <VocabularyScoreData>("SELECT * FROM " + typeof(VocabularyScoreData).Name + " WHERE VocabularyDataType = '" + (int)dataType + "'"); if (ConfigAI.VerboseDataSelection) { weightedData_debugString += ConfigAI.FormatTeacherReportHeader("Selection Weights"); weightedData_debugString = ""; } var weights_list = new List <float>(); foreach (var sourceData in source_data_list) { float cumulativeWeight = 0; if (ConfigAI.VerboseDataSelection) { weightedData_debugString += "\n" + sourceData.GetId() + " ---"; } // Get score data var score_data = score_data_list.Find(x => x.ElementId == sourceData.GetId()); float currentScore = 0; int daysSinceLastScore = 0; if (score_data != null) { var timespanFromLastScoreToNow = GenericHelper.GetTimeSpanBetween(score_data.UpdateTimestamp, GenericHelper.GetTimestampForNow()); daysSinceLastScore = timespanFromLastScoreToNow.Days; currentScore = score_data.Score; } //UnityEngine.Debug.Log("Data " + id + " score: " + currentScore + " days " + daysSinceLastScore); // Score Weight [0,1]: higher the lower the score [-1,1] is var scoreWeight = 0.5f * (1 - currentScore); cumulativeWeight += scoreWeight * ConfigAI.Vocabulary_Score_Weight; if (ConfigAI.VerboseDataSelection) { weightedData_debugString += " \tScore: " + scoreWeight * ConfigAI.Vocabulary_Score_Weight + "(" + scoreWeight + ")"; } // RecentPlay Weight [1,0]: higher the more in the past we saw that data const float dayLinerWeightDecrease = 1f / ConfigAI.DaysForMaximumRecentPlayMalus; float weightMalus = daysSinceLastScore * dayLinerWeightDecrease; float recentPlayWeight = 1f - UnityEngine.Mathf.Min(1, weightMalus); cumulativeWeight += recentPlayWeight * ConfigAI.Vocabulary_RecentPlay_Weight; if (ConfigAI.VerboseDataSelection) { weightedData_debugString += " \tRecent: " + recentPlayWeight * ConfigAI.Vocabulary_RecentPlay_Weight + "(" + recentPlayWeight + ")"; } // Current focus weight [1,0]: higher if the data is part of the current play session / learning block / stage float currentPlaySessionWeight = 0; if (currentPlaySessionContents.Contains(sourceData)) { currentPlaySessionWeight = 1; } else if (currentLearningBlockContents.Contains(sourceData)) { currentPlaySessionWeight = 0.5f; } else if (currentStageContents.Contains(sourceData)) { currentPlaySessionWeight = 0.2f; } cumulativeWeight += currentPlaySessionWeight * ConfigAI.Vocabulary_CurrentPlaySession_Weight; if (ConfigAI.VerboseDataSelection) { weightedData_debugString += " \tFocus: " + currentPlaySessionWeight * ConfigAI.Vocabulary_CurrentPlaySession_Weight + "(" + currentPlaySessionWeight + ")"; } // If the cumulative weight goes to the negatives, we give it a fixed weight // TODO check if we shound use if (cumulativeWeight <= ConfigAI.Vocabulary_MinTotal_Weight) // TODO check the "continue" because it wont' save the data if (cumulativeWeight <= 0) { cumulativeWeight = ConfigAI.Vocabulary_MinTotal_Weight; continue; } // Save cumulative weight weights_list.Add(cumulativeWeight); if (ConfigAI.VerboseDataSelection) { weightedData_debugString += " TOTw: " + cumulativeWeight; } } //return source_data_list; if (ConfigAI.VerboseDataSelection) { ConfigAI.AppendToTeacherReport(weightedData_debugString); } // Select data from the list var selected_data_list = new List <T>(); if (source_data_list.Count > 0) { int nToSelectFromCurrentList = 0; List <T> chosenData = null; switch (severity) { case SelectionSeverity.AsManyAsPossible: case SelectionSeverity.AllRequired: nToSelectFromCurrentList = UnityEngine.Mathf.Min(source_data_list.Count, nToSelect); chosenData = RandomHelper.RouletteSelectNonRepeating(source_data_list, weights_list, nToSelectFromCurrentList); selected_data_list.AddRange(chosenData); break; case SelectionSeverity.MayRepeatIfNotEnough: int nRemainingToSelect = nToSelect; while (nRemainingToSelect > 0) { var listCopy = new List <T>(source_data_list); nToSelectFromCurrentList = UnityEngine.Mathf.Min(source_data_list.Count, nRemainingToSelect); chosenData = RandomHelper.RouletteSelectNonRepeating(listCopy, weights_list, nToSelectFromCurrentList); selected_data_list.AddRange(chosenData); nRemainingToSelect -= nToSelectFromCurrentList; } break; } } return(selected_data_list); }