using System; using System.Collections.Generic; using System.Linq; using System.Text; using NodaTime; namespace InfluxDB.Client.Core.Flux.Domain { /// /// A record is a tuple of values. Each record in the table represents a single point in the series. /// /// Specification. /// public class FluxRecord { /// /// The Index of the table that the record belongs. /// public int Table { get; set; } /// /// The record's values. /// public Dictionary Values { get; } = new Dictionary(); /// /// The record's columns. /// public List Row { get; } = new List(); public FluxRecord(int table) { Table = table; } /// the inclusive lower time bound of all records public Instant? GetStart() { return (Instant?)GetValueByKey("_start"); } /// the exclusive upper time bound of all records public Instant? GetStop() { return (Instant?)GetValueByKey("_stop"); } /// /// The timestamp as a /// /// the time of the record public Instant? GetTime() { return (Instant?)GetValueByKey("_time"); } /// /// The timestamp as a /// /// the time of the record public DateTime? GetTimeInDateTime() { var time = GetTime(); return time?.InUtc().ToDateTimeUtc() ?? default(DateTime); } /// the value of the record public object GetValue() { return GetValueByKey("_value"); } /// get value with key _field public string GetField() { return (string)GetValueByKey("_field"); } /// get value with key _measurement public string GetMeasurement() { return (string)GetValueByKey("_measurement"); } /// /// Get FluxRecord value by index. /// /// index of value in CSV response /// value public object GetValueByIndex(int index) { return Values.Values.ToList()[index]; } /// /// Get FluxRecord value by key. /// /// the key of value in CSV response /// value public object GetValueByKey(string key) { object value; if (Values.TryGetValue(key, out value)) { return value; } return null; } public override string ToString() { return new StringBuilder(GetType().Name + "[") .Append("table=" + Table) .Append(", values=" + Values.Count) .Append("]") .ToString(); } } }