Пример #1
0
        //c'tor
        public GraphVM(FlightDetectorModel fdm)
        {
            this.fdm           = fdm;
            this.prevLineIndex = 0;
            AnomaliesPoints    = new List <List <DataPoint> >();
            for (int i = 0; i < 42; i++)
            {
                AnomaliesPoints.Add(new List <DataPoint>());
            }
            AnomaliesPointsSpecificFeature = new List <DataPoint>();
            this.fdm.PropertyChanged      +=
                delegate(Object sender, PropertyChangedEventArgs e)
            {
                //if the propreties have changed
                if (e.PropertyName == "PropertyNames")
                {
                    PropertyIndexes = new List <PropertyIndex>();
                    int counter = 0;
                    //pass on each proprety name and create propertyIndex according to it's index and name
                    foreach (var item in this.fdm.PropertyNames)
                    {
                        PropertyIndex propertyIndex = new PropertyIndex();
                        propertyIndex.Name = item;
                        propertyIndex.Id   = counter++;
                        PropertyIndexes.Add(propertyIndex);
                    }
                }
                //if the values have changed
                if (e.PropertyName == "AnomalyPropertyValues")
                {
                    List <float> valuesGraph = fdm.AnomalyPropertyValues[0];
                    Points = new List <DataPoint>();
                    DateTime date = new DateTime(2020, 3, 26, 0, 0, 0);
                    //create data points aacording to the time and value
                    foreach (var item in valuesGraph)
                    {
                        Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), item));
                        date = date.AddMinutes(1);
                    }

                    List <float> correlatedPropretyGraph = fdm.AnomalyPropertyValues[0];
                    CorrelatedPoints = new List <DataPoint>();
                    foreach (var item in correlatedPropretyGraph)
                    {
                        CorrelatedPoints.Add(new DataPoint(DateTimeAxis.ToDouble(date), item));
                        date = date.AddMinutes(1);
                    }

                    List <float> regLinePropretyGraph = fdm.AnomalyPropertyValues[0];
                    RegPoints = new List <DataPoint>();
                    for (int i = 0; i < correlatedPropretyGraph.Count; i++)
                    {
                        RegPoints.Add(new DataPoint(valuesGraph[i], correlatedPropretyGraph[i]));
                        date = date.AddMinutes(1);
                    }

                    RegLinePoints = new List <DataPoint>();
                }

                //if the values have changed
                if (e.PropertyName == "LineToTransmit")
                {
                    //update the values proprety that is chosen at the list box
                    this.currenLineIndex = fdm.LineToTransmit;
                    if (pressed)
                    {
                        INotifyPropertyChanged("UpdateGraph");
                    }
                }

                if (e.PropertyName == "AnomaliesList")
                {
                    //update the anomalies
                    updateAnomaliesPoints();
                }

                if (e.PropertyName == "CorrlativeCircles")
                {
                    //update the cireles
                    if (pressed)
                    {
                        this.drawCircle = true;
                        updateCircels();
                        INotifyPropertyChanged("UpdateCircele");
                    }
                }
            };
            this.fdm.readXml();
            this.fdm.readAnomalyCsv();
            this.fdm.readNormalCsv();
            this.mcf = new MostCorrelativeFinder(fdm.NormalPropertyValues);
            this.minCorrelatedPointsXValue = new List <float>();
            this.maxCorrelatedPointsXValue = new List <float>();
            //List<int> cor = mcf.CorrlatedColumns;
            //printCor(cor);
            updateMinMaxValues();
            // updateAnomaliesPoints();
        }
Пример #2
0
        // change proprety and show it's values at the graph
        public void changeValues(PropertyIndex property)
        {
            //update every 3 rows
            int  lineDiff             = 3;
            long lineToCopy           = 0;
            int  idxOfMostCorrelative = mcf.findTheMostCorrelative(fdm.NormalPropertyValues, property.Id);
            // Line regLine = mcf.linearRegressionList[idxOfMostCorrelative];
            Line regLine = mcf.linearRegressionList[property.Id];

            //List<int> cor = mcf.CorrlatedColumns;

            //check if we need update
            if (Math.Abs(this.currenLineIndex - this.prevLineIndex) >= lineDiff)
            {
                //update the cuurent line
                this.prevLineIndex = currenLineIndex;
                lineToCopy         = currenLineIndex;
            }
            else
            {
                lineToCopy = prevLineIndex;
            }
            //all values of the  current feature column
            List <float> AllData = fdm.AnomalyPropertyValues[property.Id];
            //the relevant points need to be shown at the graph
            List <float> valuesGraph = new List <float>();
            //all values of the current correlative feature
            List <float> correlatedPropretyData = fdm.AnomalyPropertyValues[idxOfMostCorrelative];
            //the relevant points need to be shown at the graph
            List <float> correlatedPropretyGraph = new List <float>();

            //add the relevant values (until the line given)
            for (int i = 0; i < lineToCopy; i++)
            {
                valuesGraph.Add(AllData[i]);
                correlatedPropretyGraph.Add(correlatedPropretyData[i]);
            }
            //points for the regular gaph
            Points = new List <DataPoint>();
            //points for the correlated grph
            CorrelatedPoints = new List <DataPoint>();
            //regression points
            RegPoints = new List <DataPoint>();
            //line regression points
            RegLinePoints = new List <DataPoint>();
            AnomaliesPointsSpecificFeature = new List <DataPoint>();

            DateTime date = new DateTime(2020, 3, 26, 0, 0, 0);

            for (int i = 0; i < lineToCopy; i++)
            {
                Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), AllData[i]));
                CorrelatedPoints.Add(new DataPoint(DateTimeAxis.ToDouble(date), correlatedPropretyData[i]));
                date = date.AddMilliseconds(100);
            }

            // we want to show the last 30 seconds, 10 fps -> 30*10 lines to show
            int linesForReg = 30 * 10;

            for (int j = (int)Math.Max(0, lineToCopy - linesForReg); j < lineToCopy; j++)
            {
                RegPoints.Add(new DataPoint(AllData[j], correlatedPropretyGraph[j]));
            }

            if (correlatedPropretyGraph.Count > 0)
            {
                if ((minCorrelatedPointsXValue[property.Id] != maxCorrelatedPointsXValue[property.Id]))
                {
                    RegLinePoints.Add(new DataPoint(minCorrelatedPointsXValue[property.Id], mcf.calcY(regLine, minCorrelatedPointsXValue[property.Id])));
                    RegLinePoints.Add(new DataPoint(maxCorrelatedPointsXValue[property.Id], mcf.calcY(regLine, maxCorrelatedPointsXValue[property.Id])));
                }
                else
                {
                    RegLinePoints.Add(new DataPoint(minCorrelatedPointsXValue[property.Id], minCorrelatedPointsXValue[idxOfMostCorrelative]));
                    RegLinePoints.Add(new DataPoint(maxCorrelatedPointsXValue[property.Id], maxCorrelatedPointsXValue[idxOfMostCorrelative]));
                }
            }

            if (this.AnomaliesPoints.Count != 0)
            {
                int amountAnomalies = this.AnomaliesPoints[property.Id].Count;
                for (int i = 0; i < amountAnomalies; i++)
                {
                    if (this.fdm.AnomaliesList[property.Id][i].Item2 <= this.fdm.LineToTransmit)
                    {
                        this.AnomaliesPointsSpecificFeature.Add(this.AnomaliesPoints[property.Id][i]);
                    }
                }
            }

            this.Title           = property.Name;
            this.CorrelatedTitle = PropertyIndexes[idxOfMostCorrelative].Name;
            NotifyPropertyChanged("Title");
            NotifyPropertyChanged("CorrelatedTitle");
            NotifyPropertyChanged("Points");
            NotifyPropertyChanged("CorrelatedPoints");
            NotifyPropertyChanged("RegPoints");
            NotifyPropertyChanged("RegLinePoints");
            NotifyPropertyChanged("AnomaliesPointsSpecificFeature");
        }