private List <ThermometerExData> GetThermometerWithBulletinData(string userToken, string culture = "en", bool isTesting = false) { float hv = 4.5f, av = 3.5f, rv = 6.5f, iv = 7.5f, xv = 2.5f; if (isTesting) { var context = new EsmContext(); hv = (float)(from a in context.Answers join b in context.Options on a.ChoiceId equals b.ChoiceId join c in context.Questionnairs on a.QuestionnairId equals c.QuestionnairId where a.RespondentKey == userToken && c.QuestionairCode == "B01" select b.Value).Average(); av = (float)(from a in context.Answers join b in context.Options on a.ChoiceId equals b.ChoiceId join c in context.Questionnairs on a.QuestionnairId equals c.QuestionnairId where a.RespondentKey == userToken && c.QuestionairCode == "B02" select b.Value).Average(); rv = (float)(from a in context.Answers join b in context.Options on a.ChoiceId equals b.ChoiceId join c in context.Questionnairs on a.QuestionnairId equals c.QuestionnairId where a.RespondentKey == userToken && c.QuestionairCode == "B03" select b.Value).Average(); iv = (float)(from a in context.Answers join b in context.Options on a.ChoiceId equals b.ChoiceId join c in context.Questionnairs on a.QuestionnairId equals c.QuestionnairId where a.RespondentKey == userToken && c.QuestionairCode == "B04" select b.Value).Average(); xv = (float)(from a in context.Answers join b in context.Options on a.ChoiceId equals b.ChoiceId join c in context.Questionnairs on a.QuestionnairId equals c.QuestionnairId where a.RespondentKey == userToken && c.QuestionairCode == "B05" select b.Value).Average(); } return(new List <ThermometerExData> { new ThermometerExData { Label = "Happy", Color = Color.LightGreen, Value = hv, ExtraHigh = 36, ExtraLow = 63 }, new ThermometerExData { Label = "Awake", Color = Color.LightPink, Value = av, ExtraHigh = 39, ExtraLow = 54 }, new ThermometerExData { Label = "Relaxed", Color = Color.LightSalmon, Value = rv, ExtraHigh = 54, ExtraLow = 47 }, new ThermometerExData { Label = "InControl", Color = Color.LightSkyBlue, Value = iv, ExtraHigh = 43, ExtraLow = 27 }, new ThermometerExData { Label = "Anxious", Color = Color.LightPink, Value = xv, ExtraHigh = 37, ExtraLow = 58 } }); }
public ActionResult RemoveRespondant(string userToken) { var context = new EsmContext(); var list = context.Answers.Where(x => x.RespondentKey == userToken).ToList(); context.Answers.RemoveRange(list); context.SaveChanges(); return(View()); }
public ActionResult SaveSurvey(string userToken, string notificationId, int questionId, int answerId, string answerIdStr = "", string userInput = "", string culture = "en") { var context = new EsmContext(); var isOtherInput = false; if (answerIdStr.EndsWith(",")) { answerIdStr = answerIdStr.Substring(0, answerIdStr.Length - 1); } if (userInput.EndsWith(",")) { userInput = userInput.Substring(0, userInput.Length - 1); } var q = context.Questionnairs.First(x => x.QuestionnairId == questionId);//q never be null var answer = new Answer { RespondentKey = userToken, NotificationId = notificationId, QuestionnairId = questionId, ChoiceId = answerId, ResponseDate = DateTime.Now }; switch (q.QuestionType) { case QuestionType.MultipleChoice: //do something later break; case QuestionType.MultipleChoiceWithOtherInput: var multipleChoices = (from s in answerIdStr.Split(',') select int.Parse(s)).ToList(); //do something later break; case QuestionType.MultiInput: //do something later break; default: //do something later break; } if (answerId != 0) { isOtherInput = context.Options.First(x => x.ChoiceId == answerId).IsUserInput; } if (!isOtherInput) { userInput = ""; } int surveyType = 1; if (q != null) { surveyType = (int)q.SurveyType; } answer.ChoicesIdStr = answerIdStr; answer.ChoiceId = answerId; answer.SurveyType = (int)q.SurveyType; answer.TheUserInputAnswer = userInput; context.Answers.Add(answer); context.SaveChanges(); return(RedirectToAction("ConductSurvey", new { userToken = userToken, notificationId = notificationId, culture = culture })); }
public ActionResult ConductSurvey(string userToken, string notificationId, string culture = "en") { var context = new EsmContext(); var aCount = context.Answers.Count(x => x.RespondentKey == userToken && x.SurveyType == (int)SurveyType.QuestionnaireA); var bCount = 0; var supportCount = context.Answers.Count(x => x.RespondentKey == userToken && x.SurveyType == (int)SurveyType.Supportive); if (string.IsNullOrEmpty(notificationId)) { notificationId = DateTime.Now.ToString(); } else { bCount = context.Answers.Count(x => x.RespondentKey == userToken && x.NotificationId == notificationId && x.SurveyType == (int)SurveyType.QuestionnairB); } var question = new Questionnair(); string percentage = ""; if (aCount < 11) { percentage = $"({Math.Round((double)(aCount+1)/(11+9)*100)}%)"; question = context.Questionnairs.Where(x => x.SurveyType == SurveyType.QuestionnaireA).OrderBy(x => x.QuestionnairId).Skip(aCount).FirstOrDefault(); } else if (bCount < 9) { percentage = $"({Math.Round((double)(aCount +bCount+ 1) / (11 + 9)*100)}%)"; question = context.Questionnairs.Where(x => x.SurveyType == SurveyType.QuestionnairB).OrderBy(x => x.QuestionnairId).Skip(bCount).FirstOrDefault(); } else if (supportCount < 3) { percentage = $"(100%+Extra:{Math.Round((double)(supportCount + 1) /3*100)}%)"; question = context.Questionnairs.Where(x => x.SurveyType == SurveyType.Supportive).OrderBy(x => x.QuestionnairId).Skip(supportCount).FirstOrDefault(); } var model = new QuestionModel { UserToken = userToken, NotificationId = notificationId, Culture = culture }; if (question == null) { model.Message = culture == "fr" ? "Vous avez fait l'enquête pour cette fois, merci" : "You have done the survey for this time, Thanks"; model.QuestionnairId = 0; } else { model.Type = (int)question.QuestionType; model.HelpDesc = culture == "fr"?question.HelpDescFre: question.HelpDescEng; question.Choices = context.Options.Where(x => x.QuestionnairId == question.QuestionnairId).ToList(); model.Text = culture == "en" ? question.EnglishName : question.FrenchName; model.QuestionnairId = question.QuestionnairId; model.Choices = (from c in question.Choices select new ChoiceModel { ChoiceId = c.ChoiceId, IsUserInput = c.IsUserInput, Text = culture == "en" ? c.EnglishName : c.FrenchName }).ToList(); model.Percentage = percentage; } return(View(model)); }
private List <BarDataSingle> GetBarData(string userToken, string culture = "en", bool isTesting = false) { if (isTesting) { var context = new EsmContext(); var list = (from a in context.Answers join b in context.Questionnairs on a.QuestionnairId equals b.QuestionnairId join c in context.Options on a.ChoiceId equals c.ChoiceId where b.QuestionairCode == "B06" select c).ToList(); } return(new List <BarDataSingle> { new BarDataSingle { Label = "Media Consumption", Color = Color.Aqua, Value = 8 }, new BarDataSingle { Label = "Attending a ciname,exhibition,libray,concert,Theretre,entertainment event", Color = Color.Aquamarine, Value = 6 }, new BarDataSingle { Label = "Creative Hobbies", Color = Color.Azure, Value = 5 }, new BarDataSingle { Label = "Being Active", Color = Color.Beige, Value = 2 }, new BarDataSingle { Label = "Socializing", Color = Color.Blue, Value = 4 }, new BarDataSingle { Label = "Chores", Color = Color.Red, Value = 7 }, new BarDataSingle { Label = "Other", Color = Color.ForestGreen, Value = 1 }, new BarDataSingle { Label = "Work and school", Color = Color.LightGoldenrodYellow, Value = 3 }, new BarDataSingle { Label = "Personal care", Color = Color.Gold, Value = 4 }, }); }
private TableData GetTableData(string userToken, string culture = "en", bool isTesting = false) { if (isTesting) { var context = new EsmContext(); //B06:Location B01:Feel ;1:Very happy+ 2:Happy var listHappy = (from a in context.Answers join b in context.Questionnairs on a.QuestionnairId equals b.QuestionnairId join c in context.Options on a.ChoiceId equals c.ChoiceId join d in context.Answers on a.NotificationId equals d.NotificationId join e in context.Questionnairs on d.QuestionnairId equals e.QuestionnairId join f in context.Options on d.ChoiceId equals f.ChoiceId where b.QuestionairCode == "B06" && e.QuestionairCode == "B01" && (f.Value == 1 || f.Value == 2) select c).ToList(); } return(new TableData { Header = new List <TableHeader> { new TableHeader { Text = "Location", Alignment = CellAlignment.Left, WidthRatio = 0.3F }, new TableHeader { Text = "Happy" }, new TableHeader { Text = "Relaxed" }, new TableHeader { Text = "Awake" }, new TableHeader { Text = "In Control" }, new TableHeader { Text = "Anxious" } }, Rows = new List <TableRow> { new TableRow { Cells = new List <string> { "Sports center,community center,field or arena", "5.73", "5.55", "5.73", "5.55", "4.64" } }, new TableRow { Cells = new List <string> { "Restaurant, bar or club", "5.73", "5.55", "5.73", "5.55", "4.64" } }, new TableRow { Cells = new List <string> { "Place of worship", "5.73", "5.55", "5.73", "5.55", "4.64" } }, new TableRow { Cells = new List <string> { "Outdoors", "5.73", "5.55", "5.73", "5.55", "4.64" } }, new TableRow { Cells = new List <string> { "Medicl,dental or other health clinic", "5.73", "5.55", "5.73", "5.55", "4.64" } }, new TableRow { Cells = new List <string> { "Other", "5.73", "5.55", "5.73", "5.55", "4.64" } } } }); }
private List <GridChartData> GetChartDataForScalableLine(string userToken, string culture = "en", bool isTesting = false) { if (isTesting) { var context = new EsmContext(); //B07:Activity B01:Feel ;1:Very happy+ 2:Happy var listHappy = (from a in context.Answers join b in context.Questionnairs on a.QuestionnairId equals b.QuestionnairId join c in context.Options on a.ChoiceId equals c.ChoiceId join d in context.Answers on a.NotificationId equals d.NotificationId join e in context.Questionnairs on d.QuestionnairId equals e.QuestionnairId join f in context.Options on d.ChoiceId equals f.ChoiceId where b.QuestionairCode == "B07" && e.QuestionairCode == "B01" && (f.Value == 1 || f.Value == 2) select c).ToList(); } return(new List <GridChartData> { new GridChartData { RowHeader = new Legend { Text = "Feeling Happy", Color = Color.Green }, Columns = new List <ColumnData> { new ColumnData { ColumnHeader = "Chores", Value = 2.3 }, new ColumnData { ColumnHeader = "Personal Care", Value = 1.4 }, new ColumnData { ColumnHeader = "Creative Hobbies", Value = 3.4 }, new ColumnData { ColumnHeader = "Work and School", Value = 2.8 }, new ColumnData { ColumnHeader = "Going to Places and Events", Value = 8.4 }, new ColumnData { ColumnHeader = "Socializing", Value = 4.1 }, new ColumnData { ColumnHeader = "Being Active", Value = 5.2 }, new ColumnData { ColumnHeader = "Media Consumption", Value = 3.7 }, new ColumnData { ColumnHeader = "Other", Value = 7.4 } } }, new GridChartData { RowHeader = new Legend { Text = "Feeling Relax", Color = Color.BlueViolet }, Columns = new List <ColumnData> { new ColumnData { ColumnHeader = "Chores", Value = 3.3 }, new ColumnData { ColumnHeader = "Personal Care", Value = 4.4 }, new ColumnData { ColumnHeader = "Creative Hobbies", Value = 5.4 }, new ColumnData { ColumnHeader = "Work and School", Value = 1.0 }, new ColumnData { ColumnHeader = "Going to Places and Events", Value = 2.4 }, new ColumnData { ColumnHeader = "Socializing", Value = 6.1 }, new ColumnData { ColumnHeader = "Being Active", Value = 7.2 }, new ColumnData { ColumnHeader = "Media Consumption", Value = 8.8 }, new ColumnData { ColumnHeader = "Other", Value = 9.4 } } }, new GridChartData { RowHeader = new Legend { Text = "Feeling Anxious", Color = Color.Red }, Columns = new List <ColumnData> { new ColumnData { ColumnHeader = "Chores", Value = 7.3 }, new ColumnData { ColumnHeader = "Personal Care", Value = 8.4 }, new ColumnData { ColumnHeader = "Creative Hobbies", Value = 6.4 }, new ColumnData { ColumnHeader = "Work and School", Value = 5.2 }, new ColumnData { ColumnHeader = "Going to Places and Events", Value = 4.4 }, new ColumnData { ColumnHeader = "Socializing", Value = 3.1 }, new ColumnData { ColumnHeader = "Being Active", Value = 2.2 }, new ColumnData { ColumnHeader = "Media Consumption", Value = 1.8 }, new ColumnData { ColumnHeader = "Other", Value = 2.4 } } } }); }