示例#1
0
        public string Get()
        {
            List <QuestionDataModel> questionData = new List <QuestionDataModel>();
            string result = "Error unable to process request. Please ensure all inputs are valid.";

            questionData = surveyQuestionService.GetSurveyQuestions();

            if (questionData.Count > 0)
            {
                result = JsonConvert.SerializeObject(questionData);
            }

            return(result);
        }
示例#2
0
        private ReportAnalysisModel CollateReportData(List <CSVResponse> reportData)
        {
            ReportAnalysisModel report = new ReportAnalysisModel();

            SurveyQuestionsService service = new SurveyQuestionsService();

            List <QuestionDataModel> questionData = service.GetSurveyQuestions(reportData[0].SurveyID);

            foreach (QuestionDataModel question in questionData)
            {
                report.Responses.Add(new ReportResponseAnalysis()
                {
                    QuestionNumber = question.QuestionNumber,
                    Question       = question.Question,
                    Type           = question.Type,
                    Options        = question.Options
                });
            }

            Dictionary <string, int>          multiChoiceAnalysis = null;
            Dictionary <string, int>          rangeAnalysis       = null;
            Dictionary <string, int>          stringAnalysis      = null;
            Dictionary <string, int>          rankAnalysis        = null;
            Dictionary <string, int>          numericAnalysis     = null;
            List <QuestionAnalysisCollection> surveyAnalysis      = new List <QuestionAnalysisCollection>();

            int questionNum = 1;

            do
            {
                multiChoiceAnalysis = new Dictionary <string, int>();
                rangeAnalysis       = new Dictionary <string, int>();
                stringAnalysis      = new Dictionary <string, int>();
                rankAnalysis        = new Dictionary <string, int>();
                numericAnalysis     = new Dictionary <string, int>();

                foreach (CSVResponse responseData in reportData)
                {
                    foreach (var response in responseData.Responses)
                    {
                        if (response.QuestionNumber == questionNum)
                        {
                            string questionType = questionData.Find(o => o.QuestionNumber == response.QuestionNumber).Type;

                            switch (questionType.ToLower())
                            {
                            case "mq":
                                if (multiChoiceAnalysis.ContainsKey(response.Answer))
                                {
                                    multiChoiceAnalysis[response.Answer]++;
                                }
                                else
                                {
                                    multiChoiceAnalysis.Add(response.Answer, 1);
                                }
                                break;

                            case "range":
                                if (rangeAnalysis.ContainsKey(response.Answer))
                                {
                                    rangeAnalysis[response.Answer]++;
                                }
                                else
                                {
                                    rangeAnalysis.Add(response.Answer, 1);
                                }
                                break;

                            case "ni":
                                if (numericAnalysis.ContainsKey(response.Answer))
                                {
                                    numericAnalysis[response.Answer]++;
                                }
                                else
                                {
                                    numericAnalysis.Add(response.Answer, 1);
                                }
                                break;

                            case "rank":
                                if (rankAnalysis.ContainsKey(response.Answer))
                                {
                                    rankAnalysis[response.Answer]++;
                                }
                                else
                                {
                                    rankAnalysis.Add(response.Answer, 1);
                                }
                                break;

                            case "comment":
                            case "text":
                                if (stringAnalysis.ContainsKey(response.Answer))
                                {
                                    stringAnalysis[response.Answer]++;
                                }
                                else
                                {
                                    stringAnalysis.Add(response.Answer, 1);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                if (multiChoiceAnalysis.Count > 0)
                {
                    surveyAnalysis.Add(new QuestionAnalysisCollection {
                        QuestionType = "mq", QuestionNumber = questionNum, Summary = multiChoiceAnalysis
                    });
                }
                else if (rangeAnalysis.Count > 0)
                {
                    surveyAnalysis.Add(new QuestionAnalysisCollection {
                        QuestionType = "range", QuestionNumber = questionNum, Summary = rangeAnalysis
                    });
                }
                else if (rankAnalysis.Count > 0)
                {
                    surveyAnalysis.Add(new QuestionAnalysisCollection {
                        QuestionType = "rank", QuestionNumber = questionNum, Summary = rankAnalysis
                    });
                }
                else if (stringAnalysis.Count > 0)
                {
                    surveyAnalysis.Add(new QuestionAnalysisCollection {
                        QuestionType = "text", QuestionNumber = questionNum, Summary = stringAnalysis
                    });
                }
                else if (numericAnalysis.Count > 0)
                {
                    surveyAnalysis.Add(new QuestionAnalysisCollection {
                        QuestionType = "ni", QuestionNumber = questionNum, Summary = numericAnalysis
                    });
                }

                questionNum++;
            } while (questionNum <= questionData.Count);

            report = AnalyseReport(report, surveyAnalysis);

            return(report);
        }