public IEnumerable <Series> GetSeriesByHourMean(SeriesQuery queryModel)
        {
            using (var session = _store.OpenSession()) {
                string orderDirection = queryModel.OrderBy == Ordering.Ascending ? "asc" : "desc";

                var series = session.Query <SeriesByMeanResult>(
                    $@"select json_build_object('Group', data->>'Group', 'Tag', data->>'Tag', 'Time', date_trunc('hour',CAST(data->>'Time' as timestamp)), 'Value' ,(SUM( CAST(data->>'Value' as real )) / COUNT(*)))
                    FROM public.mt_doc_series AS d
                    WHERE (date_trunc('hour', CAST(data->>'Time' as timestamp)) >= :Start
	                    AND date_trunc('hour', CAST(data->>'Time' as timestamp)) <= :End
	                    AND d.data ->> 'Tag' = :Tag
	                    AND d.data ->> 'Group' = :Group)
                    GROUP BY data->>'Group', data->>'Tag', date_trunc('hour',CAST(data->>'Time' as timestamp))
                    ORDER BY date_trunc('hour',CAST(data->>'Time' as timestamp)) {orderDirection}
                   LIMIT :Limit",
                    new {
                    queryModel.Group,
                    queryModel.Tag,
                    queryModel.Start,
                    queryModel.End,
                    Limit = queryModel.MaxValues
                });
                return(series.Select(group => new Series {
                    Group = group.Group,
                    Tag = group.Tag,
                    Time = group.Time,
                    Value = group.Value.ToString(CultureInfo.InvariantCulture)
                }));
            }
        }
예제 #2
0
        public IEnumerable <Series> GetSeriesByHourMean(SeriesQuery queryModel)
        {
            using (var session = _store.OpenSession()) {
                var query = session.Query <SeriesByHourIndex.Result, SeriesByHourIndex>()
                            .Where(x => x.Date >= queryModel.Start &&
                                   x.Date <= queryModel.End &&
                                   x.Tag == queryModel.Tag &&
                                   x.Group == queryModel.Group);

                if (queryModel.OrderBy == Ordering.Ascending)
                {
                    query = query.OrderBy(x => x.Date);
                }
                else
                {
                    query = query.OrderByDescending(x => x.Date);
                }

                query = query.Take(queryModel.MaxValues);

                return(query.ToList().Select(x => new Series {
                    Group = x.Group,
                    Tag = x.Tag,
                    Time = x.Date,
                    Value = x.MeanValue.ToString(CultureInfo.InvariantCulture)
                }));
            }
        }
예제 #3
0
        public async Task <IActionResult> Index([FromQuery] SeriesQuery query)
        {
            Enum.TryParse(query.SeriesType, true, out ArticleSeriesType seriesType);
            ViewData["SeriesType"] = seriesType;

            string userId = this.GetViewerUserId();
            var    series = await _articleService.GetSeries(userId, seriesType).CAF();

            return(View("ManySeries", new ManySeriesViewModel
            {
                Series = series
            }));
        }
예제 #4
0
        public IEnumerable <Series> Get(DateTime start, DateTime end, string group, string tag, string meanValueType = null)
        {
            var query = new SeriesQuery {
                Start         = start,
                End           = end,
                Group         = group,
                Tag           = tag,
                MaxValues     = 1024,
                OrderBy       = Ordering.Ascending,
                MeanValueType = meanValueType
            };

            return(_collectorService.GetSeries(query));
        }
예제 #5
0
        public override VerifyResult Verify(Verifier verifier, Series series)
        {
            var typedVerifier = verifier as SeriesChangedVerifier;

            if (typedVerifier == null)
            {
                return new VerifyResult {
                           Successful = false
                }
            }
            ;
            if (verifier.Notifications == null || !verifier.Notifications.Any())
            {
                return new VerifyResult {
                           Successful = false
                }
            }
            ;

            var query = new SeriesQuery {
                Group     = typedVerifier.Group,
                Tag       = typedVerifier.Tag,
                End       = series.Time.Subtract(TimeSpan.FromMilliseconds(1)).Subtract(typedVerifier.TimeInterval),
                Start     = DateTime.MinValue,
                OrderBy   = Ordering.Descanding,
                MaxValues = 1
            };
            var seriesResult = SeriesRepository.GetSeries(query)
                               .FirstOrDefault();

            return(new VerifyResult {
                Successful = seriesResult != null && seriesResult.Value != series.Value,
                NotificationShortDescription = $"Series '{typedVerifier.Group}:{typedVerifier.Tag}' changed",
                NotificationLongDescription = $"Series '{series.Id}' with '{typedVerifier.Group}:{typedVerifier.Tag}:{series.Value}' has changed to {seriesResult?.Value} within the time interval {typedVerifier.TimeInterval}"
            });
        }
    }
}
        public IEnumerable <Series> GetSeries(SeriesQuery queryModel)
        {
            using (var session = _store.OpenSession()) {
                var query = session.Query <Series>()
                            .Where(x => x.Time >= queryModel.Start &&
                                   x.Time <= queryModel.End &&
                                   x.Tag == queryModel.Tag &&
                                   x.Group == queryModel.Group);

                if (queryModel.OrderBy == Ordering.Ascending)
                {
                    query = query.OrderBy(x => x.Time);
                }
                else
                {
                    query = query.OrderByDescending(x => x.Time);
                }

                query = query.Take(queryModel.MaxValues);

                return(query);
            }
        }
예제 #7
0
        public IEnumerable <Series> GetSeries(SeriesQuery query)
        {
            var unescapedQuery = new SeriesQuery {
                Start         = query.Start,
                End           = query.End,
                MaxValues     = query.MaxValues,
                OrderBy       = query.OrderBy,
                Group         = Uri.UnescapeDataString(query.Group),
                Tag           = Uri.UnescapeDataString(query.Tag),
                MeanValueType = query.MeanValueType == null ? "" : query.MeanValueType
            };

            switch (unescapedQuery.MeanValueType.Trim().ToLower())
            {
            case "day":
                return(_seriesQueryRepository.GetSeriesByDayMean(unescapedQuery));

            case "hour":
                return(_seriesQueryRepository.GetSeriesByHourMean(unescapedQuery));

            default:
                return(_seriesQueryRepository.GetSeries(unescapedQuery));
            }
        }