public PlotDataTemplate() { measIds = new List <int>(); measurementNames = new List <string>(); dataSetName = "Plot Title"; startDateMode = "variable"; startDateTime = DateTime.Now; startDateVariable = new VariableTime(); endDateMode = "variable"; endDateTime = DateTime.Now; endDateVariable = new VariableTime(); dataRate = 25; fetchWindow = new VariableTime(); }
public async Task PlotMeasIdsAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken) { AddLinesToConsole("Started fetching async data"); int dataRate = plotTemplate_.dataRate; List <int> measurementIDs = plotTemplate_.measIds; List <string> measurementNames = plotTemplate_.measurementNames; VariableTime fetchWindow = plotTemplate_.fetchWindow; if (measurementIDs.Count == 0) { return; } //ConfigurationManager _configManager = new ConfigurationManager(); //_configManager.Initialize(); //HistoryDataAdapter _historyAdapter = new HistoryDataAdapter(); //_historyAdapter.Initialize(_configManager); if (dataRate <= 0 || dataRate > 25) { // default dataRate of PMU dataRate = 25; } int numWindows = 1; // find the number of seconds in a fetch window //stub int reportFetchWindowSecs = (int)(fetchWindow.hours * 60 * 60 + fetchWindow.mins * 60 + fetchWindow.secs); if (reportFetchWindowSecs <= 0) { numWindows = 1; reportFetchWindowSecs = Convert.ToInt32(Math.Ceiling((endTime - startTime).TotalSeconds)); } else { // find the number of fetch windows as Ceil(Fetchspan/windowspan) int reportfetchSpanSecs = Convert.ToInt32(Math.Ceiling((endTime - startTime).TotalSeconds)); numWindows = reportfetchSpanSecs / reportFetchWindowSecs; } DateTime fetchEndTime = startTime; Dictionary <object, List <PMUDataStructure> > parsedData; List <PMUMeasDataLists> measurementsData = new List <PMUMeasDataLists>(); for (int window = 0; window < numWindows; window++) { // fetch and update for ith window DateTime fetchStartTime = fetchEndTime; fetchEndTime = fetchStartTime.AddSeconds(reportFetchWindowSecs); if (fetchEndTime > endTime) { fetchEndTime = endTime; } // get the data of all measurementIds for the window parsedData = await _historyAdapter.GetDataAsync(fetchStartTime, fetchEndTime, measurementIDs, true, false, dataRate); cancellationToken.ThrowIfCancellationRequested(); // check if we have atleast one measurement if (parsedData != null) { // get the data of measurements and add to List for (int i = 0; i < measurementIDs.Count; i++) { PMUMeasDataLists measurementData; measurementData = await _historyAdapter.GetDataOfMeasIdAsync(parsedData, (uint)measurementIDs.ElementAt(i), true); cancellationToken.ThrowIfCancellationRequested(); if (window == 0) { measurementsData.Add(measurementData); } else { measurementsData.ElementAt(i).pmuQualities.AddRange(measurementData.pmuQualities); measurementsData.ElementAt(i).pmuTimeStamps.AddRange(measurementData.pmuTimeStamps); measurementsData.ElementAt(i).pmuVals.AddRange(measurementData.pmuVals); } } } else { // we didnot get the required result return; } // todo update plot AddLinesToConsole($"Completed async fetching of {window + 1} of {numWindows} windows"); } // fetch completed, now update plot AddLinesToConsole("Finished async fetching data"); SeriesCollection.Clear(); // Todo change step as per the plot preferences. Step = dataRate; // get 1st measurement Data and add to SeriesCollection, also update the timestamps and dataRate PMUMeasDataLists lists = measurementsData.ElementAt(0); timeStamps_ = new List <DateTime>(lists.pmuTimeStamps); SeriesCollection.Add(new GLineSeries() { Title = measurementNames.ElementAt(0) + "_" + measurementIDs.ElementAt(0).ToString(), Values = new GearedValues <float>(lists.pmuVals), PointGeometry = null, Fill = Brushes.Transparent, StrokeThickness = 2, LineSmoothness = 0 }); // get the data of remaining measurements and add to SeriesCollection for (int i = 1; i < measurementIDs.Count; i++) { lists = measurementsData.ElementAt(i); SeriesCollection.Add(new GLineSeries() { Title = measurementNames.ElementAt(i).ToString() + "_" + measurementIDs.ElementAt(i).ToString(), Values = new GearedValues <float>(lists.pmuVals), PointGeometry = null, Fill = Brushes.Transparent, StrokeThickness = 2, LineSmoothness = 0 }); } }
// worker thread background stuff // Todo update immediately on the chart after the piecewise fetch void Worker_DoWork(object sender, DoWorkEventArgs e) { // todo refer template manager for for doing the piecewise fetch object argument = e.Argument; int dataRate = (int)argument.GetType().GetProperty("dataRate").GetValue(argument, null); DateTime startTime = (DateTime)argument.GetType().GetProperty("startTime").GetValue(argument, null); DateTime endTime = (DateTime)argument.GetType().GetProperty("endTime").GetValue(argument, null); List <int> measurementIDs = (List <int>)argument.GetType().GetProperty("measurementIDs").GetValue(argument, null); List <string> measurementNames = (List <string>)argument.GetType().GetProperty("measurementNames").GetValue(argument, null); VariableTime fetchWindow = (VariableTime)argument.GetType().GetProperty("fetchWindow").GetValue(argument, null); if (measurementIDs.Count == 0) { object nullVal = null; e.Result = new { measurementsData = nullVal, startTime = startTime, endTime = endTime, dataRate = dataRate, measurementIDs = measurementIDs, measurementNames = measurementNames, isSuccess = false, errorMsg = "Number of measurements are zero..." }; return; } ConfigurationManager _configManager = new ConfigurationManager(); _configManager.Initialize(); HistoryDataAdapter _historyAdapter = new HistoryDataAdapter(); _historyAdapter.Initialize(_configManager); if (dataRate <= 0 || dataRate > 25) { // default dataRate of PMU dataRate = 25; } int numWindows = 1; // find the number of seconds in a fetch window //stub int reportFetchWindowSecs = (int)(fetchWindow.hours * 60 * 60 + fetchWindow.mins * 60 + fetchWindow.secs); if (reportFetchWindowSecs <= 0) { numWindows = 1; reportFetchWindowSecs = Convert.ToInt32(Math.Ceiling((endTime - startTime).TotalSeconds)); } else { // find the number of fetch windows as Ceil(Fetchspan/windowspan) int reportfetchSpanSecs = Convert.ToInt32(Math.Ceiling((endTime - startTime).TotalSeconds)); numWindows = reportfetchSpanSecs / reportFetchWindowSecs; } DateTime fetchEndTime = startTime; Dictionary <object, List <PMUDataStructure> > parsedData; List <PMUMeasDataLists> measurementsData = new List <PMUMeasDataLists>(); for (int window = 0; window < numWindows; window++) { // fetch and update for ith window DateTime fetchStartTime = fetchEndTime; fetchEndTime = fetchStartTime.AddSeconds(reportFetchWindowSecs); if (fetchEndTime > endTime) { fetchEndTime = endTime; } // get the data of all measurementIds for the window parsedData = _historyAdapter.GetData(fetchStartTime, fetchEndTime, measurementIDs, true, false, dataRate); // check if we have atleast one measurement if (measurementIDs.Count > 0 && parsedData != null) { // get the data of measurements and add to List for (int i = 0; i < measurementIDs.Count; i++) { PMUMeasDataLists measurementData; measurementData = _historyAdapter.GetDataOfMeasId(parsedData, (uint)measurementIDs.ElementAt(i), true); if (window == 0) { measurementsData.Add(measurementData); } else { measurementsData.ElementAt(i).pmuQualities.AddRange(measurementData.pmuQualities); measurementsData.ElementAt(i).pmuTimeStamps.AddRange(measurementData.pmuTimeStamps); measurementsData.ElementAt(i).pmuVals.AddRange(measurementData.pmuVals); } } } else { // we didnot get the required result e.Result = new { measurementsData = measurementsData, startTime = startTime, endTime = endTime, dataRate = dataRate, measurementIDs = measurementIDs, measurementNames = measurementNames, isSuccess = false, errorMsg = "Unable to parse data..." }; return; } (sender as BackgroundWorker).ReportProgress(window, new { numWindows = numWindows }); } e.Result = new { measurementsData = measurementsData, startTime = startTime, endTime = endTime, dataRate = dataRate, measurementIDs = measurementIDs, measurementNames = measurementNames, isSuccess = true, errorMsg = "" }; }
public AutoFetchConfig(VariableTime timePeriod_) { TimePeriod_ = timePeriod_; }
public AutoFetchConfig() { TimePeriod_ = new VariableTime(0, 0, 5); }