Example #1
0
		public ExceptionsCountViewModel(ExceptionsCount model)
		{
			if (model == null) throw new ArgumentNullException(nameof(model));

			this.Model = model;
			this.Count = model.Count;
			this.CreatedAtFormatted = model.DateTime.ToString(@"d");
		}
Example #2
0
        public static IEnumerable<ExceptionsCount> GetExceptionsCounts(ExceptionsDataLoadParams dataLoadParams)
        {
            if (dataLoadParams == null) throw new ArgumentNullException(nameof(dataLoadParams));

            var query = @"
            SELECT CREATED_AT FROM FEATURE_EXCEPTION_ENTRIES
            WHERE (@VERSION IS NULL OR VERSION_ID = @VERSION)
            AND (@FROMDATE <= CREATED_AT AND CREATED_AT <= @TODATE)";

            if (dataLoadParams.Settings.RemoveExcluded)
            {
                query = @"
                SELECT CREATED_AT FROM FEATURE_EXCEPTION_ENTRIES E
                WHERE (@VERSION IS NULL OR VERSION_ID = @VERSION)
                AND (@FROMDATE <= CREATED_AT AND CREATED_AT <= @TODATE)
                AND NOT EXISTS (SELECT 1 FROM FEATURE_EXCEPTIONS_EXCLUDED EX WHERE E.EXCEPTION_ID = EX.EXCEPTION_ID)";
            }

            var versionId = default(long?);
            var version = dataLoadParams.Version;
            if (version != null)
            {
                var value = version.Row.Id;
                if (value > 0)
                {
                    versionId = value;
                }
            }

            var toDate = DateTime.Now;
            var timePeriodRow = dataLoadParams.TimePeriod.Row;
            var fromDate = toDate.Add(-timePeriodRow.TimeOffset);

            var sqlParams = new[]
            {
                new QueryParameter(@"@VERSION", versionId),
                new QueryParameter(@"@FROMDATE", fromDate),
                new QueryParameter(@"@TODATE", toDate),
            };

            var bukets = new int[timePeriodRow.ChartSamples];
            var interval = (toDate - fromDate).TotalSeconds / bukets.Length;

            var _ = new Dictionary<int, int>(0);
            dataLoadParams.Context.Fill(_, (r, m) =>
            {
                bukets[Math.Min((int)(Math.Round((toDate - r.GetDateTime(0)).TotalSeconds / interval, MidpointRounding.AwayFromZero)), bukets.Length - 1)]++;
            }, new Query(query, sqlParams));

            var counts = new ExceptionsCount[bukets.Length];
            for (var i = 0; i < bukets.Length; i++)
            {
                counts[i] = new ExceptionsCount(fromDate.AddSeconds(interval * i), bukets[bukets.Length - 1 - i]);
            }

            return counts;
        }