Esempio n. 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();
            PspDataAdapter adapter = new PspDataAdapter {
                ConfigurationManager = configManager
            };
            Dictionary <string, List <PspDataLayer.DataPoint> > res = await adapter.GetDataAsync(startTime, endTime, MeasLabel);

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

                List <PspDataLayer.DataPoint> dataResults = res.Values.ElementAt(0);
                for (int resIter = 0; resIter < dataResults.Count; resIter++)
                {
                    DateTime dataTime = dataResults[resIter].Time;
                    // 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);
                    dataPoints.Add(dataPoint);
                }

                // Create dataPoints based on the fetch strategy and max Resolution
                dataPoints = FetchHelper.GetDataPointsWithGivenMaxSampleInterval(dataPoints, MaxResolution, SamplingStrategy, DateTimeAxis.ToDouble(startTime));
            }
            return(dataPoints);
        }
        public async Task GetDataAsyncTest()
        {
            try
            {
                ConfigurationManagerJSON config      = new ConfigurationManagerJSON();
                PspDataAdapter           dataAdapter = new PspDataAdapter {
                    ConfigurationManager = config
                };
                string   measLabel = "gujarat_thermal_mu";
                DateTime fromTime  = DateTime.Now.AddDays(-10);
                DateTime toTime    = DateTime.Now.AddDays(-1);
                Dictionary <string, List <DataPoint> > result = await dataAdapter.GetDataAsync(fromTime, toTime, measLabel);

                if (result[measLabel].Count == 0)
                {
                    Assert.Fail("No data was returned");
                }
                else
                {
                    if (!result[measLabel][0].Time.Day.Equals(fromTime.Day))
                    {
                        Assert.Fail("Start data point date was not the requested one");
                    }
                    if (!result[measLabel].Last().Time.Day.Equals(toTime.Day))
                    {
                        Assert.Fail("End data point date was not the requested one");
                    }
                }
            }
            catch (Exception e)
            {
                Assert.Fail($"PSP Data adapter get async data failed by throwing error - {e.Message}");
            }
        }
        private async void PopulatePspLabelsAsync()
        {
            // get the label objects from psp data layer
            ConfigurationManagerJSON configManager = new ConfigurationManagerJSON();

            configManager.Initialize();
            PspDataAdapter adapter = new PspDataAdapter {
                ConfigurationManager = configManager
            };
            List <PspLabelApiItem> results = await adapter.GetMeasurementLabelsAsync();

            // Bind the list view with psp label items
            lvMeasurements.ItemsSource = results;

            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvMeasurements.ItemsSource);

            view.Filter = MeasurementsFilter;
        }