private static IEnumerable <Interfaces.TimeseriesData> Deserialize( InfluxDBResult result) { if (result == null || result.Series == null) { return(null); } var r = new List <Interfaces.TimeseriesData>(); foreach (var serie in result.Series) { var tagColumn = Array.FindIndex(serie.Columns, c => c == "Tag"); var sourceColumn = Array.FindIndex(serie.Columns, c => c == "Source"); var timeColumn = Array.FindIndex(serie.Columns, c => c == "time"); var valueColumn = Array.FindIndex(serie.Columns, c => c == "Value"); r.AddRange(serie.Values.GroupBy(v => new { Source = sourceColumn > 0 ? v.ElementAt(sourceColumn).ToString() : null, Tag = tagColumn > 0 ? v.ElementAt(tagColumn).ToString() : null }) .Select(g => new Interfaces.TimeseriesData { Tag = g.Key.Tag, Source = g.Key.Source, DataPoints = new List <DataPoint>(g.Select(p => new DataPoint { Timestamp = ToDateTime(p.ElementAt(timeColumn)), Value = valueColumn > 0 ? p.ElementAt(valueColumn) : null })) })); } return(r); }
private IEnumerable <TimeseriesData> AggregationDeserialize(InfluxDBResult result) { if (result == null || result.Series == null) { return(null); } var r = new List <TimeseriesData>(); foreach (var serie in result.Series) { r.Add(new TimeseriesData { Tag = serie.Tags["Tag"], Source = serie.Tags["Source"], DataPoints = serie.Values .Select(v => { var point = new DataPoint { Value = new ExpandoObject() }; dynamic ex = new ExpandoObject(); for (var i = 0; i < serie.Columns.Length; i++) { if (serie.Columns[i] == "time") { point.Timestamp = (DateTime)v[i]; (ex as IDictionary <string, Object>).Add("Timestamp", v[i]); } else { (point.Value as IDictionary <string, Object>).Add(serie.Columns[i], v[i]); (ex as IDictionary <string, Object>).Add(serie.Columns[i], v[i]); } } return(point); }).ToList() }); } return(r); }