Reads an item history from a file.
Exemplo n.º 1
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        public void ReloadFromSource(SystemContext context)
        {
            LoadConfiguration(context);

            if (m_archiveItem.LastLoadTime == DateTime.MinValue || (m_archiveItem.Persistent && m_archiveItem.LastLoadTime.AddSeconds(10) < DateTime.UtcNow))
            {
                DataFileReader reader = new DataFileReader();
                reader.LoadHistoryData(context, m_archiveItem);

                // set the start of the archive.
                if (m_archiveItem.DataSet.Tables[0].DefaultView.Count > 0)
                {
                    m_configuration.StartOfArchive.Value       = (DateTime)m_archiveItem.DataSet.Tables[0].DefaultView[0].Row[0];
                    m_configuration.StartOfOnlineArchive.Value = m_configuration.StartOfArchive.Value;
                }

                if (m_archiveItem.Archiving)
                {
                    // save the pattern used to produce new data.
                    m_pattern = new List <DataValue>();

                    foreach (DataRowView row in m_archiveItem.DataSet.Tables[0].DefaultView)
                    {
                        DataValue value = (DataValue)row.Row[2];
                        m_pattern.Add(value);
                        m_nextSampleTime = value.SourceTimestamp.AddMilliseconds(m_archiveItem.SamplingInterval);
                    }

                    // fill in data until the present time.
                    m_patternIndex = 0;
                    NewSamples(context);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the configuration.
        /// </summary>
        public void LoadConfiguration(SystemContext context)
        {
            DataFileReader reader = new DataFileReader();

            if (reader.LoadConfiguration(context, m_archiveItem))
            {
                this.DataType    = (uint)m_archiveItem.DataType;
                this.ValueRank   = m_archiveItem.ValueRank;
                this.Historizing = m_archiveItem.Archiving;

                m_configuration.MinTimeInterval.Value = m_archiveItem.SamplingInterval;
                m_configuration.MaxTimeInterval.Value = m_archiveItem.SamplingInterval;
                m_configuration.Stepped.Value         = m_archiveItem.Stepped;

                AggregateConfiguration configuration = m_archiveItem.AggregateConfiguration;
                m_configuration.AggregateConfiguration.PercentDataGood.Value        = configuration.PercentDataGood;
                m_configuration.AggregateConfiguration.PercentDataBad.Value         = configuration.PercentDataBad;
                m_configuration.AggregateConfiguration.UseSlopedExtrapolation.Value = configuration.UseSlopedExtrapolation;
                m_configuration.AggregateConfiguration.TreatUncertainAsBad.Value    = configuration.TreatUncertainAsBad;
            }
        }
Exemplo n.º 3
0
        static void DoTest(TestCase test, string filePath)
        {
            List <DataValue> expectedValues = GetExpectedResults(test.ExpectedResultsPath, test.TestId);

            ArchiveItem item = new ArchiveItem(test.DataPath, Assembly.GetExecutingAssembly(), test.DataPath);

            DataFileReader reader = new DataFileReader();

            reader.LoadConfiguration(null, item);
            reader.LoadHistoryData(null, item);

            AggregateConfiguration configuration = new AggregateConfiguration();

            configuration.PercentDataBad                = 100;
            configuration.PercentDataGood               = 100;
            configuration.TreatUncertainAsBad           = test.TreatUncertainAsBad;
            configuration.UseSlopedExtrapolation        = test.UseSlopedExtrapolation;
            configuration.UseServerCapabilitiesDefaults = false;

            DateTime startTime = DateTime.UtcNow;

            startTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0, DateTimeKind.Utc);

            AggregateCalculator calculator = new AggregateCalculator(
                test.AggregateId,
                startTime.AddSeconds(0),
                startTime.AddSeconds(100),
                5000,
                test.Stepped,
                configuration);

            StringBuilder    buffer = new StringBuilder();
            List <DataValue> values = new List <DataValue>();

            foreach (DataRowView row in item.DataSet.Tables[0].DefaultView)
            {
                DataValue rawValue = (DataValue)row.Row[2];

                if (!calculator.QueueRawValue(rawValue))
                {
                    Utils.Trace("Oops!");
                    continue;
                }

                DataValue processedValue = calculator.GetProcessedValue(false);

                if (processedValue != null)
                {
                    values.Add(processedValue);
                }
            }

            for (DataValue processedValue = calculator.GetProcessedValue(true); processedValue != null; processedValue = calculator.GetProcessedValue(true))
            {
                values.Add(processedValue);
            }

            for (int ii = 0; ii < values.Count && ii < expectedValues.Count; ii++)
            {
                if (values[ii].SourceTimestamp != expectedValues[ii].SourceTimestamp)
                {
                    Utils.Trace("Wrong Status Timestamp");
                    continue;
                }

                if (values[ii].StatusCode != expectedValues[ii].StatusCode)
                {
                    Utils.Trace("Wrong Status Code");
                    continue;
                }

                if (StatusCode.IsNotBad(values[ii].StatusCode))
                {
                    double value1 = Math.Round(Convert.ToDouble(values[ii].Value), 4);
                    double value2 = Math.Round(Convert.ToDouble(expectedValues[ii].Value), 4);

                    if (value1 != value2)
                    {
                        Utils.Trace("Wrong Value");
                        continue;
                    }
                }
            }

            foreach (DataValue processedValue in values)
            {
                buffer.Append(processedValue.SourceTimestamp.ToString("HH:mm:ss"));
                buffer.Append(", ");
                buffer.Append(processedValue.WrappedValue);
                buffer.Append(", ");
                buffer.Append(new StatusCode(processedValue.StatusCode.CodeBits));
                buffer.Append(", ");
                buffer.Append(processedValue.StatusCode.AggregateBits);
                buffer.Append("\r\n");
            }

            // write to the file.
            using (StreamWriter writer = new StreamWriter(filePath))
            {
                writer.Write(buffer.ToString());
            }
        }
Exemplo n.º 4
0
        static void DoTest(TestCase test, string filePath)
        {
            List<DataValue> expectedValues = GetExpectedResults(test.ExpectedResultsPath, test.TestId);

            ArchiveItem item = new ArchiveItem(test.DataPath, Assembly.GetExecutingAssembly(), test.DataPath);

            DataFileReader reader = new DataFileReader();
            reader.LoadConfiguration(null, item);
            reader.LoadHistoryData(null, item);

            AggregateConfiguration configuration = new AggregateConfiguration();
            configuration.PercentDataBad = 100;
            configuration.PercentDataGood = 100;
            configuration.TreatUncertainAsBad = test.TreatUncertainAsBad;
            configuration.UseSlopedExtrapolation = test.UseSlopedExtrapolation;
            configuration.UseServerCapabilitiesDefaults = false;

            DateTime startTime = DateTime.UtcNow;
            startTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0, DateTimeKind.Utc);

            AggregateCalculator calculator = new AggregateCalculator(
                test.AggregateId,
                startTime.AddSeconds(0),
                startTime.AddSeconds(100),
                5000,
                test.Stepped,
                configuration);

            StringBuilder buffer = new StringBuilder();
            List<DataValue> values = new List<DataValue>();

            foreach (DataRowView row in item.DataSet.Tables[0].DefaultView)
            {
                DataValue rawValue = (DataValue)row.Row[2];

                if (!calculator.QueueRawValue(rawValue))
                {
                    Utils.Trace("Oops!");
                    continue;
                }

                DataValue processedValue = calculator.GetProcessedValue(false);

                if (processedValue != null)
                {
                    values.Add(processedValue);
                }
            }

            for (DataValue processedValue = calculator.GetProcessedValue(true); processedValue != null; processedValue = calculator.GetProcessedValue(true))
            {
                values.Add(processedValue);
            }

            for (int ii = 0; ii < values.Count && ii < expectedValues.Count; ii++)
            {
                if (values[ii].SourceTimestamp != expectedValues[ii].SourceTimestamp)
                {
                    Utils.Trace("Wrong Status Timestamp");
                    continue;
                }

                if (values[ii].StatusCode != expectedValues[ii].StatusCode)
                {
                    Utils.Trace("Wrong Status Code");
                    continue;
                }

                if (StatusCode.IsNotBad(values[ii].StatusCode))
                {
                    double value1 = Math.Round(Convert.ToDouble(values[ii].Value), 4);
                    double value2 = Math.Round(Convert.ToDouble(expectedValues[ii].Value), 4);

                    if (value1 != value2)
                    {
                        Utils.Trace("Wrong Value");
                        continue;
                    }
                }
            }
            
            foreach (DataValue processedValue in values)
            {
                buffer.Append(processedValue.SourceTimestamp.ToString("HH:mm:ss"));
                buffer.Append(", ");
                buffer.Append(processedValue.WrappedValue);
                buffer.Append(", ");
                buffer.Append(new StatusCode(processedValue.StatusCode.CodeBits));
                buffer.Append(", ");
                buffer.Append(processedValue.StatusCode.AggregateBits);
                buffer.Append("\r\n");
            }

            // write to the file.
            using (StreamWriter writer = new StreamWriter(filePath))
            {
                writer.Write(buffer.ToString());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        public void ReloadFromSource(SystemContext context)
        {
            LoadConfiguration(context);

            if (m_archiveItem.LastLoadTime == DateTime.MinValue || (m_archiveItem.Persistent && m_archiveItem.LastLoadTime.AddSeconds(10) < DateTime.UtcNow))
            {
                DataFileReader reader = new DataFileReader();
                reader.LoadHistoryData(context, m_archiveItem);

                // set the start of the archive.
                if (m_archiveItem.DataSet.Tables[0].DefaultView.Count > 0)
                {
                    m_configuration.StartOfArchive.Value = (DateTime)m_archiveItem.DataSet.Tables[0].DefaultView[0].Row[0];
                    m_configuration.StartOfOnlineArchive.Value = m_configuration.StartOfArchive.Value;
                }

                if (m_archiveItem.Archiving)
                {
                    // save the pattern used to produce new data.
                    m_pattern = new List<DataValue>();

                    foreach (DataRowView row in m_archiveItem.DataSet.Tables[0].DefaultView)
                    {
                        DataValue value = (DataValue)row.Row[2];
                        m_pattern.Add(value);
                        m_nextSampleTime = value.SourceTimestamp.AddMilliseconds(m_archiveItem.SamplingInterval);
                    }

                    // fill in data until the present time.
                    m_patternIndex = 0;
                    NewSamples(context);
                }
            }

            
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads the configuration.
        /// </summary>
        public void LoadConfiguration(SystemContext context)
        {
            DataFileReader reader = new DataFileReader();

            if (reader.LoadConfiguration(context, m_archiveItem))
            {
                this.DataType = (uint)m_archiveItem.DataType;
                this.ValueRank = m_archiveItem.ValueRank;
                this.Historizing = m_archiveItem.Archiving;

                m_configuration.MinTimeInterval.Value = m_archiveItem.SamplingInterval;
                m_configuration.MaxTimeInterval.Value = m_archiveItem.SamplingInterval;
                m_configuration.Stepped.Value = m_archiveItem.Stepped;

                AggregateConfiguration configuration = m_archiveItem.AggregateConfiguration;
                m_configuration.AggregateConfiguration.PercentDataGood.Value = configuration.PercentDataGood;
                m_configuration.AggregateConfiguration.PercentDataBad.Value = configuration.PercentDataBad;
                m_configuration.AggregateConfiguration.UseSlopedExtrapolation.Value = configuration.UseSlopedExtrapolation;
                m_configuration.AggregateConfiguration.TreatUncertainAsBad.Value = configuration.TreatUncertainAsBad;
            }
        }