コード例 #1
0
        public IPercentileRanksAggregation Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            var count       = 0;
            var percentiles = new PercentileRanksAggregation();

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (AutomataDictionary.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        percentiles.Method = formatterResolver.GetFormatter <HDRHistogramMethod>()
                                             .Deserialize(ref reader, formatterResolver);
                        break;

                    case 1:
                        percentiles.Method = formatterResolver.GetFormatter <TDigestMethod>()
                                             .Deserialize(ref reader, formatterResolver);
                        break;

                    case 2:
                        percentiles.Field = reader.ReadString();
                        break;

                    case 3:
                        percentiles.Script = formatterResolver.GetFormatter <IScript>()
                                             .Deserialize(ref reader, formatterResolver);
                        break;

                    case 4:
                        percentiles.Missing = reader.ReadDouble();
                        break;

                    case 5:
                        percentiles.Meta = formatterResolver.GetFormatter <IDictionary <string, object> >()
                                           .Deserialize(ref reader, formatterResolver);
                        break;

                    case 6:
                        percentiles.Values = formatterResolver.GetFormatter <IEnumerable <double> >()
                                             .Deserialize(ref reader, formatterResolver);
                        break;

                    case 7:
                        percentiles.Keyed = reader.ReadBoolean();
                        break;
                    }
                }
            }

            return(percentiles);
        }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var o               = JObject.Load(reader);
            var properties      = o.Properties().ToDictionary(p => p.Name, p => p.Value);
            var percentileRanks = new PercentileRanksAggregation();

            ReadMetricProperties(percentileRanks, properties);
            percentileRanks.Method = ReadMethodProperty(properties);
            if (properties.ContainsKey("values"))
            {
                percentileRanks.Values = properties["values"].ToObject <List <double> >();
            }
            return(percentileRanks);;
        }