示例#1
0
        /// <summary>
        /// Creates a new TimeSeriesStream object with the given number of equally spaced time buckets.
        /// </summary>
        public TimeSeriesStream(TimeSeriesSpan span, int decimalPlaces)
            : this(new MemoryStream(typeof(T) == typeof(bool) ? span.Count / 4 : span.Count * sizeof(short)), 0, span, decimalPlaces)
        {
            _isStreamManaged = true;

            for (int i = 0; i < _span.Count; i++)
            {
                WriteValue(null);
            }
        }
        /// <summary>
        /// Creates a new EventTimeSeriesStream object with the start time and max number of events given in the span
        /// </summary>
        public EventTimeSeriesStream(TimeSeriesSpan span)
            : this(new MemoryStream(span.Count * (sizeof(int) + new TSerializer().SizeOf)), 0, span)
        {
            _isStreamManaged = true;

            var nullEventBytes = Enumerable.Range(0, _serializer.SizeOf).Select(b => (byte)0).ToArray();

            using var writer = new BinaryWriter(_stream, Encoding.UTF8, true);
            for (int i = 0; i < span.Count; i++)
            {
                writer.Write(-1);
                writer.Write(nullEventBytes);
            }
        }
        /// <summary>
        /// Creates a new EventTimeSeriesStream object with an existing underlying stream that has to be
        /// readable, writable and seekable. The event series starts at the given streamPosition.
        /// </summary>
        public EventTimeSeriesStream(Stream stream, int streamPosition, TimeSeriesSpan span)
        {
            if (stream == null)
            {
                throw new ArgumentException("underlying stream can not be null");
            }

            if (!stream.CanSeek || !stream.CanRead || !stream.CanWrite)
            {
                throw new ArgumentException("underlying stream must be readable, writable and seekable");
            }

            Span           = span;
            _stream        = stream;
            _startPosition = streamPosition;
        }
示例#4
0
        /// <summary>
        /// Creates a new TimeSeriesStream object with an existing underlying stream that has to be
        /// readable, writable and seekable. The time series starts at the given streamPosition.
        /// </summary>
        public TimeSeriesStream(Stream stream, int streamPosition, TimeSeriesSpan span, int decimalPlaces = 1)
            : base(span)
        {
            if (stream == null)
            {
                throw new ArgumentException("underlying stream can not be null");
            }

            if (!stream.CanSeek || !stream.CanRead || !stream.CanWrite)
            {
                throw new ArgumentException("underlying stream must be readable, writable and seekable");
            }

            _stream        = stream;
            _startPosition = streamPosition;
            _decimalPlaces = decimalPlaces;
        }
        public static EventTimeSeriesStream <TEvent, TSerializer> FromByteArray(TimeSeriesSpan span, byte[] array)
        {
            // create a SceneEventStream with a self-managed stream and copy over the array
            var eventstream = new EventTimeSeriesStream <TEvent, TSerializer>(span);

            eventstream._stream.Seek(0, SeekOrigin.Begin);
            (eventstream._stream as MemoryStream)?.Write(array, 0, Math.Min((int)eventstream._stream.Length, array.Length));

            // restore count by iterating until no more non-null events are found
            var count = 0;

            foreach (var item in eventstream)
            {
                count++;
            }
            eventstream._count = count;

            return(eventstream);
        }
示例#6
0
 /// <summary>
 /// Creates a new TimeSeriesStream object with the given number of equally spaced time buckets.
 /// </summary>
 public TimeSeriesStream(TimeSeriesSpan span) : this(span, 1)
 {
 }
示例#7
0
 /// <summary>
 /// Creates a new TimeSeries object with the given number of equally spaced time buckets.
 /// </summary>
 public TimeSeries(TimeSeriesSpan span)
     : base(span)
 {
     _list = Enumerable.Range(0, _span.Count).Select(t =>
                                                     new KeyValuePair <DateTime, T?>(span.Begin.Add(_span.Duration * t), default)).ToList();
 }
        /// <summary>
        /// Restores a TimeSeriesStreamCollection from a compressed byte array.
        /// </summary>
        public TimeSeriesStreamCollection(byte[] compressedByteArray, int keySize, Func <Stream, TKey> readKeyFunc, TimeSeriesSpan span, int decimalPlaces = 1) : base()
        {
            Metrics = new BinaryStreamMetrics(keySize, span.Count, decimalPlaces);
            _stream = CompressableMemoryStream.FromCompressedByteArray(compressedByteArray);

            int count = 0;

            using (var reader = new BinaryReader(_stream, System.Text.Encoding.UTF8, true))
                count = reader.ReadInt32();

            foreach (var i in Enumerable.Range(0, count))
            {
                _stream.Seek(Metrics.KeyPosition(i), SeekOrigin.Begin);
                var key = readKeyFunc(_stream);

                _dict.Add(key, new TimeSeriesStream <T>(_stream, Metrics.TimeseriesPosition(i), span, decimalPlaces));
            }
        }
        /// <summary>
        /// Creates a new empty TimeSeriesStreamCollection object. It initializes an underlying MemoryStream and
        /// inits it with default values for all TimeSeries (one for each given key is created). Every write access
        /// to any TimeSeries will then be in-place on the already allocated buffer with the fixed size of
        /// keys.Count * bucketCount.
        /// </summary>
        public TimeSeriesStreamCollection(IEnumerable <TKey> keys, int keySize, Action <TKey, Stream> writeKeyAction, TimeSeriesSpan span, int decimalPlaces = 1) : base()
        {
            var keyList = keys.ToList();

            Metrics = new BinaryStreamMetrics(keySize, span.Count, decimalPlaces);

            _stream = new CompressableMemoryStream(Metrics.StreamSize(keyList.Count));
            _stream.SetLength(Metrics.StreamSize(keyList.Count));

            using (var writer = new BinaryWriter(_stream, System.Text.Encoding.UTF8, true))
                writer.Write(keyList.Count);

            foreach (var i in Enumerable.Range(0, keyList.Count))
            {
                writeKeyAction(keyList[i], _stream);

                var timeseries = new TimeSeriesStream <T>(_stream, Metrics.TimeseriesPosition(i), span, decimalPlaces);
                foreach (var item in timeseries)
                {
                    timeseries[item.Key] = null;
                }

                _dict.Add(keyList[i], timeseries);
            }
        }
 public TimeSeriesResampler(TimeSeriesSpan span, SamplingConstraint constraint)
 => (Span, Constraint) = (span, constraint);
 public TimeSeriesResampler(TimeSeriesSpan span) : this(span, SamplingConstraint.SampleAny)
 {
 }
示例#12
0
 /// <summary>
 /// TimeSeriesBase constructor for the given number of equally spaced time buckets.
 /// </summary>
 public TimeSeriesBase(TimeSeriesSpan span) => _span = span;