forked from influxdata/influxdb-client-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFluxRecord.cs
122 lines (105 loc) · 3.37 KB
/
FluxRecord.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NodaTime;
namespace InfluxDB.Client.Core.Flux.Domain
{
/// <summary>
/// A record is a tuple of values. Each record in the table represents a single point in the series.
///
/// <para><a href="http://bit.ly/flux-spec#record">Specification</a>.</para>
/// </summary>
public class FluxRecord
{
/// <summary>
/// The Index of the table that the record belongs.
/// </summary>
public int Table { get; set; }
/// <summary>
/// The record's values.
/// </summary>
public Dictionary<string, object> Values { get; } = new Dictionary<string, object>();
/// <summary>
/// The record's columns.
/// </summary>
public List<object> Row { get; } = new List<object>();
public FluxRecord(int table)
{
Table = table;
}
/// <returns>the inclusive lower time bound of all records</returns>
public Instant? GetStart()
{
return (Instant?)GetValueByKey("_start");
}
/// <returns>the exclusive upper time bound of all records</returns>
public Instant? GetStop()
{
return (Instant?)GetValueByKey("_stop");
}
///<summary>
/// The timestamp as a <see cref="Instant"/>
/// </summary>
/// <returns>the time of the record</returns>
public Instant? GetTime()
{
return (Instant?)GetValueByKey("_time");
}
///<summary>
/// The timestamp as a <see cref="DateTime"/>
/// </summary>
/// <returns>the time of the record</returns>
public DateTime? GetTimeInDateTime()
{
var time = GetTime();
return time?.InUtc().ToDateTimeUtc() ?? default(DateTime);
}
/// <returns>the value of the record</returns>
public object GetValue()
{
return GetValueByKey("_value");
}
/// <returns>get value with key <i>_field</i></returns>
public string GetField()
{
return (string)GetValueByKey("_field");
}
/// <returns>get value with key <i>_measurement</i></returns>
public string GetMeasurement()
{
return (string)GetValueByKey("_measurement");
}
/// <summary>
/// Get FluxRecord value by index.
/// </summary>
/// <param name="index">index of value in CSV response</param>
/// <returns>value</returns>
public object GetValueByIndex(int index)
{
return Values.Values.ToList()[index];
}
/// <summary>
/// Get FluxRecord value by key.
/// </summary>
/// <param name="key">the key of value in CSV response</param>
/// <returns>value</returns>
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();
}
}
}