예제 #1
0
        public static List <CategoryInfo> CreateSingleAnswerOrDateTimeCategoryInfos(ICollection <object> values, CategoryHelper categoryHelper)
        {
            Dictionary <string, int> casesDict = CreateCasesDict(values);

            Dictionary <string, string> sortKeyDict = new Dictionary <string, string>();
            List <string> keyList = casesDict.Keys.ToList();

            foreach (string key in keyList)
            {
                // 1 => 0000000001
                // 21=> 0000000021
                sortKeyDict[key] = EDOUtils.PadZero(key, 10);
            }

            keyList.Sort((a, b) => string.Compare(sortKeyDict[a], sortKeyDict[b]));
            List <CategoryInfo> categoryInfos = new List <CategoryInfo>();
            int emptyCases = 0;

            foreach (string key in keyList)
            {
                int cases = casesDict[key];
                if (string.IsNullOrEmpty(key))
                {
                    emptyCases += cases;
                    continue;
                }
                CategoryInfo categoryInfo = categoryHelper.CreateCategoryInfo(key, cases);
                categoryInfos.Add(categoryInfo);
            }
            CategoryInfo emptyCategoryInfo = CreateEmptyCategoryInfo(emptyCases);

            categoryInfos.Add(emptyCategoryInfo);
            CalcPercent(categoryInfos);
            return(categoryInfos);
        }
예제 #2
0
 public static int UniqOrderNo(HashSet <string> titles, string curTitle, string prefix)
 {
     // Returns unique number for the specified title
     if (curTitle != null)
     {
         Regex reg = new Regex(prefix + @"\d+");
         Match m   = reg.Match(curTitle);
         if (!m.Success)
         {
             return(-1); //Return -1 if the title doesn't start with prefix
         }
     }
     for (int i = 1; i < 9999; i++)
     {
         string title = EDOUtils.OrderTitle(prefix, i);
         if (curTitle != null)
         {
             // Return 4 if the title has been decided such as "Mode of Data Collection 4".
             if (title == curTitle)
             {
                 return(i);
             }
         }
         else
         {
             // If title is null(not stored in model) and unused, returns its number.
             // Returns title2 if title1 and title3 are included in titles
             if (!titles.Contains(title))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
예제 #3
0
        public static List <CodebookVariable> CreateCodebookVariables(StudyUnitVM studyUnit)
        {
            List <CodebookVariable>           codebookVariables = new List <CodebookVariable>();
            ObservableCollection <QuestionVM> questions         = studyUnit.AllQuestions;

            foreach (VariableVM variable in studyUnit.Variables)
            {
                QuestionVM      question       = EDOUtils.Find <QuestionVM>(questions, variable.QuestionId);
                StatisticsInfo  statisticsInfo = studyUnit.FindStatisticsInfoModel(variable);
                StatisticsTypes statisticsType = StatisticsTypes.Unknown;
                if (statisticsInfo == null)
                {
                    statisticsType = studyUnit.GetStatisticsType(variable);
                }
                else
                {
                    statisticsType = statisticsInfo.StatisticsType;
                    statisticsInfo.ApplyScale();
                }
                CodebookVariable codebookVariable = null;
                if (question != null && StatisticsInfo.IsTypeChoicesMultipleAnswerOf(statisticsType))
                {
                    codebookVariable = CodebookVariable.FindByQuestionId(codebookVariables, question.Id);
                }
                if (codebookVariable == null)
                {
                    codebookVariable = new CodebookVariable();
                    codebookVariables.Add(codebookVariable);
                }
                codebookVariable.Variables.Add(variable);
                codebookVariable.Question       = question;
                codebookVariable.StatisticsInfo = statisticsInfo;
                codebookVariable.StatisticsType = statisticsType;
            }
            return(codebookVariables);
        }