예제 #1
0
        void UC_CurveChart_Loaded(object sender, RoutedEventArgs e)
        {
            List <HouseData> houseDataList = LoadHouseData("..\\..\\Data.txt");

            DateTime[] dates = new DateTime[houseDataList.Count];
            int[]      numberSalesCompletion = new int[houseDataList.Count];
            int[]      numberRentCompletion  = new int[houseDataList.Count];
            int[]      numberSalesTarget     = new int[houseDataList.Count];
            int[]      numberRentTarget      = new int[houseDataList.Count];
            int        totalSalesCompletion  = 0;
            int        totalRentCompletion   = 0;

            for (int i = 0; i < houseDataList.Count; ++i)
            {
                dates[i] = houseDataList[i].date;
                numberSalesCompletion[i] = houseDataList[i].i_SalesCompletion;
                numberRentCompletion[i]  = houseDataList[i].i_RentCompletion;
                numberSalesTarget[i]     = houseDataList[i].i_SalesTarget;
                numberRentTarget[i]      = houseDataList[i].i_RentTarget;
                totalSalesCompletion     = totalSalesCompletion + houseDataList[i].i_SalesCompletion;
                totalRentCompletion      = totalRentCompletion + houseDataList[i].i_RentCompletion;
            }

            var datesDataSource = new EnumerableDataSource <DateTime>(dates);

            datesDataSource.SetXMapping(x => dateAxis.ConvertToDouble(x));

            var numberSalesDataSource = new EnumerableDataSource <int>(numberSalesCompletion);

            numberSalesDataSource.SetYMapping(y => y);
            numberSalesDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty,
                                             Y => String.Format("出售数量:{0}", Y));

            var numberRentDataSource = new EnumerableDataSource <int>(numberRentCompletion);

            numberRentDataSource.SetYMapping(y => y);
            numberRentDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty,
                                            Y => String.Format("出租数量:{0}", Y));

            header.Content = string.Format(@"房源总量:" + (totalSalesCompletion + totalRentCompletion).ToString() + "套(出售:" + totalSalesCompletion + "套,出租:" + totalRentCompletion + "套)");

            CompositeDataSource compositeDataSource1 = new
                                                       CompositeDataSource(datesDataSource, numberSalesDataSource);
            CompositeDataSource compositeDataSource2 = new
                                                       CompositeDataSource(datesDataSource, numberRentDataSource);

            plotter.AddLineGraph(compositeDataSource1,
                                 new Pen(Brushes.Blue, 2),
                                 new CircleElementPointMarker {
                Size = 10.0, Fill = Brushes.Red
            },
                                 new PenDescription("完成量"));

            plotter.AddLineGraph(compositeDataSource2,
                                 new Pen(Brushes.LimeGreen, 2),
                                 new CircleElementPointMarker
            {
                Size = 10.0,
                //Pen = new Pen(Brushes.Black, 2.0),
                Fill = Brushes.Orange
            },
                                 new PenDescription("目标量"));

            CursorCoordinateGraph cursorCoordinateGraph = new CursorCoordinateGraph();

            cursorCoordinateGraph.IsHorizontalDateTimeAxis = true;//横轴显示时间

            plotter.Children.Add(cursorCoordinateGraph);

            plotter.Viewport.FitToView();
        }
예제 #2
0
        void OnCurrentDataItemViewModelChanged(DataItemViewModel oldItem, DataItemViewModel newItem)
        {
            this.Title = string.Empty;

            Part_Plotter.Children.Remove(m_selectedPeakGraph);
            Part_Plotter.Children.Remove(m_peaksGraph);
            Part_Plotter.Children.Remove(m_diffSignalGraph);
            Part_Plotter.Children.Remove(m_signalGraph);
            Part_Plotter.Children.Remove(m_cursorGraph);
            Part_Plotter.Children.Remove(m_peakThresholdGraph);
            Part_Plotter.Children.Remove(m_stimuliStartsGraph);
            Part_Plotter.Children.Remove(m_filteredSignalGraph);



            m_selectedPeakGraph   = null;
            m_peaksGraph          = null;
            m_diffSignalGraph     = null;
            m_signalGraph         = null;
            m_cursorGraph         = null;
            m_peakThresholdGraph  = null;
            m_stimuliStartsGraph  = null;
            m_filteredSignalGraph = null;

            if (oldItem != null)
            {
                oldItem.CurrentPeakIndexChanged      += OnCurrentPeakIndexChanged;
                oldItem.DataItem.LocatedPeaksUpdated -= OnData_LocatedPeaksUpdated;
                oldItem.DataItem.SweepsChanged       -= OnSweepsChangedChanged;
                oldItem.DataItem.PeakDetectionSettings.CalculatedThresholdChanged -= OnCalculatedThresholdChanged;
            }

            if (newItem == null)
            {
                return;
            }

            this.Title = System.IO.Path.GetFileNameWithoutExtension(newItem.DataItem.Recording.FilePath);

            newItem.CurrentPeakIndexChanged      += OnCurrentPeakIndexChanged;
            newItem.DataItem.LocatedPeaksUpdated += OnData_LocatedPeaksUpdated;
            newItem.DataItem.SweepsChanged       += OnSweepsChangedChanged;
            newItem.DataItem.PeakDetectionSettings.CalculatedThresholdChanged += OnCalculatedThresholdChanged;

            var points = newItem.DataItem.CreateContinuousSignal();

            {
                var xs = Enumerable.Range(0, points.Length).Select(item => item * newItem.DataItem.Recording.Xscale);
                CompositeDataSource origSignal = new CompositeDataSource(xs.AsXDataSource(), points.AsYDataSource());
                m_signalGraph = new DXLineGraph()
                {
                    DataSource = origSignal, LineColor = Colors.Blue
                };

                if (Settings.Settings.Instance.ViewSettings.IsSignalVisible)
                {
                    Part_Plotter.Children.Add(m_signalGraph);
                }

                double samplingPeriod  = 1.0 / (newItem.DataItem.Recording.SamplingFrequency * 1000);
                double cutoffFrequency = 300;
//                bool isLowPass = false;
                var filter = PeaksProcessing.Processing.FirFilter.Create(cutoffFrequency, samplingPeriod, FilterType.HighPass);

                var filteredPoints = newItem.DataItem.CreateContinuousSignal();

                filter.FilterInPlace(filteredPoints);

                //var mad = DataProcessor.MAD(filteredPoints);
                //double sigma = 1.4826 * mad.Value;

                //var curvatures = DataProcessor.CalculateCurvatures(points);
                CompositeDataSource curvaturesSignal = new CompositeDataSource(xs.AsXDataSource(), filteredPoints.AsYDataSource());
                m_filteredSignalGraph = new DXLineGraph()
                {
                    DataSource = curvaturesSignal, LineColor = Colors.Green
                };

                Part_Plotter.Children.Add(m_filteredSignalGraph);

                //m_curvaturesGraph = new DXLineGraph() { DataSource = curvaturesSignal, LineColor = Colors.Green };

                //Part_Plotter.Children.Add(m_curvaturesGraph);
            }

            {
                var xsDiff = Enumerable.Range(0, points.Length - 1).Select(item => item * newItem.DataItem.Recording.Xscale);
                CompositeDataSource diffSignal = new CompositeDataSource(xsDiff.AsXDataSource(), DataProcessor.ComputeDiff(points).AsYDataSource());
                m_diffSignalGraph = new DXLineGraph()
                {
                    DataSource = diffSignal, LineColor = Colors.Red
                };

                if (Settings.Settings.Instance.ViewSettings.IsDiffSignalVisible)
                {
                    Part_Plotter.Children.Add(m_diffSignalGraph);
                }
            }

            m_cursorGraph = new CursorCoordinateGraph()
            {
                CustomXFormat = "{0:F}", CustomYFormat = "{0:F}"
            };
            Part_Plotter.Children.Add(m_cursorGraph);

            Part_Plotter.FitToView();

            RefreshPeaksGraph();
            RefreshStimuliStartsGraph();
            OrderGraphs();
        }