Ejemplo n.º 1
0
        public IEnumerable <PIPoint> Search(string query)
        {
            var queries = PIPointQuery.ParseQuery(_server, query);
            var points  = PIPoint.FindPIPoints(_server, queries);

            return(points);
        }
        public void ArchiveQueryTest(string pointMask, string startTime, string endTime, double minValue, double maxValue)
        {
            var now = AFTime.Now;
            var st  = new AFTime(startTime, now);
            var et  = new AFTime(endTime, now);

            Output.WriteLine($"Start to execute PI Data Archive queries on PI Points matching [{pointMask}] " +
                             $"between [{st}] and [{et}].");

            IList <IEnumerable <PIPointQuery> > queries = PIPointQuery.ParseQuery(Fixture.PIServer, pointMask);
            IEnumerable <PIPoint>          pointList    = PIPoint.FindPIPoints(Fixture.PIServer, queries).ToList();
            IDictionary <string, AFValues> events       = Fixture.ReadPIEvents(pointList, st, et);

            // Verify all event values are in the expected range
            foreach (var ptvaluespair in events)
            {
                foreach (var val in ptvaluespair.Value.Where(val => val.IsGood))
                {
                    var convertedValue = Convert.ToDouble(val.Value, CultureInfo.InvariantCulture);
                    Assert.True(convertedValue >= minValue && convertedValue <= maxValue,
                                $"[{ptvaluespair.Key}] has a value [{val.Value}] outside of expected data range of " +
                                $"[{minValue} ~ {maxValue}]");
                }
            }

            Output.WriteLine($"Found {events.Sum(kvp => kvp.Value.Count)} PI events.");
        }
        public void PIPointSearchTest()
        {
            PIServer piServer = PIFixture.PIServer;
            int      numberOfPointsToCreate = 10;
            var      pointPrefix            = "PIPointSearchTest_Point";

            try
            {
                // Create PI Points
                Output.WriteLine($"Creating PI Points with prefix [{pointPrefix}].");
                var points = PIFixture.CreatePIPoints($"{pointPrefix}#", numberOfPointsToCreate);

                // Assign range of values to defined tags
                for (int i = 0; i < points.Count(); i++)
                {
                    points.ElementAt(i).UpdateValue(new AFValue(Math.Pow(-1, i + 1), null), 0);

                    // Set the Step attribute of half of the PI Points to true and half to false
                    points.ElementAt(i).SetAttribute(PICommonPointAttributes.Step, Convert.ToBoolean(1 * ((i + 1) % 2)));
                    points.ElementAt(i).SaveAttributes();
                }

                // Search PI Points with queries
                var searchQuery = $"Name:'{pointPrefix}*' value:>0";
                Output.WriteLine($"Searching for PI Points with query [{searchQuery}].");
                var parsedQuery       = PIPointQuery.ParseQuery(piServer, searchQuery);
                var searchPointsCount = PIPoint.FindPIPoints(piServer, parsedQuery).Count();
                AssertEventually.True(
                    () => PIPoint.FindPIPoints(piServer, parsedQuery).Count() == (numberOfPointsToCreate / 2),
                    TimeSpan.FromSeconds(10),
                    TimeSpan.FromSeconds(0.5),
                    $"The PI Points count do not match. Expected: {numberOfPointsToCreate / 2}, Actual: {searchPointsCount}.");

                searchQuery = $"Name:'{pointPrefix}*'";
                Output.WriteLine($"Searching for PI Points with query [{searchQuery}].");
                parsedQuery       = PIPointQuery.ParseQuery(piServer, searchQuery);
                searchPointsCount = PIPoint.FindPIPoints(piServer, parsedQuery).Count();
                AssertEventually.True(
                    () => PIPoint.FindPIPoints(piServer, parsedQuery).Count() == numberOfPointsToCreate,
                    TimeSpan.FromSeconds(10),
                    TimeSpan.FromSeconds(0.5),
                    $"The PI Points count do not match. Expected: {numberOfPointsToCreate}, Actual: {searchPointsCount}.");

                searchQuery = $"Name:'{pointPrefix}*' step:=0";
                Output.WriteLine($"Searching for PI Points with query [{searchQuery}].");
                parsedQuery       = PIPointQuery.ParseQuery(piServer, searchQuery);
                searchPointsCount = PIPoint.FindPIPoints(piServer, parsedQuery).Count();
                AssertEventually.True(
                    () => PIPoint.FindPIPoints(piServer, parsedQuery).Count() == (numberOfPointsToCreate / 2),
                    TimeSpan.FromSeconds(10),
                    TimeSpan.FromSeconds(0.5),
                    $"The PI Points count do not match. Expected: {numberOfPointsToCreate / 2}, Actual: {searchPointsCount}.");
            }
            finally
            {
                PIFixture.DeletePIPoints("PIPointSearchTest_Point*", Output);
            }
        }
        public void PointSearchTest(string query, int expectedCount)
        {
            Output.WriteLine($"Search for PI Points using the query [{query}]. Expect to find {expectedCount} PI Points.");
            IList <IEnumerable <PIPointQuery> > queries = PIPointQuery.ParseQuery(Fixture.PIServer, query);
            IEnumerable <PIPoint> pointList             = PIPoint.FindPIPoints(Fixture.PIServer, queries).ToList();
            int actualCount = pointList.Count();

            Assert.True(actualCount == expectedCount,
                        $"Query [{query}] resulted in {actualCount} PI Points, expected {expectedCount}.");
        }
Ejemplo n.º 5
0
        public PIPointsProvider(string query, PIServer server)
        {
            var queries = PIPointQuery.ParseQuery(server, query);

            if (queries == null || queries.Count < 1)
            {
                throw new Exception("The query passed was invalid, it would not find any PI Point");
            }

            Points = PIPoint.FindPIPoints(server, queries);
        }
        public void SineWaveEventsTest()
        {
            string query = $"name:{PIFixture.SineWavePointNameMask} AND PointSource:{PIFixture.TestPIPointSource}";

            Output.WriteLine($"Start to verify the SineWave wave pattern in PI Points matching [{query}] in the past one day.");
            IList <IEnumerable <PIPointQuery> > queries = PIPointQuery.ParseQuery(Fixture.PIServer, query);
            IEnumerable <PIPoint>          pointList    = PIPoint.FindPIPoints(Fixture.PIServer, queries).ToList();
            IDictionary <string, AFValues> sineEvents   = Fixture.ReadPIEvents(pointList, new AFTime("*-1d"), AFTime.Now);

            int totalCheckedEventCount = 0;

            foreach (KeyValuePair <string, AFValues> kvp in sineEvents)
            {
                // Use Distinct() in case there are duplicate archived events
                var timedEvents = kvp.Value.Distinct().ToDictionary(val => val.Timestamp.LocalTime, val => val.ValueAsDouble());

                // Start for the oldest event and check events one by one
                foreach (KeyValuePair <DateTime, double> evt in timedEvents)
                {
                    var timestampAfterAHalfWave = evt.Key.AddSeconds(PIFixture.SineWaveLengthInHours * 1800);
                    var timestampAfterOneWave   = evt.Key.AddSeconds(PIFixture.SineWaveLengthInHours * 3600);

                    if (timedEvents.ContainsKey(timestampAfterAHalfWave) && timedEvents.ContainsKey(timestampAfterOneWave))
                    {
                        // Based on the SineWave pattern, the current value should be equal to -1 * the value
                        // after a half wave and the value after a full wave.
                        Assert.True(
                            Math.Abs(evt.Value - (-1 * timedEvents[timestampAfterAHalfWave])) < PIFixture.Epsilon,
                            $"Found events in [{kvp.Key}] at [{evt.Key}] and [{timestampAfterAHalfWave}] not matching the SineWave pattern.");
                        Assert.True(
                            Math.Abs(evt.Value - timedEvents[timestampAfterOneWave]) < PIFixture.Epsilon,
                            $"Found events in [{kvp.Key}] at [{evt.Key}] and [{timestampAfterOneWave}] not matching the SineWave pattern.");

                        totalCheckedEventCount++;
                    }
                    else
                    {
                        // If the data set does not contain a key of timestampAfterOneWave, it means we have reached the end of set.
                        break;
                    }
                }
            }

            Output.WriteLine($"Successfully verified a total of {totalCheckedEventCount} SineWave values in {sineEvents.Count} PI Points.");
        }