Пример #1
0
        /// <summary>
        /// Saves the test data.
        /// </summary>
        private void SaveData(TestData testData)
        {
            m_currentDataSet.DataSetName = HistorianCB.SelectedItem as string;
            m_currentDataSet.AggregateName = AggregateCB.SelectedItem as string;
            m_currentDataSet.PercentBad = (byte)PercentBadNP.Value;
            m_currentDataSet.PercentGood = (byte)PercentGoodNP.Value;
            m_currentDataSet.ProcessingInterval = (uint)ProcessingIntervalNP.Value;
            m_currentDataSet.Stepped = SteppedCK.Checked;
            m_currentDataSet.TreatUncertainAsBad = TreatUncertainAsBadCK.Checked;
            m_currentDataSet.UseSlopedExtrapolation = UseSlopedExtrapolationCK.Checked;

            m_currentDataSet.Name = TestData.GetName(m_currentDataSet);

            ResetRowState();

            List<TestData.DataValue> values = new List<TestData.DataValue>();
            DataView view = new DataView(m_dataset.Tables[0], "RowState = 'OK'", "Timestamp", DataViewRowState.CurrentRows);

            foreach (DataRowView row in view)
            {
                TestData.DataValue dv = new TestData.DataValue();
                dv.WrappedValue = TestData.ValidateValue(row[3]);
                dv.StatusCode = TestData.ValidateQuality(row[4]);
                dv.SourceTimestamp = TestData.ValidateTimestamp(row[0]);

                string comment = row[8] as string;

                if (!String.IsNullOrEmpty(comment))
                {
                    dv.Comment = comment;
                }

                values.Add(dv);
            }

            testData.SetProcessedValues(m_currentDataSet, values);

            if (Object.ReferenceEquals(TestNameCB.SelectedItem, m_currentDataSet))
            {
                int index = TestNameCB.SelectedIndex;
                TestNameCB.Items.RemoveAt(index);
                TestNameCB.Items.Insert(index, m_currentDataSet);
                TestNameCB.SelectedIndex = index;
            }
        }
Пример #2
0
        private void DoTest()
        {
            if (HistorianCB.SelectedItem == null)
            {
                return;
            }

            m_dataset.AcceptChanges();

            // reset row state.
            ResetRowState();

            AggregateConfiguration configuration = new AggregateConfiguration();
            configuration.TreatUncertainAsBad = TreatUncertainAsBadCK.Checked;
            configuration.PercentDataGood = (byte)PercentGoodNP.Value;
            configuration.PercentDataBad = (byte)PercentBadNP.Value;
            configuration.UseSlopedExtrapolation = UseSlopedExtrapolationCK.Checked;
            configuration.UseServerCapabilitiesDefaults = false;

            DateTime startTime = new DateTime(DateTime.UtcNow.Year, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            IAggregateCalculator calculator = Aggregators.CreateStandardCalculator(
                Aggregators.GetIdForStandardAggregate(AggregateCB.SelectedItem as string),
                (!this.TimeFlowsBackwardsCK.Checked)?startTime:startTime.AddSeconds(100),
                (this.TimeFlowsBackwardsCK.Checked)?startTime:startTime.AddSeconds(100),
                (double)ProcessingIntervalNP.Value,
                SteppedCK.Checked,
                configuration);

            SortedDictionary<DateTime, TestData.DataValue> rawValues = m_testData.GetRawValues(HistorianCB.SelectedItem as string);
            List<DataValue> processedValues = new List<DataValue>();

            List<Opc.Ua.DataValue> valuesToProcess = new List<DataValue>();

            foreach (TestData.DataValue rawValue in rawValues.Values)
            {
                valuesToProcess.Add((Opc.Ua.DataValue)rawValue);
            }

            if (TimeFlowsBackwardsCK.Checked)
            {
                valuesToProcess.Reverse();
            }

            foreach (Opc.Ua.DataValue rawValue in valuesToProcess)
            {
                if (!calculator.QueueRawValue(rawValue))
                {
                    break;
                }

                DataValue processedValue = calculator.GetProcessedValue(false);

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

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

            string sort = "Timestamp";

            if (TimeFlowsBackwardsCK.Checked)
            {
                sort += " DESC";
            }

            DataView view = new DataView(m_dataset.Tables[0], "RowState = 'OK'", sort, DataViewRowState.CurrentRows);

            int index = 0;

            foreach (DataRowView row in view)
            {
                if (index >= processedValues.Count)
                {
                    UpdateActualValue(row.Row, null, RowState.Failed);
                    continue;
                }

                TestData.DataValue actualValue = new TestData.DataValue(processedValues[index++]);
                DateTime expectedTimestamp = TestData.ValidateTimestamp(row[0]);

                if (expectedTimestamp != actualValue.SourceTimestamp)
                {
                    AddActualValue(actualValue, RowState.Failed);

                    bool found = false;

                    while (TimeFlowsBackwardsCK.Checked && expectedTimestamp < actualValue.SourceTimestamp)
                    {
                        actualValue = new TestData.DataValue(processedValues[index++]);

                        if (expectedTimestamp == actualValue.SourceTimestamp)
                        {
                            found = true;
                            break;
                        }

                        AddActualValue(actualValue, RowState.Failed);
                    }

                    if (!found)
                    {
                        continue;
                    }
                }

                StatusCode expectedQuality = TestData.ValidateQuality(row[4]);

                if (expectedQuality != actualValue.StatusCode)
                {
                    UpdateActualValue(row.Row, actualValue, RowState.Failed);
                    continue;
                }

                if (StatusCode.IsNotBad(expectedQuality))
                {
                    Variant expectedValue = TestData.ValidateValue(row[3]);

                    StatusCode? statusValue1 = expectedValue.Value as StatusCode?;

                    if (statusValue1 != null)
                    {
                        StatusCode? statusValue2 = actualValue.Value as StatusCode?;

                        if (statusValue2 == null || statusValue2.Value != statusValue1.Value)
                        {
                            UpdateActualValue(row.Row, actualValue, RowState.Failed);
                            continue;
                        }
                    }

                    else
                    {
                        double value1 = Math.Round(Convert.ToDouble(expectedValue.Value), 4);
                        double value2 = Math.Round(Convert.ToDouble(actualValue.Value), 4);

                        if (value1 != value2)
                        {
                            UpdateActualValue(row.Row, actualValue, RowState.Failed);
                            continue;
                        }
                    }
                }

                UpdateActualValue(row.Row, actualValue, RowState.Success);
            }

            // add any unexpected data at the end.
            while (index < processedValues.Count)
            {
                TestData.DataValue actualValue = new TestData.DataValue(processedValues[index++]);

                DataRowView row = FindRowByTimestamp(actualValue.SourceTimestamp);

                if (row == null)
                {
                    AddActualValue(actualValue, RowState.Failed);
                }
                else
                {
                    UpdateActualValue(row.Row, actualValue, RowState.Failed);
                }
            }

            m_dataset.AcceptChanges();
            UpdatesComplete();
        }
Пример #3
0
        private void TestDataDV_RowValidated(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (m_loading)
                {
                    return;
                }

                TestData.DataValue dv = new TestData.DataValue();

                dv.Value = TestData.ValidateValue(TestDataDV.Rows[e.RowIndex].Cells[3].FormattedValue);
                dv.StatusCode = TestData.ValidateQuality(TestDataDV.Rows[e.RowIndex].Cells[4].FormattedValue);
                dv.SourceTimestamp = TestData.ValidateTimestamp(TestDataDV.Rows[e.RowIndex].Cells[0].FormattedValue);
                dv.Comment = TestDataDV.Rows[e.RowIndex].Cells[8].FormattedValue as string;

                // update the row state.
                string rowState = TestDataDV.Rows[e.RowIndex].Cells[7].FormattedValue as string;

                if (rowState == RowState.OK.ToString() || rowState == RowState.MissingExpected.ToString())
                {
                    rowState = RowState.OK.ToString();

                    string quality = TestDataDV.Rows[e.RowIndex].Cells[4].FormattedValue as string;

                    if (String.IsNullOrEmpty(quality))
                    {
                        rowState = RowState.MissingExpected.ToString();
                    }
                    else
                    {
                        if (StatusCode.IsNotBad(dv.StatusCode))
                        {
                            string value = TestDataDV.Rows[e.RowIndex].Cells[3].FormattedValue as string;

                            if (String.IsNullOrEmpty(value))
                            {
                                rowState = RowState.MissingExpected.ToString();
                            }
                        }
                    }

                    TestDataDV.Rows[e.RowIndex].Cells[7].Value = rowState;
                }

                UpdatesComplete();
            }
            catch (Exception exception)
            {
                TestDataDV.Rows[e.RowIndex].ErrorText = exception.Message;
            }
        }