Example #1
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);
        }
Example #2
0
        public static List <StatisticsInfo> CreateStatisticsInfos(RawData data, StudyUnitVM studyUnit)
        {
            Dictionary <string, List <VariableVM> > maVariables = new Dictionary <string, List <VariableVM> >();
            List <StatisticsInfo> statisticsInfos = new List <StatisticsInfo>();

            foreach (VariableVM variable in studyUnit.Variables)
            {
                StatisticsTypes type           = studyUnit.GetStatisticsType(variable);
                StatisticsInfo  statisticsInfo = null;

                if (StatisticsInfo.IsTypeNumberOf(type))
                {
                    statisticsInfo = CreateNumberStatisticsInfo(data, variable);
                }
                else if (StatisticsInfo.IsTypeDateTimeOf(type))
                {
                    statisticsInfo = CreateDateTimeStatisticsInfo(data, variable);
                }
                else if (StatisticsInfo.IsTypeChoicesSingleAnswerOf(type))
                {
                    statisticsInfo = CreateSingleAnswerStatisticsInfo(data, variable);
                }
                else if (StatisticsInfo.IsTypeChoicesMultipleAnswerOf(type))
                {
                    List <VariableVM> variables = null;
                    string            key       = variable.QuestionId;
                    if (maVariables.ContainsKey(key))
                    {
                        variables = maVariables[key];
                    }
                    else
                    {
                        variables        = new List <VariableVM>();
                        maVariables[key] = variables;
                    }
                    variables.Add(variable);
                }
                if (statisticsInfo != null)
                {
                    statisticsInfos.Add(statisticsInfo);
                }
            }
            // Multiple Answer
            foreach (KeyValuePair <string, List <VariableVM> > pair in maVariables)
            {
                string            questionId = pair.Key;
                List <VariableVM> variables  = pair.Value;
                QuestionVM        question   = studyUnit.FindQuestion(questionId);
                if (question == null)
                {
                    continue;
                }
                StatisticsInfo statisticsInfo = CreateMultipleAnswerStatisticsInfo(data, question, variables);
                if (statisticsInfo == null)
                {
                    continue;
                }
                statisticsInfos.Add(statisticsInfo);
            }
            return(statisticsInfos);
        }