QueryIntervalGroupAsync() public method

Returns items collected by time interval and group.
public QueryIntervalGroupAsync ( Keen.Core.Query.QueryType queryType, string collection, string targetProperty, string groupBy, QueryTimeframe timeframe, Keen.Core.Query.QueryInterval interval, IEnumerable filters = null, string timezone = "" ) : Task>>>>
queryType Keen.Core.Query.QueryType Type of query to run.
collection string Name of event collection to query.
targetProperty string Name of property to analyse.
groupBy string Name of field by which to group results.
timeframe QueryTimeframe Specifies window of time from which to select events for analysis. May be absolute or relative.
interval Keen.Core.Query.QueryInterval The block size for partitioning the specified timeframe. Optional, may be null.
filters IEnumerable Filters to narrow down the events used in analysis. Optional, may be null.
timezone string The timezone to use when specifying a relative timeframe. Optional, may be blank.
return Task>>>>
コード例 #1
0
ファイル: QueryTest.cs プロジェクト: kidchenko/keen-sdk-net
        public async void SelectUnique_ValidAbsoluteIntervalGroup_Success()
        {
            var client = new KeenClient(settingsEnv);
            var prop = "field1";
            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now.AddDays(-1), DateTime.Now);
            var interval = QueryInterval.EveryNHours(4);
            var groupby = "field1";
            var resultl = "hello,goodbye,I'm late";

            IEnumerable<QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>> result =
                new List<QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>>() 
                { 
                    new QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>(
                        new List<QueryGroupValue<string>>(){
                            new QueryGroupValue<string>(resultl, "abc"),
                            new QueryGroupValue<string>(resultl, "def")
                        }, 
                        timeframe.Start, timeframe.End
                        ),
                    new QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>(
                        new List<QueryGroupValue<string>>(){
                            new QueryGroupValue<string>(resultl, "abc"),
                            new QueryGroupValue<string>(resultl, "def")
                        }, 
                        timeframe.Start, timeframe.End
                        ),
                };

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric(
                        It.Is<QueryType>(q => q == QueryType.SelectUnique()),
                        It.Is<string>(c => c == testCol),
                        It.Is<string>(p => p == prop),
                        It.Is<string>(g => g == groupby),
                        It.Is<QueryAbsoluteTimeframe>(t => t == timeframe),
                        It.Is<QueryInterval>(i => i == interval),
                        It.Is<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<string>(t => t == "")
                        ))
                    .Returns(Task.FromResult(result));

                client.Queries = queryMock.Object;
            }

            var counts = (await client.QueryIntervalGroupAsync(QueryType.SelectUnique(), testCol, prop, groupby, timeframe, interval)).ToList();

            if (null != queryMock)
                queryMock.VerifyAll();
        }
コード例 #2
0
ファイル: QueryTest.cs プロジェクト: kidchenko/keen-sdk-net
        public async void Query_ValidRelativeGroupInterval_Success()
        {
            var client = new KeenClient(settingsEnv);
            var timeframe = QueryRelativeTimeframe.PreviousNDays(2);
            var interval = QueryInterval.EveryNHours(2);
            var groupby = "field1";

            IEnumerable<QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>> reply = new List<QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>>()
            {
                new QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>( 
                    new List<QueryGroupValue<string>>()
                    {
                        new QueryGroupValue<string>( "1", "field1" ),
                        new QueryGroupValue<string>( "1", "field1" ),
                    }, 
                    DateTime.Now, DateTime.Now.AddSeconds(2)
                ),
                new QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>( 
                    new List<QueryGroupValue<string>>()
                    {
                        new QueryGroupValue<string>( "2", "field1" ),
                        new QueryGroupValue<string>( "2", "field1" ),
                    }, 
                    DateTime.Now, DateTime.Now.AddSeconds(2)
                ),
            };

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric(
                        It.Is<QueryType>(q => q == QueryType.Count()),
                        It.Is<string>(c => c == testCol),
                        It.Is<string>(p => p == ""),
                        It.Is<string>(g => g == groupby),
                        It.Is<QueryTimeframe>(t => t == timeframe),
                        It.Is<QueryInterval>(i => i == interval),
                        It.Is<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<string>(z => z == "")))
                    .Returns(Task.FromResult(reply));

                client.Queries = queryMock.Object;
            }

            var count = (await client.QueryIntervalGroupAsync(QueryType.Count(), testCol, "", groupby, timeframe, interval)).ToList();
            Assert.IsNotNull(count);

            if (null != queryMock)
            {
                queryMock.VerifyAll();
            }
        }