Exemple #1
0
        public MainWindow()
        {
            InitializeComponent();
            String str = (String)((App)Application.Current).Properties["FilePathArgName"];

            openFileName(str);

            _configManager = new ConfigurationManager();
            _configManager.Initialize();
            _historyAdapter = new HistoryDataAdapter();
            _historyAdapter.Initialize(_configManager);
            SeriesCollection = new SeriesCollection();
            timeStamps_      = new List <DateTime>();
            plotTemplate_    = new PlotDataTemplate();
            //Labels = new string[0];
            Step       = 1;
            YFormatter = value => String.Format("{0:0.###}", value);
            XFormatter = delegate(double val)
            {
                if (timeStamps_.Count > 0)
                {
                    DateTime startTimeStamp = timeStamps_.ElementAt(0);
                    DateTime timeStamp;
                    timeStamp = startTimeStamp.AddSeconds(val / (double)plotTemplate_.dataRate);
                    return(timeStamp.ToString("HH:mm:ss.fff"));

                    /*
                     * if (val == 0 || val == (double)(timeStamps_.Count - 1))
                     * {
                     *  timeStamp = timeStamps_.ElementAt((int)val);
                     *  return timeStamp.ToString("dd-MM-yyyy HH:mm:ss.fff");
                     * }
                     * else
                     * {
                     *  timeStamp = startTimeStamp.AddSeconds(val / (double)plotTemplate_.dataRate);
                     *  if (timeStamp.Hour == 0 && timeStamp.Minute == 0 && timeStamp.Second == 0 && timeStamp.Millisecond == 0)
                     *  {
                     *      return timeStamp.ToString("dd-MM-yyyy");
                     *  }
                     *  return timeStamp.ToString("HH:mm:ss.fff");
                     * }
                     */
                }
                return(val.ToString());
            };
            MyChart.LegendLocation = LegendLocation.Top;
            DataContext            = this;
        }
Exemple #2
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 };
        }
Exemple #3
0
        public GearedPlotWindow()
        {
            InitializeComponent();
            AddLinesToConsole("Welcome User!");
            plotTemplate_    = new PlotDataTemplate();
            AutoFetchConfig_ = new AutoFetchConfig();
            _configManager   = new ConfigurationManager();
            _configManager.Initialize();
            _historyAdapter = new HistoryDataAdapter();
            _historyAdapter.Initialize(_configManager);

            String str = (String)((App)Application.Current).Properties["FilePathArgName"];

            OpenFileName(str);
            SeriesCollection = new SeriesCollection();
            timeStamps_      = new List <DateTime> {
                DateTime.Now
            };
            //Labels = new string[0];
            Step       = 1;
            YFormatter = value => String.Format("{0:0.###}", value);
            XFormatter = delegate(double val)
            {
                if (timeStamps_.Count > 0)
                {
                    DateTime startTimeStamp = timeStamps_.ElementAt(0);
                    DateTime timeStamp;
                    timeStamp = startTimeStamp.AddSeconds(val / 25.0);
                    return(timeStamp.ToString("HH:mm:ss.fff\ndd-MMM-yy"));
                }
                return(val.ToString());
            };
            MyChart.LegendLocation = LegendLocation.Top;
            DataContext            = this;
            FetchTimer_            = new DispatcherTimer();
            UpdateFetcherInterval();
            FetchTimer_.Tick += Fetch_Timer_Tick;
        }
Exemple #4
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 = "" };
        }