Skip to content

Instantly share code, notes, and snippets.

@Nikasa1889
Created July 14, 2017 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikasa1889/9eb72b29b1b058628b1e517d20019af3 to your computer and use it in GitHub Desktop.
Save Nikasa1889/9eb72b29b1b058628b1e517d20019af3 to your computer and use it in GitHub Desktop.
Influx Data Model in C#
[InfluxMeasurement("consumption")]
public class ConsumptionMeasurement:InfluxMeasurementBase
{
[InfluxTimestamp]
public override DateTime Timestamp { get; set; }
[InfluxTag("assetguid")]
public Guid AssetGuid { get; set; }
[InfluxTag("consumptiontype")]
public ConsumptionType ConsumptionType { get; set; }
[InfluxField("createdtime")]
public DateTime CreatedTime { get; set; }
[InfluxField("sourcestatus")]
public TimeSeriesSourceStatus SourceStatus { get; set; }
//Create custom set to change default value of a field/tag when no data returned
//Default value of every field is default value of its type
private TimeSeriesValueStatus _valuestatus = TimeSeriesValueStatus.OK;
[InfluxField("valuestatus")]
public TimeSeriesValueStatus ValueStatus
{
get { return _valuestatus; }
set {
if (value == default(TimeSeriesValueStatus)) value = TimeSeriesValueStatus.OK;
_valuestatus = value;
}
}
//string cannot be null when saving to InfluxDb
private string _historyBase64 = "";
[InfluxField("historybase64"), InfluxHistoryBase64]
public string HistoryBase64 {
get { return _historyBase64;}
set
{
if (value == null) value = "";
_historyBase64 = value;
}
}
[InfluxField("value")]
public double? Value { get; set; }
// The first value in the history of the consumption corresponds to the latest value. So we just copy it out.
public override TimeSeriesValueModel ToTimeSeriesValueModel()
public override TimeSeriesModel ToTimeSeriesModelPrototype()
public override List<InfluxMeasurementBase> FromTimeSeriesModel(TimeSeriesModel tsModel)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment