Example #1
0
 public ScoreData(string elementId, DbTables table, float score, int timestamp)
 {
     this.ElementId           = elementId;
     this.TableName           = table.ToString();
     this.Id                  = TableName + "." + ElementId;
     this.Score               = score;
     this.LastAccessTimestamp = timestamp;
 }
Example #2
0
 private UpdateData CreateUpdateDataMessage(int objectId, string columnName, DbTables tableName)
 {
     return(new UpdateData
     {
         RowId = objectId,
         ColumnName = columnName,
         TableName = tableName.ToString()
     });
 }
 public LogLearnData(string _Session, string _PlaySession, MiniGameCode _MiniGame, DbTables _table, string _elementId, float _score)
 {
     this.Session     = _Session;
     this.PlaySession = _PlaySession;
     this.MiniGame    = _MiniGame;
     this.TableName   = _table.ToString();
     this.ElementId   = _elementId;
     this.Score       = _score;
     this.Timestamp   = GenericUtilities.GetTimestampForNow();
 }
Example #4
0
        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);
        }
Example #5
0
        public List <I> GetAllInfo <D, I>(List <D> data_list, DbTables table) where I : DataInfo <D>, new() where D : IData
        {
            var info_list = new List <I>();

            // Build info instances for the given data
            foreach (var data in data_list)
            {
                var info = new I();
                info.data = data;
                info_list.Add(info);
            }

            // Find available scores
            string           query          = string.Format("SELECT * FROM ScoreData WHERE TableName = '" + table.ToString() + "' ORDER BY ElementId ");
            List <ScoreData> scoredata_list = dbManager.FindScoreDataByQuery(query);

            for (int i = 0; i < info_list.Count; i++)
            {
                var info      = info_list[i];
                var scoredata = scoredata_list.Find(x => x.ElementId == info.data.GetId());
                if (scoredata != null)
                {
                    info.score    = scoredata.Score;
                    info.unlocked = true;
                }
                else
                {
                    info.score    = 0; // 0 until unlocked
                    info.unlocked = false;
                }
            }

            return(info_list);
        }
Example #6
0
        private void UpdateScoreDataWithMovingAverage(DbTables table, string elementId, float newScore, int movingAverageSpan)
        {
            string           query                = string.Format("SELECT * FROM ScoreData WHERE TableName = '{0}' AND ElementId = '{1}'", table.ToString(), elementId);
            List <ScoreData> scoreDataList        = db.FindScoreDataByQuery(query);
            float            previousAverageScore = 0;

            if (scoreDataList.Count > 0)
            {
                previousAverageScore = scoreDataList[0].Score;
            }
            // @note: for the first movingAverageSpan values, this won't be accurate
            float newAverageScore = previousAverageScore - previousAverageScore / movingAverageSpan + newScore / movingAverageSpan;

            db.UpdateScoreData(table, elementId, newAverageScore);
        }
Example #7
0
        private void UpdateScoreDataWithMaximum(DbTables table, string elementId, float newScore)
        {
            string           query            = string.Format("SELECT * FROM ScoreData WHERE TableName = '{0}' AND ElementId = '{1}'", table.ToString(), elementId);
            List <ScoreData> scoreDataList    = db.FindScoreDataByQuery(query);
            float            previousMaxScore = 0;

            if (scoreDataList.Count > 0)
            {
                previousMaxScore = scoreDataList[0].Score;
            }
            float newMaxScore = Mathf.Max(previousMaxScore, newScore);

            db.UpdateScoreData(table, elementId, newMaxScore);
        }