QueryGroupAsync() public method

Returns values collected by group.
public QueryGroupAsync ( Keen.Core.Query.QueryType queryType, string collection, string targetProperty, string groupBy, QueryTimeframe timeframe = null, 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 a collection field by which to group results.
timeframe QueryTimeframe Specifies window of time from which to select events for analysis. May be absolute or relative.
filters IEnumerable Filter 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>>
Ejemplo n.º 1
0
        public async void SelectUnique_ValidRelativeGroup_Success()
        {
            var client = new KeenClient(settingsEnv);
            var prop = "field1";
            var groupby = "field1";
            var timeframe = QueryRelativeTimeframe.PreviousNDays(5);
            IEnumerable<QueryGroupValue<string>> reply = new List<QueryGroupValue<string>>()
            {
                new QueryGroupValue<string>( "hello,goodbye,I'm late", "field1" ),
                new QueryGroupValue<string>( "hello,goodbye,I'm late", "field1" ),
            };

            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<QueryRelativeTimeframe>(t => t == timeframe),
                        It.Is<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<string>(t => t == "")
                        ))
                    .Returns(Task.FromResult(reply));

                client.Queries = queryMock.Object;
            }

            (await client.QueryGroupAsync(QueryType.SelectUnique(), testCol, prop, groupby, timeframe, null)).ToList();

            if (null != queryMock)
                queryMock.VerifyAll();
        }
Ejemplo n.º 2
0
        public async void Query_ValidRelativeGroup_Success()
        {
            var client = new KeenClient(settingsEnv);
            var timeframe = QueryRelativeTimeframe.PreviousNDays(2);
            var groupby = "field1";
            IEnumerable<QueryGroupValue<string>> reply = new List<QueryGroupValue<string>>()
            {
                new QueryGroupValue<string>( "0", "field1" ),
                new QueryGroupValue<string>( "0", "field1" ),
            };

            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<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<string>(z => z == "")))
                    .Returns(Task.FromResult(reply));

                client.Queries = queryMock.Object;
            }

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

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