示例#1
0
        private IAggregate GetPercentilesAggregate(ref JsonReader reader, IReadOnlyDictionary <string, object> meta)
        {
            var metric = new PercentilesAggregate {
                Meta = meta
            };
            var token = reader.GetCurrentJsonToken();

            if (token != JsonToken.BeginObject && token != JsonToken.BeginArray)
            {
                reader.ReadNextBlock();
                return(metric);
            }

            var count = 0;

            if (token == JsonToken.BeginObject)
            {
                while (reader.ReadIsInObject(ref count))
                {
                    var propertyName = reader.ReadPropertyName();
                    if (propertyName.Contains(Parser.AsStringSuffix))
                    {
                        reader.ReadNextBlock();
                        continue;
                    }

                    metric.Items.Add(new PercentileItem
                    {
                        Percentile = double.Parse(propertyName, CultureInfo.InvariantCulture),
                        Value      = reader.ReadNullableDouble()
                    });
                }
            }
            else
            {
                while (reader.ReadIsInArray(ref count))
                {
                    reader.ReadNext();                     // {
                    reader.ReadNext();                     // "key"
                    reader.ReadNext();                     // :
                    var percentile = reader.ReadDouble();
                    reader.ReadNext();                     // ,
                    reader.ReadNext();                     // "value"
                    reader.ReadNext();                     // :
                    metric.Items.Add(new PercentileItem
                    {
                        Percentile = percentile,
                        Value      = reader.ReadNullableDouble()
                    });
                    reader.ReadNext();                     // }
                }
            }

            return(metric);
        }
示例#2
0
        private IAggregate GetPercentilesAggregate(JsonReader reader, JsonSerializer serializer, bool oldFormat = false)
        {
            var metric          = new PercentilesAggregate();
            var percentileItems = new List <PercentileItem>();

            if (reader.TokenType == JsonToken.StartObject)
            {
                reader.Read();
            }
            while (reader.TokenType != JsonToken.EndObject)
            {
                var propertyName = (string)reader.Value;
                if (propertyName.Contains(Parser.AsStringSuffix))
                {
                    reader.Read();
                    reader.Read();
                }
                if (reader.TokenType != JsonToken.EndObject)
                {
                    var percentileValue = (string)reader.Value;
                    var percentile      = double.Parse(percentileValue, CultureInfo.InvariantCulture);
                    reader.Read();
                    var value = reader.Value as double?;
                    percentileItems.Add(new PercentileItem()
                    {
                        Percentile = percentile,
                        Value      = value.GetValueOrDefault(0)
                    });
                    reader.Read();
                }
            }
            metric.Items = percentileItems;
            if (!oldFormat)
            {
                reader.Read();
            }
            return(metric);
        }
		private IAggregate GetPercentilesMetric(JsonReader reader, JsonSerializer serializer, bool oldFormat = false)
		{
			var metric = new PercentilesAggregate();
			var percentileItems = new List<PercentileItem>();
			if (reader.TokenType == JsonToken.StartObject)
				reader.Read();
			while (reader.TokenType != JsonToken.EndObject)
			{
				if ((reader.Value as string).Contains("_as_string"))
				{
					reader.Read();
					reader.Read();
				}
				if (reader.TokenType != JsonToken.EndObject)
				{
					var percentile = double.Parse(reader.Value as string, CultureInfo.InvariantCulture);
					reader.Read();
					var value = reader.Value as double?;
					percentileItems.Add(new PercentileItem()
					{
						Percentile = percentile,
						Value = value.GetValueOrDefault(0)
					});
					reader.Read();
				}
			}
			metric.Items = percentileItems;
			if (!oldFormat) reader.Read();
			return metric;
		}