Exemple #1
0
        public async Task <List <DataPoint> > FetchData(DateTime startTime, DateTime endTime)
        {
            List <DataPoint> dataPoints = new List <DataPoint>();

            // using data layer for fetching data
            ConfigurationManagerJSON configManager = new ConfigurationManagerJSON();

            configManager.Initialize();
            HistoryDataAdapter adapter = new HistoryDataAdapter(configManager);
            List <int>         measIds = new List <int> {
                MeasId
            };
            Dictionary <object, List <PMUDataStructure> > res = await adapter.GetDataAsync(startTime, endTime, measIds, true, false, 25);

            // check if result has one key since we queried for only one key
            if (res.Keys.Count == 1)
            {
                // todo check the measId also

                List <PMUDataStructure> dataResults = res.Values.ElementAt(0);
                for (int resIter = 0; resIter < dataResults.Count; resIter++)
                {
                    DateTime dataTime = dataResults[resIter].TimeStamp;
                    // convert the time from utc to local
                    dataTime = DateTime.SpecifyKind((TimeZoneInfo.ConvertTime(dataTime, TimeZoneInfo.Utc, TimeZoneInfo.Local)), DateTimeKind.Local);
                    DataPoint dataPoint = new DataPoint(DateTimeAxis.ToDouble(dataTime), dataResults[resIter].Value[0]);
                    dataPoints.Add(dataPoint);
                }

                // Create dataPoints based on the fetch strategy and max Resolution
                dataPoints = FetchHelper.GetDataPointsWithGivenMaxSampleInterval(dataPoints, MaxResolution, SamplingStrategy, DateTimeAxis.ToDouble(startTime));
            }
            return(dataPoints);
        }
Exemple #2
0
 public FaultSortEngine(ConfigManager configuration, PgConfig pgConfig)
 {
     historyDataAdapter = new HistoryDataAdapter();
     PgAdapter          = new PgAdapter(pgConfig);
     historyDataAdapter.Initialize(configuration);
     DoInitialStuff();
 }
Exemple #3
0
        public async Task GetDataAsyncTestAsync()
        {
            try
            {
                HistoryDataAdapter adapter   = new HistoryDataAdapter(new ConfigurationManagerJSON());
                DateTime           startTime = DateTime.Now.AddMinutes(-2);
                DateTime           endTime   = startTime.AddMinutes(1);
                List <int>         measIds   = new List <int> {
                    4924
                };
                Dictionary <object, List <PMUDataStructure> > res = await adapter.GetDataAsync(startTime, endTime, measIds, true, false, 25);

                // check if start time is expected
                DateTime dataTime = res.Values.ElementAt(0)[0].TimeStamp;
                // convert the time from utc to local
                dataTime = DateTime.SpecifyKind((TimeZoneInfo.ConvertTime(dataTime, TimeZoneInfo.Utc, TimeZoneInfo.Local)), DateTimeKind.Local);
                TimeSpan timeDiff = dataTime - startTime;
                Assert.AreEqual(timeDiff.TotalMilliseconds, 0);

                // check of result has keys with count same as measIds
                Assert.AreEqual(measIds.Count, res.Keys.Count);

                // since we are testing for full resolution, check if we have numSecs*25 samples
                Assert.AreEqual(res.Values.ElementAt(0).Count, Math.Floor((endTime - startTime).TotalSeconds) * 25);
            }
            catch (Exception e)
            {
                Assert.Fail($"PMU History Data adapter get async data failed by throwing error - {e.Message}");
            }
        }
Exemple #4
0
        public void HistoryDataAdapterTest()
        {
            ConfigurationManagerJSON configuration;
            HistoryDataAdapter       adapter;

            //constructor creation test
            try
            {
                configuration = new ConfigurationManagerJSON();
                adapter       = new HistoryDataAdapter(configuration);
            }
            catch (Exception)
            {
                Assert.Fail("PMU History Data adapter initialization by constructor failed");
            }

            // initialization after construction test
            try
            {
                configuration = new ConfigurationManagerJSON();
                adapter       = new HistoryDataAdapter();
                adapter.Initialize(configuration);
            }
            catch (Exception)
            {
                Assert.Fail("PMU History Data adapter initialization after construction failed");
            }
        }
Exemple #5
0
 public MainWindow()
 {
     InitializeComponent();
     configurationManager = new ConfigManager();
     configurationManager.Initialize();
     historyDataAdapter = new HistoryDataAdapter();
     historyDataAdapter.Initialize(configurationManager);
 }
Exemple #6
0
        private void FetchAndPopulatePMUMeasurements()
        {
            // get the label objects from psp data layer
            ConfigurationManagerJSON configManager = new ConfigurationManagerJSON();

            configManager.Initialize();
            HistoryDataAdapter adapter = new HistoryDataAdapter(configManager);

            measXml = adapter.GetMeasXml();
            // Bind the tree view with xml
            //SetTreeViewElements(measXml);
            SetMeasDataTable();
            SaveMeasXml();
        }
        public async Task GetDataTestAsync()
        {
            try
            {
                ConfigManager configurationManager = new ConfigManager();
                configurationManager.Initialize();
                HistoryDataAdapter historyDataAdapter = new HistoryDataAdapter();
                historyDataAdapter.Initialize(configurationManager);
                // test the data fetch
                DateTime startTime = DateTime.Now.AddHours(-1);
                DateTime endTime   = startTime.AddSeconds(5);

                int testKey  = 5505;
                int dataRate = 25;
                Dictionary <Object, List <PMUDataStructure> > fetchResp = await historyDataAdapter.GetDataAsync(startTime, endTime, new List <int> {
                    testKey
                }, true, false, dataRate);

                // check if we got exactly one key
                Assert.AreEqual(fetchResp.Count, 1);

                Assert.AreEqual((uint)fetchResp.Keys.ElementAt(0), (uint)testKey);

                // get the data of the key
                if (!fetchResp.TryGetValue((uint)testKey, out List <PMUDataStructure> measData))
                {
                    // the key isn't in the dictionary.
                    Assert.Fail("Did not get data from the history data adapter dictionary via the measurement key");
                }

                // Test the data list length as per the time span
                Assert.IsTrue(measData.Count == endTime.Subtract(startTime).Seconds *dataRate, "Got unexpected rows for a timespan");

                // check if we are not getting null data
                Assert.IsTrue(measData[0] != null, "Got a null data first row of the measurement");
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
Exemple #8
0
 public FaultSortEngine()
 {
     historyDataAdapter = new HistoryDataAdapter();
     historyDataAdapter.Initialize();
     DoInitialStuff();
 }