private static ScaleAnswersSummary SummarizeScaleAnswers(IEnumerable<SurveySubmission> submissions, SurveyQuestion question) { var answersCount = 0; var total = 0; foreach (var submission in submissions) { var answer = submission.Answers.SingleOrDefault(a => a.Question.Id == question.Id); if (answer != null && !string.IsNullOrEmpty(answer.Value)) { var value = 0; if (int.TryParse(answer.Value, out value)) { total += value; answersCount++; } } } return new ScaleAnswersSummary { Average = answersCount > 0 ? Math.Round((decimal)total / answersCount, 2) : 0 }; }
private static YesNoAnswersSummary SummarizeYesNoAnswers(IEnumerable<SurveySubmission> submissions, SurveyQuestion question) { var answersSummary = new YesNoAnswersSummary { Yes = 0, No = 0 }; foreach (var submission in submissions) { var answer = submission.Answers.SingleOrDefault(a => a.Question.Id == question.Id); if (answer != null && !string.IsNullOrEmpty(answer.Value)) { if (answer.Value.Equals("Yes")) { answersSummary.Yes++; } else { answersSummary.No++; } } } return answersSummary; }
private static TextAnswersSummary SummarizeTextAnswers(IEnumerable<SurveySubmission> submissions, SurveyQuestion question) { var answersSummary = new TextAnswersSummary { Answers = new List<string>() }; foreach (var submission in submissions) { var answer = submission.Answers.SingleOrDefault(a => a.Question.Id == question.Id); if (answer != null && !string.IsNullOrEmpty(answer.Value)) { answersSummary.Answers.Add(answer.Value); } } return answersSummary; }