コード例 #1
0
        // created by sudhir on 30.12.2017
        // worker thread background stuff
        // Todo stub implement piecewise fetching here like that of on demand fetch
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            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);
            ConfigurationManager _configManager   = new ConfigurationManager();

            _configManager.Initialize();
            HistoryDataAdapter _historyAdapter = new HistoryDataAdapter();

            _historyAdapter.Initialize(_configManager);
            Dictionary <object, List <PMUDataStructure> > parsedData = _historyAdapter.GetData(startTime, endTime, measurementIDs, true, false, dataRate);

            e.Result = new { parsedData = parsedData, startTime = startTime, endTime = endTime, dataRate = dataRate, measurementIDs = measurementIDs, measurementNames = measurementNames };
        }
コード例 #2
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 = "" };
        }