public static StatisticsInfo CreateDummyChoicesMultiAnswerStatisticsInfo(CodebookVariable codebookVariable) { Debug.Assert(codebookVariable.IsTypeChoicesMultipleAnswer); Debug.Assert(codebookVariable.Question != null); QuestionVM question = codebookVariable.Question; ObservableCollection <CodeVM> codes = question.Response.Codes; List <VariableVM> variables = codebookVariable.Variables; List <CategoryInfo> categoryInfos = new List <CategoryInfo>(); for (int i = 0; i < variables.Count; i++) { if (i >= codes.Count) { break; } VariableVM variable = variables[i]; CodeVM code = codes[i]; CategoryInfo categoryInfo = new CategoryInfo(); categoryInfo.VariableTitle = variable.Title; categoryInfo.CodeValue = code.Value; categoryInfo.CategoryTitle = code.Label; categoryInfos.Add(categoryInfo); } StatisticsInfo statisticsInfo = new StatisticsInfo(); statisticsInfo.QuestionId = question.Id; statisticsInfo.StatisticsType = StatisticsTypes.ChoicesMultipleAnswer; statisticsInfo.CategoryInfos = categoryInfos; return(statisticsInfo); }
private void WriteNumberVariable(Body body, CodebookVariable codebookVariable) { WriteVariableInfo(body, codebookVariable.FirstVariable); WriteQuestionInfo(body, codebookVariable.Question); Paragraph p = CreateEmptyParagraph(); body.Append(p); Table table = CreateTable(); body.Append(table); DocxTableRowParam rowParam = new DocxTableRowParam(); rowParam.Add(Resources.Item); rowParam.Add(Resources.Value); table.Append(rowParam.CreateTableRow()); rowParam = new DocxTableRowParam(); rowParam.Add(Resources.ValidFrequency); rowParam.AddRight(codebookVariable.ValidCasesString); table.Append(rowParam.CreateTableRow()); rowParam = new DocxTableRowParam(); rowParam.Add(Resources.InvalidFrequency); rowParam.AddRight(codebookVariable.InvalidCasesString); table.Append(rowParam.CreateTableRow()); rowParam = new DocxTableRowParam(); rowParam.Add(Resources.SampleFrequency); rowParam.AddRight(codebookVariable.TotalCasesString); table.Append(rowParam.CreateTableRow()); rowParam = new DocxTableRowParam(); rowParam.Add(Resources.Mean); rowParam.AddRight(codebookVariable.MeanString); table.Append(rowParam.CreateTableRow()); rowParam = new DocxTableRowParam(); rowParam.Add(Resources.Median); rowParam.AddRight(codebookVariable.MedianString); table.Append(rowParam.CreateTableRow()); rowParam = new DocxTableRowParam(); rowParam.Add(Resources.StandardDeviation); rowParam.AddRight(codebookVariable.StandardDeviationString); table.Append(rowParam.CreateTableRow()); rowParam = new DocxTableRowParam(); rowParam.Add(Resources.Minimum); rowParam.AddRight(codebookVariable.MinimumString); table.Append(rowParam.CreateTableRow()); rowParam = new DocxTableRowParam(); rowParam.Add(Resources.Maximum); rowParam.AddRight(codebookVariable.MaximumString); table.Append(rowParam.CreateTableRow()); }
public static StatisticsInfo CreateDummyChoicesSingleAnswerStatisticsInfo(CodebookVariable codebookVariable) { VariableVM variable = codebookVariable.FirstVariable; ObservableCollection <CodeVM> codes = variable.Response.Codes; List <CategoryInfo> categoryInfos = new List <CategoryInfo>(); foreach (CodeVM code in codes) { CategoryInfo categoryInfo = new CategoryInfo(); categoryInfo.CategoryType = CategoryHelper.ToCategoryType(code.IsMissingValue); categoryInfo.CodeValue = code.Value; categoryInfo.CategoryTitle = code.Label; categoryInfos.Add(categoryInfo); } StatisticsInfo statisticsInfo = new StatisticsInfo(); statisticsInfo.VariableId = variable.Id; statisticsInfo.StatisticsType = StatisticsTypes.ChoicesSingleAnswer; statisticsInfo.CategoryInfos = categoryInfos; return(statisticsInfo); }
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); }
private void WriteChoicesSingleAnswerVariable(Body body, CodebookVariable codebookVariable, bool writeCode = true) { WriteVariableInfo(body, codebookVariable.FirstVariable); WriteQuestionInfo(body, codebookVariable.Question); Paragraph p = CreateEmptyParagraph(); body.Append(p); Table table = CreateTable(); body.Append(table); DocxTableRowParam rowParam = new DocxTableRowParam(); if (writeCode) { rowParam.Add(Resources.CodeNumber); } rowParam.Add(Resources.BranchSentence); rowParam.Add(Resources.Frequency); rowParam.Add(Resources.TotalPercent); rowParam.Add(Resources.TotalEffectivePercent); table.Append(rowParam.CreateTableRow()); StatisticsInfo statisticsInfo = codebookVariable.StatisticsInfo; if (statisticsInfo == null) { statisticsInfo = StatisticsUtils.CreateDummyChoicesSingleAnswerStatisticsInfo(codebookVariable); } ValueConverter converter = new ValueConverter() { HasData = codebookVariable.HasData }; CategoryInfoCollection[] collections = CategoryInfoCollection.Create(statisticsInfo); // normal values CategoryInfoCollection normalCollection = collections[1]; foreach (CategoryInfo normalInfo in normalCollection) { rowParam = CreateNormalCategoryInfoRow(normalInfo, converter, writeCode); table.Append(rowParam.CreateTableRow()); } // normal values subtotal rowParam = CreateTotalRow(normalCollection, converter, Resources.TotalValidValues, normalCollection.FullPercent, writeCode); table.Append(rowParam.CreateTableRow()); // missing values CategoryInfoCollection missingCollection = collections[2]; foreach (CategoryInfo missingInfo in missingCollection) { rowParam = CreateMissingOrEmptyCategoryInfoRow(missingInfo, converter, writeCode); table.Append(rowParam.CreateTableRow()); } // missing values subtotal rowParam = CreateTotalRow(missingCollection, converter, Resources.TotalInvalidValues, EDOConstants.EMPTY_CURSOR, writeCode); table.Append(rowParam.CreateTableRow()); // total CategoryInfoCollection totalCollection = collections[0]; rowParam = CreateTotalRow(totalCollection, converter, Resources.TotalAll, EDOConstants.EMPTY_CURSOR, writeCode); table.Append(rowParam.CreateTableRow()); }
private void WriteChoicesMultiAnswerVariable(Body body, CodebookVariable codebookVariable) { WriteQuestionInfo(body, codebookVariable.Question); Paragraph p = CreateEmptyParagraph(); body.Append(p); Table table = CreateTable(); body.Append(table); DocxTableRowParam rowParam = new DocxTableRowParam(); rowParam.Add(Resources.VariableName); rowParam.Add(Resources.CodeNumber); rowParam.Add(Resources.BranchSentence); rowParam.Add(Resources.Frequency); rowParam.Add(Resources.Percent); rowParam.Add(Resources.CasePercent); rowParam.Add(Resources.EffectivePercent); rowParam.Add(Resources.EffectiveCasePercent); table.Append(rowParam.CreateTableRow()); StatisticsInfo statisticsInfo = codebookVariable.StatisticsInfo; if (statisticsInfo == null) { statisticsInfo = StatisticsUtils.CreateDummyChoicesMultiAnswerStatisticsInfo(codebookVariable); } CategoryInfoCollection[] collections = CategoryInfoCollection.Create(statisticsInfo); ValueConverter converter = new ValueConverter() { HasData = codebookVariable.HasData }; // normal values CategoryInfoCollection normalCollection = collections[1]; foreach (CategoryInfo normalInfo in normalCollection) { rowParam = CreateMultiAnswerCategoryInfoRow(normalInfo, converter, true); table.Append(rowParam.CreateTableRow()); } // normal values subtotal rowParam = CreateMultiAnswerTotalRow(normalCollection, converter, Resources.TotalValidValues, normalCollection.TotalPercentString, normalCollection.FullPercent); table.Append(rowParam.CreateTableRow()); // missing values CategoryInfoCollection missingCollection = collections[2]; foreach (CategoryInfo missingInfo in missingCollection) { rowParam = CreateMultiAnswerCategoryInfoRow(missingInfo, converter, false); table.Append(rowParam.CreateTableRow()); } // missing values subtotal rowParam = CreateMultiAnswerTotalRow(missingCollection, converter, Resources.TotalInvalidValues, normalCollection.TotalPercentString, EDOConstants.EMPTY_CURSOR); table.Append(rowParam.CreateTableRow()); CategoryInfoCollection totalCollection = collections[0]; // total responses rowParam = CreateMultiAnswerTotalRow(totalCollection, converter, Resources.TotalResponses, totalCollection.FullPercent, EDOConstants.EMPTY_CURSOR); table.Append(rowParam.CreateTableRow()); // total samples rowParam = CreateMultiAnswerTotalRow(totalCollection, converter, Resources.TotalSamples, EDOConstants.EMPTY_CURSOR, EDOConstants.EMPTY_CURSOR); table.Append(rowParam.CreateTableRow()); }