示例#1
0
        public static string GetAnalizedPollData(long ownerid, string ownerType, long pollId)
        {
            AnalysePollData pollData = GetAnalizedPollDataModel(ownerid, ownerType, pollId);

            if (pollData == null)
            {
                return(Helper.GetResult(false, "0x0012"));
            }
            return(Helper.GetResult(true, pollData));
        }
示例#2
0
        public static AnalysePollData GetAnalizedPollDataModel(long ownerid, string ownerType, long pollId)
        {
            poll pollMaster =
                EntityConnectionService.Poll.GetSingle(x => x.pollid.Equals(pollId) && x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType));

            if (pollMaster == null)
            {
                return(null);
            }

            Stopwatch analyseStopwatch = new Stopwatch();

            analyseStopwatch.Start();

            List <question> questionList =
                EntityConnectionService.Question.GetList(
                    x =>
                    x.pollid.Equals(pollId) && x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType)).ToList();

            PollModel poll = new PollModel();

            poll.PollId    = pollMaster.pollid;
            poll.PollTitle = pollMaster.polltitle;
            poll.Questions = new List <Question>();
            poll.Fields    = pollMaster.fielddata;
            poll.Active    = pollMaster.active;
            for (int i = 0; i < questionList.Count; i++)
            {
                Question localQuestion = new Question
                {
                    Content      = questionList[i].content,
                    QuestionId   = questionList[i].questionid,
                    QuestionType = questionList[i].questiontype,
                    Answers      = new List <Answer>()
                };

                localQuestion.VoteCount =
                    EntityConnectionService.GuestAnswer.GetDataCount(
                        x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId) && x.questionid.Equals(localQuestion.QuestionId));

                List <answer> answerList =
                    EntityConnectionService.Answer.GetList(
                        x =>
                        x.pollid.Equals(pollId) && x.questionid.Equals(localQuestion.QuestionId) &&
                        x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType)).ToList();

                for (int j = 0; j < answerList.Count; j++)
                {
                    Answer localAnswer = new Answer
                    {
                        AnswerId   = answerList[j].answerid,
                        Content    = answerList[j].content,
                        AnswerType = answerList[j].answertype
                    };
                    localAnswer.VoteCount =
                        EntityConnectionService.GuestAnswer.GetDataCount(
                            x =>
                            x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.answerid.Equals(localAnswer.AnswerId) &&
                            x.questionid.Equals(localQuestion.QuestionId));
                    localQuestion.Answers.Add(localAnswer);
                }
                poll.Questions.Add(localQuestion);
            }

            AnalysePollData analysePoll = new AnalysePollData();

            analysePoll.GuestAnswers = new List <GuestAnswer>();
            var guestAnswerList = EntityConnectionService.GuestAnswer.GetList(
                x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId));

            for (int i = 0; i < guestAnswerList.Count; i++)
            {
                analysePoll.GuestAnswers.Add(new GuestAnswer()
                {
                    GuestId    = guestAnswerList[i].guestid,
                    AnswerId   = guestAnswerList[i].answerid,
                    QuestionId = guestAnswerList[i].questionid,
                });
            }
            analysePoll.Poll      = poll;
            analysePoll.GuestList =
                EntityConnectionService.Guest.GetDataPart(
                    x => x.ownerid.Equals(ownerid) && x.ownertype.Equals(ownerType) && x.pollid.Equals(pollId),
                    x => new { x.guestid, x.fielddata, x.crdat, x.crtim, x.complatesecond },
                    x => new { x.crdat, x.crtim }).ToList();

            int totalComplateSecond = 0;

            foreach (var guest in analysePoll.GuestList)
            {
                if (!string.IsNullOrEmpty(guest.complatesecond.ToString()))
                {
                    totalComplateSecond += int.Parse(guest.complatesecond.ToString());
                }
            }
            if (analysePoll.GuestList.Count > 0)
            {
                TimeSpan avarageTime = TimeSpan.FromSeconds(totalComplateSecond / analysePoll.GuestList.Count);
                analysePoll.AvarageComplateTime    = new DateTime(avarageTime.Ticks).ToStringHhmmss();
                analysePoll.AvarageComplateSeconds = (totalComplateSecond / analysePoll.GuestList.Count).ToString();
                analysePoll.TotalComplate          = analysePoll.GuestList.Count.ToString();
                analysePoll.TotalView       = pollMaster.viewcount.ToString();
                analysePoll.AnalyseDateTime = DateTime.Now.ToStringYyyyMMddHhmmss();
            }
            else
            {
                analysePoll.AvarageComplateTime    = "000000";
                analysePoll.AvarageComplateSeconds = "0";
                analysePoll.TotalComplate          = "0";
                analysePoll.TotalView       = "0";
                analysePoll.AnalyseDateTime = DateTime.Now.ToStringYyyyMMddHhmmss();
            }



            analyseStopwatch.Stop();
            analysePoll.AnalyseTime = string.Format("{0}:{1}:{2}.{3}", analyseStopwatch.Elapsed.Hours,
                                                    analyseStopwatch.Elapsed.Minutes, analyseStopwatch.Elapsed.Seconds,
                                                    analyseStopwatch.Elapsed.Milliseconds);

            Log.Info(string.Format("Analyse Time :{0}", analysePoll.AnalyseTime));
            return(analysePoll);
        }