Example #1
0
        private static void AssertPercentilesAggregate(AggregateDictionary bucket, string name)
        {
            var percentilesAggregate = bucket.Percentiles(name);

            percentilesAggregate.Should().NotBeNull();
            percentilesAggregate.Items.Should().HaveCount(1).And.Contain(p => Math.Abs(p.Percentile - 50d) < double.Epsilon);
        }
        public void SetUp()
        {
            callback = MockRepository.GenerateMock <IDictionaryCallback>();

            dict1 = new Dictionary <string, object>
            {
                { "a", 1 },
                { "b", 2 },
                { "c", 3 }
            };

            dict2 = new Dictionary <string, object>
            {
                { "d", 4 },
                { "e", 5 },
                { "f", 6 }
            };

            dict3 = new Dictionary <string, object>
            {
                { "g", 7 },
                { "h", 8 },
                { "i", 9 }
            };

            aggregate = new AggregateDictionary();
            aggregate.AddLocator(RequestDataSource.Route, key => dict1.ContainsKey(key) ? dict1[key] : null, () => dict1.Keys);
            aggregate.AddLocator(RequestDataSource.Request, key => dict2.ContainsKey(key) ? dict2[key] : null, () => dict2.Keys);
            aggregate.AddLocator(RequestDataSource.Header, key => dict3.ContainsKey(key) ? dict3[key] : null, () => dict3.Keys);
        }
Example #3
0
 protected void OpenDictionary()
 {
     persistentSource = new FileBasedPersistentSource(tempPath, "test_", TransactionMode.Safe);
     aggregateDictionary = new AggregateDictionary(persistentSource);
     persistentDictionary = aggregateDictionary.Add(new PersistentDictionary(persistentSource, JTokenComparer.Instance));
     aggregateDictionary.Initialze();
 }
Example #4
0
        public override bool OnData(object data)
        {
            if (!(data is DataType))
            {
                throw new BlockTypeMismatchException(typeof(DataType), data.GetType(), this);
            }

            var d = (DataType)data;

            // :HACK: lol
            if (isAggregator)
            {
                List <DataType> temp;
                AggregateDictionary.TryGetValue(KeyFunction(d), out temp);
                if (temp == null)
                {
                    AggregateDictionary[KeyFunction(d)] = new List <DataType>();
                }
                AggregateDictionary[KeyFunction(d)].Add(d);
                SendToChildren(AggregateDictionary);
            }
            else
            {
                Dictionary[KeyFunction(d)] = d;
                SendToChildren(Dictionary);
            }

            return(false);
        }
Example #5
0
 public static double ObterBucketAggregationDouble(AggregateDictionary agg, string bucket)
 {
     if (agg.BucketScript(bucket).Value.HasValue)
     {
         return(agg.BucketScript(bucket).Value.Value);
     }
     return(0);
 }
Example #6
0
        public void SetUp()
        {
            dictionary = new Dictionary<string, object>();
            aggregate = new AggregateDictionary();
            aggregate.AddDictionary(dictionary);

            request = new RequestData(aggregate);
        }
        private static void AssertExtendedStats(AggregateDictionary bucket, string name)
        {
            var extendedStatsAggregate = bucket.ExtendedStats(name);

            extendedStatsAggregate.Should().NotBeNull();
            extendedStatsAggregate.Count.Should().BeGreaterOrEqualTo(0);
            extendedStatsAggregate.StdDeviationBounds.Should().NotBeNull();
        }
        public void SetUp()
        {
            dictionary = new Dictionary<string, object>();
            aggregate = new AggregateDictionary();
            aggregate.AddLocator(RequestDataSource.Route, key => dictionary.ContainsKey(key) ? dictionary[key] : null);

            request = new RequestData(aggregate);
        }
Example #9
0
        public void SetUp()
        {
            dictionary = new Dictionary <string, object>();
            aggregate  = new AggregateDictionary();
            aggregate.AddDictionary(dictionary);


            request = new RequestData(aggregate);
        }
Example #10
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var dictionary             = new AggregateDictionary(requestContext);
            ServiceArguments arguments = new ServiceArguments().With(dictionary);

            IActionBehavior behavior = GetBehavior(arguments);

            return(new FubuHttpHandler(behavior));
        }
        public void indexer_should_find_value_with_one_locator_registered()
        {
            var values = new NameValueCollection { { "foo", "value" } };
            var dict = new AggregateDictionary();

            dict.AddLocator(s => values[s]);

            dict["foo"].ShouldEqual("value");
        }
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var dictionary = new AggregateDictionary(requestContext);
            ServiceArguments arguments = new ServiceArguments().With(dictionary);

            IActionBehavior behavior = GetBehavior(arguments);

            return new FubuHttpHandler(behavior);
        }
Example #13
0
        public static StatsAggregate GetStats <T>(this AggregateDictionary aggs, Expression <Func <T, object> > fieldGetter, Expression <Func <T, object> > filterRule = null)
        {
            var aggWithResult = GetAggregationContainingResult(aggs, filterRule);
            var aggName       = fieldGetter.GetAggName(AggType.Stats);

            aggWithResult.CheckForAggregationInResult(aggName);
            var itemsTerms = aggWithResult.Stats(aggName);

            return(itemsTerms);
        }
Example #14
0
        public static IList <PercentileItem> GetPercentile <T>(this AggregateDictionary aggs, Expression <Func <T, object> > fieldGetter, Expression <Func <T, object> > filterRule = null)
        {
            var aggWithResult = GetAggregationContainingResult(aggs, filterRule);
            var aggName       = fieldGetter.GetAggName(AggType.Percentile);

            aggWithResult.CheckForAggregationInResult(aggName);
            var itemsTerms = aggWithResult.Percentiles(aggName);

            return(itemsTerms.Items);
        }
        protected void OpenDictionary()
        {
            persistentSource = new FileBasedPersistentSource(Path.GetTempPath(), "test_", TransactionMode.Lazy);
            aggregateDictionary = new AggregateDictionary(persistentSource);

            persistentDictionaryOne = aggregateDictionary.Add(new PersistentDictionary(persistentSource, JTokenComparer.Instance));
            persistentDictionaryTwo = aggregateDictionary.Add(new PersistentDictionary(persistentSource, JTokenComparer.Instance));

            aggregateDictionary.Initialze();
        }
Example #16
0
        public void should_never_find_uri_value_from_request_property()
        {
            var requestCtx = Do_the_Stupid_ASPNET_Mock_HokeyPokey();

            aggregate = new AspNetAggregateDictionary(requestCtx);

            forKey("Url");

            assertWasNotFound();
        }
Example #17
0
        public DebugReport(AggregateDictionary dictionary, ICurrentHttpRequest request)
        {
            _dictionary = dictionary;
            _request    = request;
            Id          = Guid.NewGuid();

            FormData = new Dictionary <string, object>();
            Headers  = new Dictionary <string, string>();
            Time     = DateTime.Now;
        }
Example #18
0
        public static TK GetAverage <T, TK>(this AggregateDictionary aggs, Expression <Func <T, TK> > fieldGetter, Expression <Func <T, object> > filterRule = null)
        {
            var aggWithResult = GetAggregationContainingResult(aggs, filterRule);
            var aggName       = fieldGetter.GetAggName(AggType.Average);

            aggWithResult.CheckForAggregationInResult(aggName);
            var avgAgg = aggWithResult.Average(aggName);

            return(ValueAsUndType <TK>(avgAgg));
        }
Example #19
0
        public static TK GetFirstBy <T, TK>(this AggregateDictionary aggs, Expression <Func <T, TK> > fieldGetter, Expression <Func <T, object> > filterRule = null)
        {
            var aggWithResult = GetAggregationContainingResult(aggs, filterRule);
            var aggName       = fieldGetter.GetAggName(AggType.First);

            aggWithResult.CheckForAggregationInResult(aggName);
            var termsAgg = aggWithResult.Terms(aggName);

            return(Filters.StringToAnything <TK>(termsAgg.Buckets.First().Key));
        }
Example #20
0
        public static int GetCardinality <T>(this AggregateDictionary aggs, Expression <Func <T, object> > fieldGetter, Expression <Func <T, object> > filterRule = null)
        {
            var aggWithResult = GetAggregationContainingResult(aggs, filterRule);
            var aggName       = fieldGetter.GetAggName(AggType.Cardinality);

            aggWithResult.CheckForAggregationInResult(aggName);
            var itemsTerms = aggWithResult.Cardinality(aggName);

            return((int)itemsTerms.Value.Value);
        }
Example #21
0
        public void find_uri_value_from_request_property()
        {
            var expectedValue = new Uri("http://localhost/foo");
            var requestCtx    = Do_the_Stupid_ASPNET_Mock_HokeyPokey();

            aggregate = new AspNetAggregateDictionary(requestCtx);

            forKey("Url");

            assertFound(RequestDataSource.RequestProperty, expectedValue);
        }
        public void TryGetValue_should_find_value_with_one_locator_registered()
        {
            var values = new NameValueCollection { { "foo", "value" } };
            var dict = new AggregateDictionary();

            dict.AddLocator(s => values[s]);

            object value;
            dict.TryGetValue("foo", out value).ShouldBeTrue();
            value.ShouldEqual("value");
        }
        public void indexer_should_not_error_if_no_locator_finds_the_value()
        {
            var values1 = new NameValueCollection { { "foo", "value" } };
            var values2 = new NameValueCollection { { "bar", "baz" } };
            var dict = new AggregateDictionary();

            dict.AddLocator(s => values1[s]);
            dict.AddLocator(s => values2[s]);

            dict["zzzz"].ShouldBeNull();
        }
        public void indexer_should_find_value_with_multiple_locators_registered()
        {
            var values1 = new NameValueCollection { { "foo", "value" } };
            var values2 = new NameValueCollection { { "bar", "baz" } };
            var dict = new AggregateDictionary();

            dict.AddLocator(s => values1[s]);
            dict.AddLocator(s => values2[s]);

            dict["bar"].ShouldEqual("baz");
        }
Example #25
0
        public void find_value_from_request_property()
        {
            const string expectedValue = "STUBBED USERAGENT";
            var          requestCtx    = Do_the_Stupid_ASPNET_Mock_HokeyPokey();

            requestCtx.HttpContext.Request.Stub(r => r.UserAgent).Return(expectedValue);
            aggregate = new AspNetAggregateDictionary(requestCtx);

            forKey("UserAgent");

            assertFound(RequestDataSource.RequestProperty, expectedValue);
        }
Example #26
0
        public static string FindPath(AggregateDictionary dictionary)
        {
            var routeData = dictionary.DataFor(RequestDataSource.Route.ToString());
            var list      = new List <string>();

            for (var i = 0; i < 10; i++)
            {
                routeData.Value("Part" + i, o => list.Add(o.ToString()));
            }

            return(list.Join("/"));
        }
        public void TryGetValue_should_find_value_with_multiple_locators_registered()
        {
            var values1 = new NameValueCollection { { "foo", "value" } };
            var values2 = new NameValueCollection { { "bar", "baz" } };
            var dict = new AggregateDictionary();

            dict.AddLocator(s => values1[s]);
            dict.AddLocator(s => values2[s]);

            object value;
            dict.TryGetValue("bar", out value).ShouldBeTrue();
            value.ShouldEqual("baz");
        }
Example #28
0
        public void request_for_url_should_come_from_the_server_variables_not_RequestProperty()
        {
            var expectedValue = "ServerVariables URL";
            var requestCtx    = Do_the_Stupid_ASPNET_Mock_HokeyPokey();
            var request       = requestCtx.HttpContext.Request;

            request.Stub(r => r["Url"]).Return(expectedValue);
            aggregate = new AspNetAggregateDictionary(requestCtx);

            forKey("Url");

            assertFound(RequestDataSource.Request, expectedValue);
        }
Example #29
0
        public static AggregateDictionary GetAggregationContainingResult <T>(this AggregateDictionary aggs,
                                                                             Expression <Func <T, object> > filterRule = null)
        {
            if (filterRule == null)
            {
                return(aggs);
            }

            var filterName = filterRule.GenerateFilterName();

            aggs.CheckForAggregationInResult(filterName);
            return(aggs.Filter(filterName));
        }
        public void SetUp()
        {
            var container = StructureMapContainerFacility.GetBasicFubuContainer();

            theHeaderDictionary = new Dictionary <string, object>();
            var dictionary = new AggregateDictionary();

            dictionary.AddDictionary(RequestDataSource.Header.ToString(), theHeaderDictionary);

            container.Inject(dictionary);

            theHeaders = container.GetInstance <RequestHeaders>();
        }
Example #31
0
        /// <summary>
        /// Checks if aggregation with given name is available on the result and throws if not
        /// </summary>
        public static void CheckForAggregationInResult(this AggregateDictionary aggs, string aggName)
        {
            if (aggs == null || aggs.Count == 0)
            {
                throw new InvalidOperationException("No aggregations available on the result");
            }

            if (!aggs.ContainsKey(aggName))
            {
                var availableAggregations = aggs.Select(x => x.Key).Aggregate((agg, x) => agg + "m" + x);
                throw new InvalidOperationException($"Aggregation {aggName} not in the result. Available aggregations: {availableAggregations}");
            }
        }
Example #32
0
        public static int?GetCount <T>(this AggregateDictionary aggs, Expression <Func <T, object> > fieldGetter, Expression <Func <T, object> > filterRule = null)
        {
            var aggWithResult = GetAggregationContainingResult(aggs, filterRule);
            var aggName       = fieldGetter.GetAggName(AggType.Count);

            aggWithResult.CheckForAggregationInResult(aggName);
            var itemsTerms = aggWithResult.ValueCount(aggName);

            if (!itemsTerms.Value.HasValue)
            {
                return(null);
            }
            return((int)itemsTerms.Value);
        }
Example #33
0
        public void find_value_from_request_property_of_added_aggregate()
        {
            const string expectedValue = "STUBBED USERAGENT";

            aggregate = new AggregateDictionary();

            aggregate.AddDictionary("Other", new Dictionary <string, object> {
                { "UserAgent", expectedValue }
            });
            forKey("UserAgent1");
            callback.AssertWasNotCalled(x => x.Callback(RequestDataSource.Other.ToString(), null), o => o.IgnoreArguments());

            forKey("UserAgent");
            assertFound(RequestDataSource.Other, expectedValue);
        }
        public void SetUp()
        {
            theServiceArguments = new ServiceArguments();
            theDictionary       = new AggregateDictionary();
            theHeaders          = new Dictionary <string, object>();
            theDictionary.AddDictionary(RequestDataSource.Header.ToString(), theHeaders);

            theServiceArguments.Set(typeof(AggregateDictionary), theDictionary);

            stash <IHttpWriter>();
            stash <ICurrentChain>();

            theCache = new EtagCache();

            theFilter = new AssetEtagInvocationFilter(theCache);
        }
Example #35
0
        public void SetUp()
        {
            theBinder = StandardModelBinder.Basic().As <StandardModelBinder>();

            theAggregateDictionary = new AggregateDictionary();

            var otherDictionary = new Dictionary <string, object>();

            for (int i = 0; i < 10; i++)
            {
                otherDictionary.Add("Part" + i, Guid.NewGuid().ToString());
            }

            theAggregateDictionary.AddDictionary(RequestDataSource.Request.ToString(), otherDictionary);


            theRouteValues = new Dictionary <string, object>();

            theAggregateDictionary.AddDictionary(RequestDataSource.Route.ToString(), theRouteValues);
        }
        private List <Aggregation> BuildAggregations(AggregateDictionary aggregations)
        {
            if (aggregations.Count == 0)
            {
                return(null);
            }
            List <Aggregation> aggResult = new List <Aggregation>();

            foreach (var esAggResult in aggregations)
            {
                aggResult.Add(new Aggregation
                {
                    aggregationName  = esAggResult.Key,
                    aggregationField = esAggResult.Key,
                    docCount         = ((BucketAggregate)esAggResult.Value).Items.Count,
                    filters          = BuildFilters(((BucketAggregate)esAggResult.Value).Items)
                });
            }
            return(aggResult);
        }
Example #37
0
        /// <summary>
        ///     Die Methode für die folgenden Filterungen durch:
        ///     - Es wird nur eine creationPeriod Facette zurückgegeben
        ///     - Aggregationen die mit 'facet_' beginnen werden nicht zurückgegeben. Stattdessen wird das Child von diesen
        ///     Aggregationen zurückgegeben.
        /// </summary>
        private Dictionary <string, IAggregate> GetfilteredAggregations(AggregateDictionary aggs, FacetFilters[] facetsFilters,
                                                                        out string chosenCreationPeriodAggregation)
        {
            var filteredAggregations = new Dictionary <string, IAggregate>();
            var found = false;

            chosenCreationPeriodAggregation = string.Empty;

            foreach (var entry in aggs.OrderBy(t => t.Key))
            {
                if (entry.Key.StartsWith("facet_aggregationFields.creationPeriodYears"))
                {
                    if (!found)
                    {
                        var primaryAggregation = ((SingleBucketAggregate)entry.Value).First().Value;

                        // Wähle den Bucket, der weniger als 10 Einträge hat. Oder dann ganz am Ende den Jahrhundertfilter
                        if (GetSelectedCreationPeriod(facetsFilters) == string.Empty && (((BucketAggregate)primaryAggregation).Items.Count < 10 ||
                                                                                         entry.Key == "facet_aggregationFields.creationPeriodYears100"
                                                                                         ) ||
                            GetSelectedCreationPeriod(facetsFilters) == entry.Key)
                        {
                            filteredAggregations.Add("aggregationFields.creationPeriodYears", primaryAggregation);
                            found = true;
                            chosenCreationPeriodAggregation = entry.Key.Remove(0, 6);
                        }
                    }
                }
                else if (entry.Key.StartsWith("facet_"))
                {
                    var primaryAggregation = ((SingleBucketAggregate)entry.Value).First().Value;
                    filteredAggregations.Add(entry.Key.Remove(0, 6), primaryAggregation);
                }
                else
                {
                    filteredAggregations.Add(entry.Key, entry.Value);
                }
            }

            return(filteredAggregations);
        }
Example #38
0
        private static IEnumerable <AggregationResult> GetAggregationResultsFrom(AggregateDictionary aggregations)
        {
            if (aggregations == null)
            {
                return(Enumerable.Empty <AggregationResult>());
            }

            var terms = aggregations.Terms(SubCategoriesAggregationName);

            if (terms == null)
            {
                return(Enumerable.Empty <AggregationResult>());
            }

            var items = terms.Buckets.Select(bucket => new AggregationResult
            {
                Code  = bucket.Key,
                Count = bucket.DocCount.GetValueOrDefault(0)
            });

            return(items);
        }
        private ISearchResponse <Document> DoSearch(int?skip)
        {
            lastskip = skip ?? 0;
            ISearchResponse <Document> searchResult;

            if (_luceneQuery != null)
            {
                _queryContainer = new QueryContainer(new QueryStringQuery()
                {
                    Query           = _luceneQuery.ToString(),
                    AnalyzeWildcard = true
                });
            }
            if (_queryContainer != null)
            {
                SearchDescriptor <Document> searchDescriptor = new SearchDescriptor <Document>();
                searchDescriptor.Index(_indexName)
                .Skip(skip)
                .Size(_maxResults)
                .Query(q => _queryContainer)

                .Sort(s => _sortDescriptor);

                var json = _client.RequestResponseSerializer.SerializeToString(searchDescriptor);
                searchResult = _client.Search <Document>(searchDescriptor);
            }
            else if (_searchRequest != null)
            {
                searchResult = _client.Search <Document>(_searchRequest);
            }
            else
            {
                searchResult = _client.Search <Document>(_searchSelector);
            }

            TotalItemCount = searchResult.Total;
            Aggregation    = searchResult.Aggregations;
            return(searchResult);
        }
Example #40
0
        public static IEnumerable <V> GetDistinct <T, V>(this AggregateDictionary aggs, Expression <Func <T, V> > fieldGetter)
        {
            var aggName    = fieldGetter.GetAggName(AggType.Distinct);
            var itemsTerms = aggs.Terms(aggName);
            var targetType = typeof(V);

            if (targetType.IsEnum)
            {
                return(itemsTerms.Buckets.Select((x => Filters.Parse <V>(x.Key))));
            }

            if (targetType == typeof(string))
            {
                return(itemsTerms.Buckets.Select(x => x.Key).Cast <V>());
            }

            if (targetType == typeof(long) || targetType == typeof(int))
            {
                return(itemsTerms.Buckets.Select(x => long.Parse(x.Key)).Cast <V>());
            }

            throw new NotImplementedException("You can get only distinct values of Strings, Enums, ints or long");
        }
        public void indxer_should_work_without_any_locators_registered()
        {
            var dict = new AggregateDictionary();

            dict["foo"].ShouldBeNull();
        }
        public void TryGetValue_should_work_without_any_locators_registered()
        {
            var dict = new AggregateDictionary();

            object value;

            dict.TryGetValue("foo", out value).ShouldBeFalse();

            value.ShouldBeNull();
        }
        public void TryGetValue_should_not_error_if_no_locator_finds_the_value()
        {
            var values1 = new NameValueCollection { { "foo", "value" } };
            var values2 = new NameValueCollection { { "bar", "baz" } };
            var dict = new AggregateDictionary();

            dict.AddLocator(s => values1[s]);
            dict.AddLocator(s => values2[s]);

            object value;
            dict.TryGetValue("zzzz", out value).ShouldBeFalse();
            value.ShouldBeNull();
        }