Permalink
Browse files

Add multi model classes

  • Loading branch information...
1 parent bcd5adc commit 3cb00c88207767b4743e60a5b4c1a91fb802cd69 @maddenpj maddenpj committed Sep 25, 2013
View
25 Client.Tests/DataPointModelTests.cs
@@ -54,4 +54,29 @@ public void Equality_Null()
Assert.AreEqual(false, dp1.Equals(null));
}
}
+
+ [TestFixture]
+ class MultiPointModelTests
+ {
+ [Test]
+ public void Double_Or_Long()
+ {
+ var dp1 = new MultiIdPoint("id1", new DateTime(2013, 9, 25, 0, 0, 1), 12.34);
+ var dp2 = new MultiIdPoint("id2", new DateTime(2013, 9, 25, 0, 0, 1), 1000L);
+
+ Assert.AreEqual(dp1.Value, 12.34);
+ Assert.AreEqual(dp1.Value is double, true);
+ Assert.AreEqual(dp2.Value, 1000L);
+ Assert.AreEqual(dp2.Value is long, true);
+ }
+
+ public void Multi_List()
+ {
+ var dp1 = new MultiIdPoint("id1", new DateTime(2013, 9, 25, 0, 0, 1), 12.24);
+ var dp2 = new MultiKeyPoint("key1", new DateTime(2013, 9, 25, 0, 0, 1), 1000L);
+
+ var list = new List<MultiPoint>{ dp1, dp2 };
+ Assert.AreEqual(list.Count, 2);
+ }
+ }
}
View
32 Client/Model/MultiIdPoint.cs
@@ -0,0 +1,32 @@
+using Newtonsoft.Json;
+using System;
+
+namespace Client.Model
+{
+ /// <summary>
+ /// Represents a datapoint for a series referenced by id. This class is used to represent
+ /// datapoints in a multi write.
+ /// </summary>
+ public class MultiIdPoint : MultiPoint
+ {
+ /// <param name="id"> The id of the Series </param>
+ /// <param name="timestamp"> The timestamp of the datapoint </param>
+ /// <param name="value"> The datapoint value </param>
+ public MultiIdPoint(string id, DateTime timestamp, double value)
+ {
+ Id = id;
+ Timestamp = timestamp;
+ Value = value;
+ }
+
+ public MultiIdPoint(string id, DateTime timestamp, long value)
+ {
+ Id = id;
+ Timestamp = timestamp;
+ Value = value;
+ }
+
+ [JsonProperty(PropertyName = "id")]
+ public string Id { get; private set; }
+ }
+}
View
32 Client/Model/MultiKeyPoint.cs
@@ -0,0 +1,32 @@
+using Newtonsoft.Json;
+using System;
+
+namespace Client.Model
+{
+ /// <summary>
+ /// Represents a datapoint for a series referenced by key. This class is used to represent
+ /// datapoints in a multi write.
+ /// </summary>
+ public class MultiKeyPoint : MultiPoint
+ {
+ /// <param name="key"> The key of the Series </param>
+ /// <param name="timestamp"> The timestamp of the datapoint </param>
+ /// <param name="value"> The datapoint value </param>
+ public MultiKeyPoint(string key, DateTime timestamp, double value)
+ {
+ Key = key;
+ Timestamp = timestamp;
+ Value = value;
+ }
+
+ public MultiKeyPoint(string key, DateTime timestamp, long value)
+ {
+ Key = key;
+ Timestamp = timestamp;
+ Value = value;
+ }
+
+ [JsonProperty(PropertyName = "key")]
+ public string Key { get; private set; }
+ }
+}
View
21 Client/Model/MultiPoint.cs
@@ -0,0 +1,21 @@
+using Newtonsoft.Json;
+using System;
+
+namespace Client.Model
+{
+ /// <summary>
+ /// The abstract parent class representing a datapoint used in a multi write. Multi
+ /// writing allows values for different series to be written for multiple timestamps in one
+ /// Rest call. The series can be referenced by series id or series key. The two subclasses
+ /// represent these two options.
+ /// </summary>
+
+ public abstract class MultiPoint
+ {
+ [JsonProperty(PropertyName = "t")]
+ public DateTime Timestamp { get; protected set; }
+
+ [JsonProperty(PropertyName = "v")]
+ public object Value { get; protected set; }
+ }
+}
View
3 Client/TempoClient.csproj
@@ -54,6 +54,9 @@
<Compile Include="Model\BulkIdPoint.cs" />
<Compile Include="Model\BulkKeyPoint.cs" />
<Compile Include="Model\BulkPoint.cs" />
+ <Compile Include="Model\MultiIdPoint.cs" />
+ <Compile Include="Model\MultiKeyPoint.cs" />
+ <Compile Include="Model\MultiPoint.cs" />
<Compile Include="Model\Common.cs" />
<Compile Include="Model\DataPoint.cs" />
<Compile Include="Model\DataSet.cs" />

0 comments on commit 3cb00c8

Please sign in to comment.