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); }
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}"); } }
public async Task <Dictionary <object, List <PMUDataStructure> > > GetLineDataAsync(Dictionary <string, int> measDict, DateTime startTime, DateTime endTime) { //IBM,IYA,IPM,IRM,IRA,IYM,IBA,IPA List <int> measIds = measDict.Values.ToList(); int dataRate = 25; Dictionary <object, List <PMUDataStructure> > data = await historyDataAdapter.GetDataAsync(startTime, endTime, measIds, true, false, dataRate); return(data); }
private async void FetchTestBtn_Click(object sender, RoutedEventArgs e) { // test the data fetch DateTime startTime = DateTime.Now.AddHours(-1); DateTime endTime = startTime.AddSeconds(5); Dictionary <Object, List <PMUDataStructure> > fetchResp = await historyDataAdapter.GetDataAsync(startTime, endTime, new List <int> { 5505 }, true, false, 25); }
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); } }