// 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);
            }
        }