// for not-the-first-time-user calculate the cumulative tag result - // or you may say update the current knowledge status of the user // unique for user-domain public List <CumulativeTagScore> getCumulativeTagWiseResult(UserQuizDetail quiz, UserResult userResult) { List <QuestionAttempted> questions = quiz.QuestionsAttempted; HashSet <string> labels = new HashSet <string>(); Dictionary <string, int> totalTagCount = new Dictionary <string, int>(); Dictionary <string, int> correctTagCount = new Dictionary <string, int>(); Dictionary <int, int> questionTagCount = new Dictionary <int, int>(); Dictionary <string, double> tagRatingList = new Dictionary <string, double>(); foreach (var item in questions) { labels.UnionWith(new HashSet <string>(item.ConceptTags)); } List <CumulativeTagScore> newCumulativeTagScores = new List <CumulativeTagScore>(); foreach (var item in labels) { totalTagCount.Add(item, 0); tagRatingList.Add(item, 0); foreach (var question in questions) { if (question.ConceptTags.Contains(item)) { totalTagCount[item] += 1; if (question.IsCorrect) { tagRatingList[item] += 1 / (float)(question.ConceptTags.Length); } } } tagRatingList[item] /= totalTagCount[item]; tagRatingList[item] = Math.Round(tagRatingList[item], 2); } //calculated the value for the current test, now we'll calculate the aggregate int numOfQuiz = userResult.QuizResults.Count; List <CumulativeTagScore> cumulativeTagScores = userResult.TagWiseCumulativeScore; foreach (var item in cumulativeTagScores) { CumulativeTagScore score = new CumulativeTagScore(); string tagName = item.TagName; double tagRating = item.TagRating; double oldTotalTemp = tagRating * numOfQuiz; double newTotalTemp = oldTotalTemp + tagRatingList[tagName]; double newTagRating = newTotalTemp / (numOfQuiz + 1); newTagRating = Math.Round(newTagRating, 2); score.TagName = tagName; score.TagRating = newTagRating; newCumulativeTagScores.Add(score); } return(newCumulativeTagScores); }
//Update UserQuizDetail table from the UserQuizResponse to use it in UserResult table. This is to make the code less coupled //so that even if the parameters of the UserQuizDetail has changed, we need not have to change everything. //public UserQuizDetail UpdateUserQuizDetail(UserQuizResponse userQuizResponse) //{ // UserQuizDetail userQuizDetail = new UserQuizDetail(); // List<QuestionAttempted> questionsAttempted = new List<QuestionAttempted>(); // string quizId = userQuizResponse.QuizId; // int userId = userQuizResponse.UserId; // string domainName = userQuizResponse.DomainName; // DateTime time = DateTime.Now; // List<Object> questionsList = userQuizResponse.QuestionsAttempted; // int questionCount = 1; // foreach (var x in questionsList) // { // Question item = x as Question; // string questionId = item.QuestionId; // string questionText = item.QuestionText; // List<Result.Models.Options> options = item.Options; // string questionType = item.QuestionType; // string domain = item.Domain; // string[] conceptTags = item.ConceptTags; // int difficultyLevel = item.DifficultyLevel; // string userResponse = item.userResponse; // string correctOption = item.CorrectOption; // Boolean isCorrect = item.IsCorrect; // string taxonomy = item.Taxonomy; // QuestionAttempted question = new QuestionAttempted(); // question.QuestionId = questionId; // question.QuestionText = questionText; // question.QuestionNumber = questionCount++; // List<string> optionList = new List<string>(); // foreach (var option in options) // { // optionList.Add(option.Raw); // } // question.Options = optionList; // question.QuestionType = questionType; // question.ConceptTags = conceptTags; // question.DifficultyLevel = difficultyLevel; // question.Response = userResponse; // question.CorrectAns = correctOption; // question.IsCorrect = isCorrect; // question.Taxonomy = taxonomy; // questionsAttempted.Add(question); // } // userQuizDetail.QuizId = quizId; // userQuizDetail.UserId = userId; // userQuizDetail.Domain = domainName; // userQuizDetail.Time = time; // userQuizDetail.QuestionsAttempted = questionsAttempted; // _context.UserQuizDetail.InsertOne(userQuizDetail); // return userQuizDetail; //} //for the first time, calculate the cumultaive tag wise result for that user-domain test. public void getCumulativeTagWiseResultFirst(UserQuizDetail quiz, List <CumulativeTagScore> cumulativeTagScore) { List <QuestionAttempted> questions = quiz.QuestionsAttempted; HashSet <string> labels = new HashSet <string>(); Dictionary <string, int> totalTagCount = new Dictionary <string, int>(); Dictionary <string, int> correctTagCount = new Dictionary <string, int>(); Dictionary <int, int> questionTagCount = new Dictionary <int, int>(); Dictionary <string, double> tagRatingList = new Dictionary <string, double>(); foreach (var item in questions) { labels.UnionWith(new HashSet <string>(item.ConceptTags)); } foreach (var item in labels) { totalTagCount.Add(item, 0); tagRatingList.Add(item, 0); foreach (var question in questions) { if (question.ConceptTags.Contains(item)) { totalTagCount[item] += 1; if (question.IsCorrect) { tagRatingList[item] += 1 / (float)(question.ConceptTags.Length); } } } tagRatingList[item] /= totalTagCount[item]; tagRatingList[item] = Math.Round(tagRatingList[item], 2); CumulativeTagScore tag = new CumulativeTagScore(); tag.TagName = item; tag.TagRating = tagRatingList[item]; cumulativeTagScore.Add(tag); } }
// for not-the-first-time-user calculate the cumulative tag result - // or you may say update the current knowledge status of the user // unique for user-domain public List <CumulativeTagScore> getCumulativeTagWiseResult(UserQuizDetail quiz, UserResult userResult) { List <QuestionAttempted> questions = quiz.QuestionsAttempted; HashSet <string> labels = new HashSet <string>(); Dictionary <string, int> totalTagCount = new Dictionary <string, int>(); Dictionary <string, int> correctTagCount = new Dictionary <string, int>(); Dictionary <int, int> questionTagCount = new Dictionary <int, int>(); Dictionary <string, double> tagRatingList = new Dictionary <string, double>(); Dictionary <string, double> taxScoreCumulative = new Dictionary <string, double>(); Dictionary <string, double> totalDenCount = new Dictionary <string, double>(); Dictionary <string, int> taxScoreNumber = new Dictionary <string, int>(); Dictionary <string, int> taxScoreNumberOld = new Dictionary <string, int>(); string[] taxonomyLevels = { "Remember", "Understand", "Apply", "Analyze", "Evaluate", "Create" }; foreach (var item in questions) { labels.UnionWith(new HashSet <string>(item.ConceptTags)); } List <CumulativeTagScore> newCumulativeTagScores = new List <CumulativeTagScore>(); foreach (var item in labels) { totalTagCount.Add(item, 0); tagRatingList.Add(item, 0); taxScoreCumulative.Add(item, 0); totalDenCount.Add(item, 0); foreach (var tax in taxonomyLevels) { taxScoreNumber[tax + "-" + item] = 0; } foreach (var question in questions) { if (question.ConceptTags.Contains(item)) { totalTagCount[item] += 1; totalDenCount[item] += question.DifficultyLevel / (float)(question.ConceptTags.Length); if (question.IsCorrect) { tagRatingList[item] += question.DifficultyLevel / (float)(question.ConceptTags.Length); taxScoreCumulative[item] += Array.IndexOf(taxonomyLevels, question.Taxonomy) + 1; taxScoreNumber[question.Taxonomy + "-" + item] += question.DifficultyLevel; } } } tagRatingList[item] /= totalDenCount[item]; tagRatingList[item] = Math.Round(tagRatingList[item], 2); } //calculated the value for the current test, now we'll calculate the aggregate int numOfQuiz = userResult.QuizResults.Count - 1; List <CumulativeTagScore> cumulativeTagScores = userResult.TagWiseCumulativeScore; HashSet <string> oldTag = new HashSet <string>(); foreach (var old in cumulativeTagScores) { oldTag.Add(old.TagName); } HashSet <string> h = new HashSet <string>(labels); HashSet <string> h1 = new HashSet <string>(oldTag); Console.WriteLine("================"); Console.WriteLine(String.Join(",", h1)); Console.WriteLine(String.Join(",", h)); Console.WriteLine("================"); h.ExceptWith(oldTag); h1.ExceptWith(labels); Console.WriteLine(String.Join(",", labels)); Console.WriteLine("================"); Console.WriteLine(String.Join(",", h1)); Console.WriteLine(String.Join(",", h)); Console.WriteLine("================"); foreach (var item in cumulativeTagScores) { // Console.WriteLine("{}{}{}{} " + item.TagName); foreach (var item2 in item.TaxonomyListAndScores) { taxScoreNumberOld[item2.TaxonomyName + "-" + item.TagName] = item2.TaxonomyScoreNumber; } } Console.WriteLine(String.Join(",", taxScoreNumberOld)); Console.WriteLine(String.Join(",", taxScoreNumber)); foreach (var item in cumulativeTagScores) { //concept common in previous and in new if (!h1.Contains(item.TagName)) { Console.WriteLine(item.TagName + "===="); CumulativeTagScore score = new CumulativeTagScore(); string tagName = item.TagName; double tagRating = item.TagRating; string taxLevelOld = item.TaxonomyLevelReached; string taxLevelNew = getTaxonomyLevel(tagName, questions); double taxScoreOld = item.TaxonomyScore; double taxScoreNew = taxScoreCumulative[item.TagName] + taxScoreOld; double oldTotalTemp = tagRating * numOfQuiz; double newTotalTemp = oldTotalTemp + tagRatingList[tagName]; double newTagRating = newTotalTemp / (numOfQuiz + 1); newTagRating = Math.Round(newTagRating, 2); score.TagName = tagName; score.TagRating = newTagRating; score.TaxonomyLevelReached = getHigerTaxonomyLevel(taxLevelOld, taxLevelNew); score.TaxonomyScore = taxScoreNew; List <TaxonomyListAndScore> taxonomyListAndScores = new List <TaxonomyListAndScore>(); foreach (var taxx in taxonomyLevels) { TaxonomyListAndScore taxonomy = new TaxonomyListAndScore(); taxonomy.TaxonomyName = taxx; Console.WriteLine(taxx); taxonomy.TaxonomyScoreNumber = taxScoreNumber[taxx + "-" + item.TagName] + taxScoreNumberOld[taxx + "-" + item.TagName]; taxonomyListAndScores.Add(taxonomy); } score.TaxonomyListAndScores = taxonomyListAndScores; newCumulativeTagScores.Add(score); } //concept in previous but not in new else { CumulativeTagScore score = new CumulativeTagScore(); score.TagName = item.TagName; score.TagRating = item.TagRating; score.TaxonomyLevelReached = item.TaxonomyLevelReached; score.TaxonomyScore = item.TaxonomyScore; List <TaxonomyListAndScore> taxonomyListAndScores = new List <TaxonomyListAndScore>(); foreach (var taxx in taxonomyLevels) { TaxonomyListAndScore taxonomy = new TaxonomyListAndScore(); taxonomy.TaxonomyName = taxx; taxonomy.TaxonomyScoreNumber = taxScoreNumberOld[taxx + "-" + item.TagName]; taxonomyListAndScores.Add(taxonomy); } score.TaxonomyListAndScores = taxonomyListAndScores; newCumulativeTagScores.Add(score); } } //new incoming concept foreach (var item in h) { CumulativeTagScore score = new CumulativeTagScore(); score.TagName = item; score.TagRating = tagRatingList[item]; score.TaxonomyLevelReached = getTaxonomyLevel(item, questions); score.TaxonomyScore = taxScoreCumulative[item]; List <TaxonomyListAndScore> taxonomyListAndScores = new List <TaxonomyListAndScore>(); foreach (var taxx in taxonomyLevels) { TaxonomyListAndScore taxonomy = new TaxonomyListAndScore(); taxonomy.TaxonomyName = taxx; taxonomy.TaxonomyScoreNumber = taxScoreNumber[taxx + "-" + item]; taxonomyListAndScores.Add(taxonomy); } score.TaxonomyListAndScores = taxonomyListAndScores; newCumulativeTagScores.Add(score); } return(newCumulativeTagScores); }
//for the first time, calculate the cumultaive tag wise result for that user-domain test. public void getCumulativeTagWiseResultFirst(UserQuizDetail quiz, List <CumulativeTagScore> cumulativeTagScore) { List <QuestionAttempted> questions = quiz.QuestionsAttempted; HashSet <string> labels = new HashSet <string>(); Dictionary <string, int> totalTagCount = new Dictionary <string, int>(); Dictionary <string, int> correctTagCount = new Dictionary <string, int>(); Dictionary <int, int> questionTagCount = new Dictionary <int, int>(); Dictionary <string, double> tagRatingList = new Dictionary <string, double>(); Dictionary <string, double> taxScoreCumulative = new Dictionary <string, double>(); Dictionary <string, double> totalDenCount = new Dictionary <string, double>(); Dictionary <string, int> taxScoreNumber = new Dictionary <string, int>(); string[] taxonomyLevels = { "Remember", "Understand", "Apply", "Analyze", "Evaluate", "Create" }; foreach (var item in questions) { labels.UnionWith(new HashSet <string>(item.ConceptTags)); } foreach (var item in labels) { totalTagCount.Add(item, 0); tagRatingList.Add(item, 0); taxScoreCumulative.Add(item, 0); totalDenCount.Add(item, 0); foreach (var tax in taxonomyLevels) { taxScoreNumber[tax + "-" + item] = 0; } foreach (var question in questions) { if (question.ConceptTags.Contains(item)) { totalTagCount[item] += 1; totalDenCount[item] += question.DifficultyLevel / (float)(question.ConceptTags.Length); if (question.IsCorrect) { tagRatingList[item] += question.DifficultyLevel / (float)(question.ConceptTags.Length); taxScoreCumulative[item] += Array.IndexOf(taxonomyLevels, question.Taxonomy) + 1; taxScoreNumber[question.Taxonomy + "-" + item] += question.DifficultyLevel; } } } tagRatingList[item] /= totalDenCount[item]; tagRatingList[item] = Math.Round(tagRatingList[item], 2); CumulativeTagScore tag = new CumulativeTagScore(); tag.TagName = item; tag.TagRating = tagRatingList[item]; tag.TaxonomyLevelReached = getTaxonomyLevel(item, questions); tag.TaxonomyScore = taxScoreCumulative[item]; List <TaxonomyListAndScore> taxonomyListAndScores = new List <TaxonomyListAndScore>(); foreach (var tax in taxonomyLevels) { TaxonomyListAndScore taxonomy = new TaxonomyListAndScore(); taxonomy.TaxonomyName = tax; taxonomy.TaxonomyScoreNumber = taxScoreNumber[tax + "-" + item]; taxonomyListAndScores.Add(taxonomy); Console.WriteLine(taxonomy.TaxonomyName); } tag.TaxonomyListAndScores = taxonomyListAndScores; cumulativeTagScore.Add(tag); } }