示例#1
0
        /// <summary>
        /// Gets the original data values by expanding
        /// sequences and applying scale and offset.
        /// </summary>
        /// <returns>A list of the original data values.</returns>
        private IList <object> GetOriginalValues()
        {
            IList <object> values         = new List <object>();
            VectorElement  valuesVector   = SeriesValues;
            StorageMethods storageMethods = Definition.StorageMethodID;

            bool    incremented = (storageMethods & StorageMethods.Increment) != 0;
            dynamic start, count, increment;

            bool    scaled = (storageMethods & StorageMethods.Scaled) != 0;
            dynamic offset = ((object)SeriesOffset != null) ? SeriesOffset.Get() : 0;
            dynamic scale  = ((object)SeriesScale != null) ? SeriesScale.Get() : 1;
            dynamic value;

            if (!scaled)
            {
                offset = 0;
                scale  = 1;
            }

            if (incremented)
            {
                start     = valuesVector.Get(0);
                count     = valuesVector.Get(1);
                increment = valuesVector.Get(2);

                for (int i = 0; i < count; i++)
                {
                    values.Add((object)(start + (i * increment)));
                }
            }
            else
            {
                for (int i = 0; i < valuesVector.Size; i++)
                {
                    values.Add(valuesVector.Get(i));
                }
            }

            if (valuesVector.TypeOfValue != PhysicalType.Timestamp)
            {
                for (int i = 0; i < values.Count; i++)
                {
                    value     = values[i];
                    values[i] = offset + (value * scale);
                }

                ApplyTransducerRatio(values);
            }

            return(values);
        }
示例#2
0
        public void TestSubstorage()
        {
            var storage = new Storage();
            var sub     = new Substorage(storage, "sub/");

            StorageMethods.Set(storage, "0", 10);
            StorageMethods.Set(storage, "1", 20);

            StorageMethods.Set(sub, "a", 18);
            Assert.AreEqual(18, storage.GetInt("sub/a"), "Wrong value");

            StorageMethods.Set(storage, "2", 30);

            StorageMethods.Set(sub, "b", "qwerty");
            Assert.IsTrue(sub.Keys.SequenceEqual(new[] { "a", "b" }));

            using (var e = sub.GetEnumerator()) {
                Assert.AreEqual(e.MoveNext() ? e.Current : default(KeyValuePair <string, string>), new KeyValuePair <string, string>("a", "18"), "Wrong value");
                Assert.AreEqual(e.MoveNext() ? e.Current : default(KeyValuePair <string, string>), new KeyValuePair <string, string>("b", "qwerty"), "Wrong value");
                Assert.IsFalse(e.MoveNext());
            }

            Assert.IsTrue(storage.Keys.SequenceEqual(new[] { "0", "1", "sub/a", "2", "sub/b" }));
        }
示例#3
0
        /// <summary>
        /// Gets the original data values by expanding
        /// sequences and applying scale and offset.
        /// </summary>
        /// <returns>A list of the original data values.</returns>
        private IList <object> GetOriginalValues()
        {
            IList <object> values         = new List <object>();
            VectorElement  valuesVector   = SeriesValues;
            StorageMethods storageMethods = Definition.StorageMethodID;

            bool incremented = (storageMethods & StorageMethods.Increment) != 0;

            bool    scaled = (storageMethods & StorageMethods.Scaled) != 0;
            dynamic offset = SeriesOffset != null?SeriesOffset.Get() : 0;

            dynamic scale = SeriesScale != null?SeriesScale.Get() : 1;

            dynamic value;

            if (!scaled)
            {
                offset = 0;
                scale  = 1;
            }

            if (incremented)
            {
                dynamic rateCount = valuesVector.Get(0);

                if (rateCount > 0)
                {
                    dynamic zero  = rateCount - rateCount;
                    dynamic one   = rateCount / rateCount;
                    dynamic start = zero;

                    for (int i = 0; i < rateCount; i++)
                    {
                        int     countIndex     = i * 2 + 1;
                        int     incrementIndex = i * 2 + 2;
                        dynamic count          = valuesVector.Get(countIndex);
                        dynamic increment      = valuesVector.Get(incrementIndex);

                        for (dynamic j = zero; j < count; j += one)
                        {
                            values.Add((object)(start + j * increment));
                        }

                        start = count * increment;
                    }
                }
            }
            else
            {
                for (int i = 0; i < valuesVector.Size; i++)
                {
                    values.Add(valuesVector.Get(i));
                }
            }

            if (valuesVector.TypeOfValue != PhysicalType.Timestamp)
            {
                for (int i = 0; i < values.Count; i++)
                {
                    value     = values[i];
                    values[i] = offset + value * scale;
                }

                ApplyTransducerRatio(values);
            }

            return(values);
        }