/// <summary> /// 后台大屏幕显示界面 /// </summary> /// <param name="pollingid"></param> /// <param name="questionid"></param> /// <returns></returns> public PollingScreenView GetPollingScreenData(int pollingid, int questionid) { // TODO: check performance var pollingScreenView = new PollingScreenView(); var query = _pollingResultService.Repository.Entities.Where( x => x.PollingId == pollingid && x.IsDeleted != true); var allAnswersQuery = query.Where(x => x.QuestionId == questionid).GroupBy(x => x.Answer) .Select(x => new { x.Key, count = x.Count() }).Future(); var totalQuery = query.Select(x => x.UserId.ToUpper()).Distinct().FutureCount(); var allAnswers = allAnswersQuery.ToList(); pollingScreenView.PollingTotal = totalQuery.Value;//最新的投票人数 var sereisLst = new List <SereisData>(); var allOptions = _pollingOptionService.Repository.Entities.Where(x => x.QuestionId == questionid && x.IsDeleted != true) .Select(x => new { Id = x.Id, OptionName = x.OptionName }).ToList(); var options = allOptions.AsParallel().Where(x => allAnswers.AsParallel().All(y => x.Id != y.Key)).Select(x => new SereisData { Sereisname = x.OptionName, Sereisvalue = 0, Id = x.Id }).ToList(); sereisLst.AddRange(options); allAnswers.ForEach(y => { int answer = y.Key; int optionCount = y.count; int perent = (optionCount * 100 / allAnswers.Sum(x => x.count)); var obj = new SereisData() { Sereisname = allOptions.Find(x => x.Id == answer).OptionName, Sereisvalue = perent, Id = answer }; sereisLst.Add(obj); }); pollingScreenView.SereisData = sereisLst.OrderBy(x => x.Id).ToList(); return(pollingScreenView); }
public JsonResult GetSeriesData(string id, int appId, string questionid) { var screenView = new PollingScreenView(); //根据qId去结果表里面算数据 if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(questionid)) { int pollingId = int.Parse(id); int quesId = int.Parse(questionid); screenView = _pollingService.GetPollingScreenData(pollingId, quesId); } return(Json(screenView, JsonRequestBehavior.AllowGet)); }
public PollingScreenView GetPollingScreenData(int pollingid, int questionid) { var pollingScreenView = new PollingScreenView(); var allAnswers = _pollingResultService.Repository.Entities.Where(x => x.PollingId == pollingid && x.QuestionId == questionid && x.IsDeleted != true) .Select(x => new { UserId = x.UserId, QuestionId = x.QuestionId, Answer = x.Answer, AnswerText = x.AnswerText }) .ToList(); var total = _pollingResultService.Repository.Entities.Where(x => x.PollingId == pollingid && x.IsDeleted != true) .Select(x => x.UserId.ToUpper()).Distinct().Count(); pollingScreenView.PollingTotal = total;//最新的投票人数 var sereisLst = new List <SereisData>(); var allOptions = _pollingOptionService.Repository.Entities.Where(x => x.QuestionId == questionid && x.IsDeleted != true) .Select(x => new { Id = x.Id, OptionName = x.OptionName }).ToList(); var options = allOptions.AsParallel().Where(x => allAnswers.AsParallel().All(y => x.Id != y.Answer)).Select(x => new SereisData { Sereisname = x.OptionName, Sereisvalue = 0 }).ToList(); sereisLst.AddRange(options); allAnswers.GroupBy(y => y.Answer).ToList().ForEach(y => { int answer = y.First().Answer; int optionCount = y.Count(); int perent = (optionCount * 100 / allAnswers.Count()); var obj = new SereisData() { Sereisname = allOptions.Find(x => x.Id == answer).OptionName, Sereisvalue = perent }; sereisLst.Add(obj); }); pollingScreenView.SereisData = sereisLst; return(pollingScreenView); }