Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public string Build(string root, Time.Range r)
        {
            var list = this
                       .Where(x => x.Params?.Length > 0)
                       .ToList();

            var groupByTime = list.FirstOrDefault(x => x.Type == GroupBy.Kind.Time);

            var groupByFill = list.FirstOrDefault(x => x.Type == GroupBy.Kind.Fill);

            var groupByTag = list
                             .Where(x => x.Type == GroupBy.Kind.Tag)
                             .ToList();

            if (null != groupByTime)
            {
                var influxGroupBy = InfluxDateTimeHelper.GetGroupBy(r);

                //query = query.Replace( VmFilter.TIME_FILTER_KEY, influxFilter );

                //var gb = ( this.range ) ? this.getOptimalAutoGroupBy() : groupByTime.params[ 0 ];
                var gb = groupByTime.Params?[0];
                root = $"{root}	GROUP BY time({gb})";

                var groupByAutoIndex = root.IndexOf(GROUP_BY_AUTO_KEY);

                if (-1 != groupByAutoIndex)
                {
                    root = root.Replace(GROUP_BY_AUTO_KEY, influxGroupBy);                      // TODO
                }
            }

            if (groupByTag.Count > 0)
            {
                root = (null == groupByTime) ? $"{root} GROUP BY" : $"{root},";
                var index = 0;

                groupByTag
                .ForEach(e =>
                {
                    var i = index > 0 ? ", " : " ";
                    root  = $"{root}{i} \"{e.Params [ 0 ]}\"";
                    ++index;
                });
            }

            if (null != groupByFill)
            {
                root = $"{root} FILL({groupByFill.Params [ 0 ] })";
            }

            return(root);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private string RenderMeasurement(Time.Range r)
        {
            var meas = (string.IsNullOrEmpty(Measurement)) ? "measurement" : Measurement;

            var rp = (!string.IsNullOrEmpty(Policy) && Policy != "default") ? $"\"{Policy}\"." : "";

            var root = $"{rp}\"{meas}\"";

            var cond = Tags?.Build() ?? string.Empty;

            var timeFilter = InfluxDateTimeHelper.GetFilter(r);

            if (!string.IsNullOrEmpty(cond))
            {
                root = $"{root}	WHERE ({cond}) and {timeFilter}";
            }
            else
            {
                // TODO
                root = $"{root}	WHERE {timeFilter}";
            }

            if (null != GroupBy)
            {
                root = GroupBy?.Build(root, r);
            }

            if (Order != OrderByTime.Asc)
            {
                root = $"{root} ORDER BY time DESC";
            }

            if (Limit > 0)
            {
                root = $"{root}	LIMIT {Limit}";
            }

            if (SLimit > 0)
            {
                root = $"{root}	SLIMIT {SLimit}";
            }

            return(root);
        }