Esempio n. 1
0
        private int GetTraceCount(DateHistogramBucket dateHistogram)
        {
            var valueAggregate = dateHistogram.Values.FirstOrDefault() as ValueAggregate;

            if (valueAggregate == null || valueAggregate.Value == null)
            {
                return(0);
            }
            return((int)valueAggregate.Value.Value);
        }
Esempio n. 2
0
 private decimal?GetAverage(DateHistogramBucket dateHistogramBucket)
 {
     if (dateHistogramBucket?.Average("average")?.Value != null)
     {
         return(Math.Round((decimal)dateHistogramBucket.Average("average").Value, 1));
     }
     else
     {
         return(null);
     }
 }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var item      = JObject.Load(reader);
            var typeToken = item.SelectToken("Data.@type") ?? item.SelectToken("data.@type");

            IBucket value = null;

            if (typeToken != null)
            {
                string type = typeToken.Value <string>();
                IDictionary <string, IAggregate> aggregations = null;
                var aggregationsToken = item.SelectToken("Aggregations") ?? item.SelectToken("aggregations");
                aggregations = aggregationsToken?.ToObject <IDictionary <string, IAggregate> >();

                switch (type)
                {
                case "datehistogram":
                    var timeZoneToken = item.SelectToken("Data.@timezone") ?? item.SelectToken("data.@timezone");
                    var kind          = timeZoneToken != null ? DateTimeKind.Unspecified : DateTimeKind.Utc;
                    var key           = item.SelectToken("Key") ?? item.SelectToken("key");
                    var date          = new DateTime(_epochTicks + ((long)key * TimeSpan.TicksPerMillisecond), kind);

                    value = new DateHistogramBucket(date, aggregations);
                    break;

                case "range":
                    value = new RangeBucket(aggregations);
                    break;

                case "string":
                    value = new KeyedBucket <string>(aggregations);
                    break;

                case "double":
                    value = new KeyedBucket <double>(aggregations);
                    break;

                case "object":
                    value = new KeyedBucket <object>(aggregations);
                    break;
                }
            }

            if (value == null)
            {
                value = new KeyedBucket <object>();
            }

            serializer.Populate(item.CreateReader(), value);

            return(value);
        }
Esempio n. 4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var item      = JObject.Load(reader);
            var typeToken = item.SelectToken("Data.@type") ?? item.SelectToken("data.@type");

            IBucket value = null;

            if (typeToken != null)
            {
                string type = typeToken.Value <string>();
                switch (type)
                {
                case "datehistogram":
                    value = new DateHistogramBucket();
                    break;

                case "range":
                    value = new RangeBucket();
                    break;

                case "string":
                    value = new KeyedBucket <string>();
                    break;

                case "double":
                    value = new KeyedBucket <double>();
                    break;

                case "object":
                    value = new KeyedBucket <object>();
                    break;
                }
            }

            if (value == null)
            {
                value = new KeyedBucket <object>();
            }

            serializer.Populate(item.CreateReader(), value);
            return(value);
        }