Exemple #1
0
        /// <summary>
        /// Add time-series data to the channel.
        /// </summary>
        /// <param name="sensorName">sensor containing the channel to add data to.</param>
        /// <param name="channelName">channel to add data to.</param>
        /// <param name="sampleRate">sample-rate for points in data</param>
        /// <param name="data">a list of points to add to the channel.
        /// <remarks>The points should be ordered and match the sample-rate provided.</remarks>
        /// </param>
        public void AddTimeSeriesData(SampleRate sampleRate, IEnumerable <Point> data)
        {
            var payload = new MemoryStream();
            var xdr     = new XdrWriter(payload);

            const int VERSION = 1;

            xdr.WriteInt(VERSION);
            xdr.WriteInt(sampleRate.Type.ToXdr());
            xdr.WriteInt(sampleRate.Rate);

            //Writing an array in XDR.  an array is always prefixed by the array length
            xdr.WriteInt(data.Count());
            foreach (Point p in data)
            {
                xdr.WriteUnsingedHyper(p.UnixTimestamp);
                xdr.WriteFloat(p.Value);
            }

            string url     = "/sensors/" + _sensorName + "/channels/" + this.Name + "/streams/timeseries/data/";
            var    request = _requests.url(url)
                             .Param("version", "1")
                             .ContentType("application/xdr")
                             .Data(payload.ToArray())
                             .Put();

            // check the response code for success
            if (request.ResponseCode != HttpStatusCode.Created)
            {
                throw SensorCloudException.GenerateSensorCloudException(request, "AddTimeSeriesData failed.");
            }
        }
Exemple #2
0
        internal TimeSeriesStream(string sensorName, string channelName, IRequests requests, ulong start, ulong end, SampleRate samplerate)
        {
            Debug.Assert(end >= start);

            _sensorName  = sensorName;
            _channelName = channelName;
            _requests    = requests;
            _sampleRate  = samplerate;

            _startTimestampNanoseconds = start;
            _endTimestampNanoseconds   = end;
        }
Exemple #3
0
 internal TimeSeriesStream(string sensorName, string channelName, IRequests requests, SampleRate sampleRate)
     : this(sensorName, channelName, requests, 0, ulong.MaxValue, sampleRate)
 {
 }
Exemple #4
0
 internal TimeSeriesStream(string sensorName, string channelName, IRequests requests, DateTime start, DateTime end, SampleRate samplerate)
     : this(sensorName, channelName, requests, convertToEpoch(start), convertToEpoch(end))
 {
 }