コード例 #1
0
        private long[][] WorkOutCumulativeVotes(IEnumerable <DateTimeVoteModel> votesPerDay)
        {
            int totalVotes            = 0;
            var cumulativeVotesPerDay = new List <DateTimeVoteModel>();

            foreach (var dateTimeVoteModel in votesPerDay)
            {
                totalVotes += dateTimeVoteModel.VoteCount;
                var model = new DateTimeVoteModel {
                    Date = dateTimeVoteModel.Date, VoteCount = totalVotes
                };
                cumulativeVotesPerDay.Add(model);
            }

            var cumulativeVotesPerDayData = chartDataConverter.ToChartData(cumulativeVotesPerDay, v => v.Date.GetJavascriptTimestamp());

            return(cumulativeVotesPerDayData);
        }
コード例 #2
0
        public IList <DateTimeVoteModel> GetVotesPerHour()
        {
            var dateToCountDictionary = voteRepository.GetAllVotes()
                                        .GroupBy(v => v.TimeRecorded.TimeOfDay.Hours)
                                        .ToDictionary(g => g.Key, g => g.Count());

            var dateTimeVoteModels = new List <DateTimeVoteModel>();

            for (var hour = 0; hour < 24; hour++)
            {
                int count;
                dateToCountDictionary.TryGetValue(hour, out count);
                var now   = DateTime.UtcNow;
                var time  = new DateTime(now.Year, now.Month, now.Day, hour, 0, 0, 0);
                var model = new DateTimeVoteModel {
                    Date = time, VoteCount = count
                };
                dateTimeVoteModels.Add(model);
            }

            return(dateTimeVoteModels);
        }
コード例 #3
0
        public IList <DateTimeVoteModel> GetVotesPerDate()
        {
            var dateToCountDictionary = voteRepository.GetAllVotes()
                                        .GroupBy(v => v.TimeRecorded.Date)
                                        .ToDictionary(g => g.Key, g => g.Count());

            var votingStartDate    = GetVotingStartDate();
            var votingEndDate      = GetVotingEndDate();
            var dateTimeVoteModels = new List <DateTimeVoteModel>();

            for (var day = votingStartDate.Date; day <= votingEndDate; day = day.AddDays(1))
            {
                int count;
                dateToCountDictionary.TryGetValue(day, out count);
                var model = new DateTimeVoteModel
                {
                    Date      = day,
                    VoteCount = count
                };
                dateTimeVoteModels.Add(model);
            }

            return(dateTimeVoteModels);
        }