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