Esempio n. 1
0
        /// <summary>
        /// Gets a set of compressed values
        /// </summary>
        /// <param name="inclusiveStartTimestamp">The start of the values to get</param>
        /// <param name="exclusiveEndTimestamp">The exclusive end of the values to get</param>
        /// <returns>A compressed data block of values</returns>
        public DataBlock[] GetCompressedValues(DateTime inclusiveStartTimestamp, DateTime exclusiveEndTimestamp)
        {
            var dataBlocks = new List<DataBlock>();
            if (Values != null)
            {
                var orderedKeyValuePairs = Values.Where(x => x.Key >= inclusiveStartTimestamp && x.Key < exclusiveEndTimestamp).OrderBy(x => x.Key).ToArray();

                var i = 0;
                while (i < orderedKeyValuePairs.Length)
                {
                    var dataBlock = new DataBlock
                    {
                        DataInterval = _owner.Owner.DataInterval,
                        StartTime = orderedKeyValuePairs[i].Key
                    };
                    var values = new List<float> { orderedKeyValuePairs[i].Value };
                    var j = 0;
                    while (i + j + 1 < orderedKeyValuePairs.Length &&
                           orderedKeyValuePairs[i + j + 1].Key - orderedKeyValuePairs[i + j].Key ==
                           new TimeSpan(0, dataBlock.DataInterval, 0))
                    {
                        values.Add(orderedKeyValuePairs[i + j + 1].Value);
                        j++;
                    }

                    dataBlock.Values = values.ToArray();
                    dataBlocks.Add(dataBlock);
                    i += j + 1;
                }
            }
            return dataBlocks.ToArray();
        }
Esempio n. 2
0
 /// <summary>
 /// Adds a block of compressed values to the list of values
 /// </summary>
 /// <param name="values">The data block to add</param>
 public void AddCompressedValues(DataBlock[] values)
 {
     if(values == null)
         return;
     foreach (var block in values)
     {
         for (var i = 0; i < block.Values.Length; i++)
         {
             Values[block.StartTime.AddMinutes(i * block.DataInterval)] = block.Values[i];
         }
     }
 }