/// <summary> /// Gets the number of responses for the particular question of the questionAnswer /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <returns>The number of total responses to this question</returns> public int GetTotalResponses(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList) { int totalResponses = 0; foreach (GetResponsesResult response in ResponseResultList) { List <QuestionInfo> QuestionResponsesList = response.QuestionList.Where(e => e.QuestionID == qaf.QuestionID).ToList <QuestionInfo>(); if (QuestionResponsesList.Count > 0) { // Do not count answers with optional comments if (qaf.QuestionSubtype == QuestionSubtypeEnum.Rating || qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking) { // optional comments have no column value, all other answers in a Matrix have both a column and row value List <AnswerInfo> QuestionResponsesWithoutOptionalCommentsList = QuestionResponsesList[0].QuestionAnswerList.Where(e => e.Column != null).ToList <AnswerInfo>(); totalResponses += QuestionResponsesWithoutOptionalCommentsList.Count; } else if (qaf.QuestionType == QuestionFamilyEnum.Demographic || qaf.QuestionType == QuestionFamilyEnum.DateTime) { totalResponses = ResponseResultList.Length; break; } else { totalResponses += QuestionResponsesList[0].QuestionAnswerList.Length; } } } return(totalResponses); }
/// <summary> /// Figures out how many times a particular respondent chose this QuestionAnswer /// </summary> /// <param name="qaf">The question answer to get counts for</param> /// <param name="qInfo">The information about how a respondent answered this question</param> /// <param name="SQCount">The number of times this answer appears in the respondent's QuestionInfo - but does not catch optional comments</param> /// <returns>The number of times this answer appears in the respondent's QuestionInfo - either 0 or 1 </returns> private int AddCount(QuestionAnswerFlat qaf, QuestionInfo qInfo, int SQCount) { // For counting optional comments if (SQCount == 0 && qaf.QuestionType == QuestionFamilyEnum.Matrix && qaf.AnswerType == AnswerTypeEnum.Other) { List <AnswerInfo> SQSelectOptional = qInfo.QuestionAnswerList.Where(e => e.Row == qaf.Column).ToList <AnswerInfo>(); return(SQSelectOptional.Count); } return(SQCount); }
/// <summary> /// Gets a summary of the responses for a particular question answer, including counts and averages based on survey responses /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <param name="calcTotalResponses">"True" when the totalResponses for this question is unknown</param> /// <returns>An object that contains all of the summary data</returns> public QuestionAnswerFlat GetQuestionAnswerSummary(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions, bool calcTotalResponses = true) { // Calculate total number of responses if it is not provided if (qaf.TotalResponses == 0) { qaf.TotalResponses = GetTotalResponses(qaf, ResponseResultList); } CountAndAverage caa = GetCountAndAverage(qaf, ResponseResultList, surveyQuestions); qaf.Count = caa.Count; qaf.RankAvg = caa.RankAvg; qaf.RankType = GetRankType(qaf); return(qaf); }
/// <summary> /// Turn a detail survey response into a survey id with a list of associated questions and answers. /// </summary> /// <param name="surveyDetailResponse">Has all data regarding the survey</param> public void LoadSurvey(GetSurveyDetailsResponse surveyDetailResponse) { int questionNumber = 0; List<QuestionInfo> qList = new List<QuestionInfo>(); List<QuestionAnswerFlat> qafList = new List<QuestionAnswerFlat>(); SurveyID = surveyDetailResponse.SurveyDetailsResult.SurveyID; foreach(PageInfo surveyPage in surveyDetailResponse.SurveyDetailsResult.PageList) { foreach(QuestionInfo pageQuestion in surveyPage.QuestionList.OrderBy(e => e.Position)) { string row = "0"; string col = "0"; qList.Add(pageQuestion); questionNumber++; foreach (AnswerInfo questionAnswer in pageQuestion.QuestionAnswerList.OrderBy(e => e.Position)) { if (questionAnswer.AnswerType == AnswerTypeEnum.Row) { row = questionAnswer.AnswerID; } if (questionAnswer.AnswerType == AnswerTypeEnum.Column) { col = questionAnswer.Column; } QuestionAnswerFlat qaf = new QuestionAnswerFlat(); qaf.AnswerID = questionAnswer.AnswerID; qaf.AnswerNumber = questionAnswer.Position; qaf.AnswerText = questionAnswer.Text; qaf.AnswerType = questionAnswer.AnswerType; qaf.AnswerVisible = questionAnswer.Visible; qaf.QuestionID = pageQuestion.QuestionID; qaf.QuestionNumber = questionNumber; qaf.QuestionSubtype = pageQuestion.QuestionType.Subtype; qaf.QuestionText = pageQuestion.Heading; qaf.QuestionType = pageQuestion.QuestionType.Family; qaf.Column = col; qaf.Row = row; qaf.Weight = questionAnswer.Weight; qafList.Add(qaf); } } } QuestionList = qList; SurveyWithAnswers = qafList; }
/// <summary> /// Turn a detail survey response into a survey id with a list of associated questions and answers. /// </summary> /// <param name="surveyDetailResponse">Has all data regarding the survey</param> public void LoadSurvey(GetSurveyDetailsResponse surveyDetailResponse) { int questionNumber = 0; List <QuestionInfo> qList = new List <QuestionInfo>(); List <QuestionAnswerFlat> qafList = new List <QuestionAnswerFlat>(); SurveyID = surveyDetailResponse.SurveyDetailsResult.SurveyID; foreach (PageInfo surveyPage in surveyDetailResponse.SurveyDetailsResult.PageList) { foreach (QuestionInfo pageQuestion in surveyPage.QuestionList.OrderBy(e => e.Position)) { string row = "0"; string col = "0"; qList.Add(pageQuestion); questionNumber++; foreach (AnswerInfo questionAnswer in pageQuestion.QuestionAnswerList.OrderBy(e => e.Position)) { if (questionAnswer.AnswerType == AnswerTypeEnum.Row) { row = questionAnswer.AnswerID; } if (questionAnswer.AnswerType == AnswerTypeEnum.Column) { col = questionAnswer.Column; } QuestionAnswerFlat qaf = new QuestionAnswerFlat(); qaf.AnswerID = questionAnswer.AnswerID; qaf.AnswerNumber = questionAnswer.Position; qaf.AnswerText = questionAnswer.Text; qaf.AnswerType = questionAnswer.AnswerType; qaf.AnswerVisible = questionAnswer.Visible; qaf.QuestionID = pageQuestion.QuestionID; qaf.QuestionNumber = questionNumber; qaf.QuestionSubtype = pageQuestion.QuestionType.Subtype; qaf.QuestionText = pageQuestion.Heading; qaf.QuestionType = pageQuestion.QuestionType.Family; qaf.Column = col; qaf.Row = row; qaf.Weight = questionAnswer.Weight; qafList.Add(qaf); } } } QuestionList = qList; SurveyWithAnswers = qafList; }
/// <summary> /// Determines the rank type of a question answer /// </summary> /// <param name="qaf">The question answer</param> /// <returns>The rank type</returns> public RankTypeEnum GetRankType(QuestionAnswerFlat qaf) { switch (qaf.QuestionSubtype) { case QuestionSubtypeEnum.Ranking: switch (qaf.AnswerType) { case AnswerTypeEnum.Row: return(RankTypeEnum.AvgRanking); case AnswerTypeEnum.Column: return(RankTypeEnum.PercentOfResponses); default: break; } break; case QuestionSubtypeEnum.Rating: switch (qaf.AnswerType) { case AnswerTypeEnum.Row: return(RankTypeEnum.AvgRating); case AnswerTypeEnum.Column: return(RankTypeEnum.PercentOfResponses); case AnswerTypeEnum.Other: return(RankTypeEnum.PercentFilledOut); default: break; } break; case QuestionSubtypeEnum.International: return(RankTypeEnum.PercentFilledOut); case QuestionSubtypeEnum.Both: return(RankTypeEnum.PercentFilledOut); default: return(RankTypeEnum.PercentOfResponses); } return(RankTypeEnum.NotSet); }
/// <summary> /// Firgures out the numerical rank of the question answer /// </summary> /// <param name="qaf">The question answer to get rankSum for</param> /// <param name="SQSelect">Contains the corresponding answer that matches the question asnwer</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <returns></returns> private int AddRankSum(QuestionAnswerFlat qaf, List <AnswerInfo> SQSelect, SurveyQuestionView surveyQuestions) { // for calculating average for rankings and ratings if (SQSelect.Count > 0 && (qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking || qaf.QuestionSubtype == QuestionSubtypeEnum.Rating) && qaf.AnswerType == AnswerTypeEnum.Row) { //return qaf.Weight; List <QuestionAnswerFlat> RankSelect = surveyQuestions.SurveyWithAnswers .Where(e => e.AnswerID == SQSelect[0].Column) .ToList <QuestionAnswerFlat>(); // Try to get rank from the weight if (qaf.Weight != 0) { return(qaf.Weight); } else // if weight not set, take from AnswerNumber { return(RankSelect[0].AnswerNumber); } } return(0); }
/// <summary> /// Loads a summary of the responses to each question answer, including counts and averages based on survey responses /// </summary> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question/param> public void LoadResponseSummary(GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions) { List <QuestionInfo> qList = new List <QuestionInfo>(); List <QuestionAnswerFlat> qafList = new List <QuestionAnswerFlat>(); string qafQuestionID = ""; int totalResponses = 0; foreach (QuestionAnswerFlat qaf in surveyQuestions.SurveyWithAnswers) { if (qafQuestionID != qaf.QuestionID) // only recalculate if it is a new question { // Calculate total number of responses for each question in case not everyone answers every question qafQuestionID = qaf.QuestionID; totalResponses = GetTotalResponses(qaf, ResponseResultList); } qaf.TotalResponses = totalResponses; QuestionAnswerFlat qafSummary = GetQuestionAnswerSummary(qaf, ResponseResultList, surveyQuestions, false); qafList.Add(qaf); } SurveyWithAnswers = qafList; }
/// <summary> /// Gets the count and rankAverage for a question answer /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <returns>An object that holds both the count and rank average for the question answer</returns> public CountAndAverage GetCountAndAverage(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions) { int count = 0; double rankSum = 0; int NAresponses = 0; // Count to ignore N/A responses when calculating average CountAndAverage caa = new CountAndAverage(); foreach (GetResponsesResult response in ResponseResultList) { foreach (QuestionInfo qInfo in response.QuestionList) { List <AnswerInfo> SQSelect = qInfo.QuestionAnswerList.Where(e => e.Row == qaf.AnswerID || e.Column == qaf.AnswerID).ToList <AnswerInfo>(); int SQCount = SQSelect.Count; count += AddCount(qaf, qInfo, SQCount); // for calculating average for rankings and ratings if (SQSelect.Count > 0 && (qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking || qaf.QuestionSubtype == QuestionSubtypeEnum.Rating) && qaf.AnswerType == AnswerTypeEnum.Row) { List <QuestionAnswerFlat> RankSelect = surveyQuestions.SurveyWithAnswers .Where(e => e.AnswerID == SQSelect[0].Column) .ToList <QuestionAnswerFlat>(); rankSum += AddRankSum(qaf, SQSelect, surveyQuestions); if (RankSelect[0].AnswerText == "N/A") { NAresponses++; } } } } caa.Count = count; caa.RankAvg = GetRankAvg(rankSum, count, NAresponses, qaf.TotalResponses); return(caa); }
/// <summary> /// Determines the rank type of a question answer /// </summary> /// <param name="qaf">The question answer</param> /// <returns>The rank type</returns> public RankTypeEnum GetRankType(QuestionAnswerFlat qaf) { switch (qaf.QuestionSubtype) { case QuestionSubtypeEnum.Ranking: switch (qaf.AnswerType) { case AnswerTypeEnum.Row: return RankTypeEnum.AvgRanking; case AnswerTypeEnum.Column: return RankTypeEnum.PercentOfResponses; default: break; } break; case QuestionSubtypeEnum.Rating: switch (qaf.AnswerType) { case AnswerTypeEnum.Row: return RankTypeEnum.AvgRating; case AnswerTypeEnum.Column: return RankTypeEnum.PercentOfResponses; case AnswerTypeEnum.Other: return RankTypeEnum.PercentFilledOut; default: break; } break; case QuestionSubtypeEnum.International: return RankTypeEnum.PercentFilledOut; case QuestionSubtypeEnum.Both: return RankTypeEnum.PercentFilledOut; default: return RankTypeEnum.PercentOfResponses; } return RankTypeEnum.NotSet; }
/// <summary> /// Firgures out the numerical rank of the question answer /// </summary> /// <param name="qaf">The question answer to get rankSum for</param> /// <param name="SQSelect">Contains the corresponding answer that matches the question asnwer</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <returns></returns> private int AddRankSum(QuestionAnswerFlat qaf, List<AnswerInfo> SQSelect, SurveyQuestionView surveyQuestions) { // for calculating average for rankings and ratings if (SQSelect.Count > 0 && (qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking || qaf.QuestionSubtype == QuestionSubtypeEnum.Rating) && qaf.AnswerType == AnswerTypeEnum.Row) { //return qaf.Weight; List<QuestionAnswerFlat> RankSelect = surveyQuestions.SurveyWithAnswers .Where(e => e.AnswerID == SQSelect[0].Column) .ToList<QuestionAnswerFlat>(); // Try to get rank from the weight if (qaf.Weight != 0) { return qaf.Weight; } else // if weight not set, take from AnswerNumber { return RankSelect[0].AnswerNumber; } } return 0; }
/// <summary> /// Figures out how many times a particular respondent chose this QuestionAnswer /// </summary> /// <param name="qaf">The question answer to get counts for</param> /// <param name="qInfo">The information about how a respondent answered this question</param> /// <param name="SQCount">The number of times this answer appears in the respondent's QuestionInfo - but does not catch optional comments</param> /// <returns>The number of times this answer appears in the respondent's QuestionInfo - either 0 or 1 </returns> private int AddCount(QuestionAnswerFlat qaf, QuestionInfo qInfo, int SQCount) { // For counting optional comments if (SQCount == 0 && qaf.QuestionType == QuestionFamilyEnum.Matrix && qaf.AnswerType == AnswerTypeEnum.Other) { List<AnswerInfo> SQSelectOptional = qInfo.QuestionAnswerList.Where(e => e.Row == qaf.Column).ToList<AnswerInfo>(); return SQSelectOptional.Count; } return SQCount; }
/// <summary> /// Gets the count and rankAverage for a question answer /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <returns>An object that holds both the count and rank average for the question answer</returns> public CountAndAverage GetCountAndAverage(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions) { int count = 0; double rankSum = 0; int NAresponses = 0; // Count to ignore N/A responses when calculating average CountAndAverage caa = new CountAndAverage(); foreach (GetResponsesResult response in ResponseResultList) { foreach (QuestionInfo qInfo in response.QuestionList) { List<AnswerInfo> SQSelect = qInfo.QuestionAnswerList.Where(e => e.Row == qaf.AnswerID || e.Column == qaf.AnswerID).ToList<AnswerInfo>(); int SQCount = SQSelect.Count; count += AddCount(qaf, qInfo, SQCount); // for calculating average for rankings and ratings if (SQSelect.Count > 0 && (qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking || qaf.QuestionSubtype == QuestionSubtypeEnum.Rating) && qaf.AnswerType == AnswerTypeEnum.Row) { List<QuestionAnswerFlat> RankSelect = surveyQuestions.SurveyWithAnswers .Where(e => e.AnswerID == SQSelect[0].Column) .ToList<QuestionAnswerFlat>(); rankSum += AddRankSum(qaf, SQSelect, surveyQuestions); if (RankSelect[0].AnswerText == "N/A") { NAresponses++; } } } } caa.Count = count; caa.RankAvg = GetRankAvg(rankSum, count, NAresponses, qaf.TotalResponses); return caa; }
/// <summary> /// Gets the number of responses for the particular question of the questionAnswer /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <returns>The number of total responses to this question</returns> public int GetTotalResponses(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList) { int totalResponses = 0; foreach (GetResponsesResult response in ResponseResultList) { List<QuestionInfo> QuestionResponsesList = response.QuestionList.Where(e => e.QuestionID == qaf.QuestionID).ToList<QuestionInfo>(); if (QuestionResponsesList.Count > 0) { // Do not count answers with optional comments if (qaf.QuestionSubtype == QuestionSubtypeEnum.Rating || qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking) { // optional comments have no column value, all other answers in a Matrix have both a column and row value List<AnswerInfo> QuestionResponsesWithoutOptionalCommentsList = QuestionResponsesList[0].QuestionAnswerList.Where(e => e.Column != null).ToList<AnswerInfo>(); totalResponses += QuestionResponsesWithoutOptionalCommentsList.Count; } else if (qaf.QuestionType == QuestionFamilyEnum.Demographic || qaf.QuestionType == QuestionFamilyEnum.DateTime) { totalResponses = ResponseResultList.Length; break; } else { totalResponses += QuestionResponsesList[0].QuestionAnswerList.Length; } } } return totalResponses; }
/// <summary> /// Gets a summary of the responses for a particular question answer, including counts and averages based on survey responses /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <param name="calcTotalResponses">"True" when the totalResponses for this question is unknown</param> /// <returns>An object that contains all of the summary data</returns> public QuestionAnswerFlat GetQuestionAnswerSummary(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions, bool calcTotalResponses = true) { // Calculate total number of responses if it is not provided if (qaf.TotalResponses == 0) { qaf.TotalResponses = GetTotalResponses(qaf, ResponseResultList); } CountAndAverage caa = GetCountAndAverage(qaf, ResponseResultList, surveyQuestions); qaf.Count = caa.Count; qaf.RankAvg = caa.RankAvg; qaf.RankType = GetRankType(qaf); return qaf; }