예제 #1
0
        public HistoryExtract BuildHistoryExtract(string componentUid, string statusUid, DateTime rangeStart, DateTime rangeEnd, TimeSpan interval, HistoryExtractDataType dataType)
        {
            var historyExtract = new HistoryExtractBuilder(_repository).Build(componentUid, statusUid, rangeStart, rangeEnd, interval, dataType);

            for (var i = historyExtract.DataPoints.Count - 1; i > 0; i--)
            {
            }

            return(historyExtract);
        }
예제 #2
0
        public void HistoryExtract_Build_Simple()
        {
            var repo = HistoryRepositoryTests.CreateRepository();

            repo.ComponentStatusOutdatedTimeout = TimeSpan.FromHours(2);
            try
            {
                var startDateTime = DateTime.UtcNow;

                var componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("0", startDateTime);
                repo.UpdateComponentStatusValue(componentStatusValue);
                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("0", startDateTime.AddMinutes(59));
                repo.UpdateComponentStatusValue(componentStatusValue);

                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("1", startDateTime.AddHours(1));
                repo.UpdateComponentStatusValue(componentStatusValue);
                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("1", startDateTime.AddHours(1).AddMinutes(59));
                repo.UpdateComponentStatusValue(componentStatusValue);

                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("2", startDateTime.AddHours(2));
                repo.UpdateComponentStatusValue(componentStatusValue);
                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("2", startDateTime.AddHours(2).AddMinutes(59));
                repo.UpdateComponentStatusValue(componentStatusValue);

                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("3", startDateTime.AddHours(3));
                repo.UpdateComponentStatusValue(componentStatusValue);
                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("3", startDateTime.AddHours(3).AddMinutes(59));
                repo.UpdateComponentStatusValue(componentStatusValue);

                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("4", startDateTime.AddHours(4));
                repo.UpdateComponentStatusValue(componentStatusValue);
                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("4", startDateTime.AddHours(4).AddMinutes(59));
                repo.UpdateComponentStatusValue(componentStatusValue);

                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("5", startDateTime.AddHours(5));
                repo.UpdateComponentStatusValue(componentStatusValue);
                componentStatusValue = HistoryRepositoryTests.CreateComponentStatusValue("5", startDateTime.AddHours(5).AddMinutes(59));
                repo.UpdateComponentStatusValue(componentStatusValue);

                var entities = repo.GetComponentStatusValues("c1", "s1");
                Assert.AreEqual(6, entities.Count);

                var extract = new HistoryExtractBuilder(repo).Build(
                    "c1",
                    "s1",
                    startDateTime,
                    startDateTime.AddHours(5),
                    TimeSpan.FromMinutes(5),
                    HistoryExtractDataType.Text);

                Assert.AreEqual(6, extract.EntityCount);
                Assert.AreEqual(61, extract.DataPoints.Count);

                var expectedValue = "0";
                var counter       = 0;
                foreach (var dataPoint in extract.DataPoints)
                {
                    Assert.AreEqual(expectedValue, dataPoint.Value);

                    counter++;

                    if (counter >= 49)
                    {
                        expectedValue = "4";
                    }
                    else if (counter >= 37)
                    {
                        expectedValue = "3";
                    }
                    else if (counter >= 25)
                    {
                        expectedValue = "2";
                    }
                    else if (counter >= 13)
                    {
                        expectedValue = "1";
                    }
                }
            }
            finally
            {
                repo.Delete();
            }
        }