public ProjectErrorStatsResult GetByProject(string projectId, DateTime?start = null, DateTime?end = null, int page = 1, int pageSize = 10, bool hidden = false, bool @fixed = false, bool notfound = true)
        {
            if (String.IsNullOrEmpty(projectId))
            {
                throw new ArgumentNullException("projectId"); // TODO: These should probably throw http Response exceptions.
            }
            Project project = _projectRepository.GetByIdCached(projectId);

            if (project == null || !User.CanAccessOrganization(project.OrganizationId))
            {
                throw new ArgumentException("Invalid project id.", "projectId"); // TODO: These should probably throw http Response exceptions.
            }
            DateTime retentionUtcCutoff    = _organizationRepository.GetByIdCached(project.OrganizationId).GetRetentionUtcCutoff();
            ProjectErrorStatsResult result = _statsHelper.GetProjectErrorStats(projectId, _projectRepository.GetDefaultTimeOffset(projectId), start, end, retentionUtcCutoff, hidden, @fixed, notfound);

            result.MostFrequent = Frequent(result.MostFrequent.Results, result.TotalLimitedByPlan, page, pageSize);
            result.MostRecent   = Recent(projectId, page, pageSize, start, end, hidden, @fixed, notfound);

            return(result);
        }
        public void CanAggregateStatsOverSmallTime()
        {
            TimeSpan  timeOffset = _projectRepository.GetDefaultTimeOffset(TestConstants.ProjectId);
            DateTime  startDate  = DateTime.UtcNow.Add(timeOffset).Date;
            DateTime  endDate    = DateTime.UtcNow.Add(timeOffset).Date.AddMinutes(5);
            const int count      = 25;

            List <Error> errors = ErrorData.GenerateErrors(count, startDate: startDate, endDate: endDate, errorStackId: TestConstants.ErrorStackId, projectId: TestConstants.ProjectId, timeZoneOffset: timeOffset).ToList();

            _errorPipeline.Run(errors);

            var info = _errorStatsHelper.GetProjectErrorStats(TestConstants.ProjectId, timeOffset, startDate, endDate);

            Assert.Equal(count, info.Total);
            Assert.Equal(1, info.UniqueTotal);
            Assert.Equal(0, info.NewTotal);
            //Assert.Equal(1, info.Stats.Count);
            Assert.Equal(count, info.Stats.Sum(ds => ds.Total));
            Assert.True(info.Stats.All(ds => ds.UniqueTotal <= 1));
            Assert.Equal(0, info.Stats.Sum(ds => ds.NewTotal));
        }
Exemple #3
0
        private object ProcessSummaryNotification(IMessage <SummaryNotification> message)
        {
            var project      = _projectRepository.GetByIdCached(message.GetBody().Id);
            var organization = _organizationRepository.GetByIdCached(project.OrganizationId);
            var userIds      = project.NotificationSettings.Where(n => n.Value.SendDailySummary).Select(n => n.Key).ToList();

            if (userIds.Count == 0)
            {
                return(null);
            }

            var users = _userRepository.GetByIds(userIds).Where(u => u.IsEmailAddressVerified).ToList();

            if (users.Count == 0)
            {
                return(null);
            }

            long count;
            List <ErrorStack> newest = _stackRepository.GetNew(project.Id, message.GetBody().UtcStartTime, message.GetBody().UtcEndTime, 0, 5, out count).ToList();

            DateTime start        = _projectRepository.UtcToDefaultProjectLocalTime(project.Id, message.GetBody().UtcStartTime);
            DateTime end          = _projectRepository.UtcToDefaultProjectLocalTime(project.Id, message.GetBody().UtcEndTime);
            var      result       = _errorStatsHelper.GetProjectErrorStats(project.Id, _projectRepository.GetDefaultTimeOffset(project.Id), start, end);
            var      mostFrequent = result.MostFrequent.Results.Take(5).ToList();
            var      errorStacks  = _stackRepository.GetByIds(mostFrequent.Select(s => s.Id));

            foreach (var frequent in mostFrequent)
            {
                var stack = errorStacks.SingleOrDefault(s => s.Id == frequent.Id);
                if (stack == null)
                {
                    mostFrequent.RemoveAll(r => r.Id == frequent.Id);
                    continue;
                }

                // Stat's Id and Total properties are already calculated in the Results.
                frequent.Type   = stack.SignatureInfo.ContainsKey("ExceptionType") ? stack.SignatureInfo["ExceptionType"] : null;
                frequent.Method = stack.SignatureInfo.ContainsKey("Method") ? stack.SignatureInfo["Method"] : null;
                frequent.Path   = stack.SignatureInfo.ContainsKey("Path") ? stack.SignatureInfo["Path"] : null;
                frequent.Is404  = stack.SignatureInfo.ContainsKey("Path");

                frequent.Title = stack.Title;
                frequent.First = stack.FirstOccurrence;
                frequent.Last  = stack.LastOccurrence;
            }

            var notification = new SummaryNotificationModel {
                ProjectId          = project.Id,
                ProjectName        = project.Name,
                StartDate          = start,
                EndDate            = end,
                Total              = result.Total,
                PerHourAverage     = result.PerHourAverage,
                NewTotal           = result.NewTotal,
                New                = newest,
                UniqueTotal        = result.UniqueTotal,
                MostFrequent       = mostFrequent,
                HasSubmittedErrors = project.TotalErrorCount > 0,
                IsFreePlan         = organization.PlanId == BillingManager.FreePlan.Id
            };

            foreach (var user in users.Where(u => u.EmailNotificationsEnabled))
            {
                _mailer.SendSummaryNotification(user.EmailAddress, notification);
            }

            return(null);
        }