private void SetXAxisLabels(AnomalyDetectionScenario scenario)
        {
            if (scenario != null)
            {
                int step = 0;
                List <TimeSeriesData> data = scenario.AllData;

                switch (scenario.ScenarioType)
                {
                case AnomalyDetectionScenarioType.Live:
                    step = DefaultDurationOfLiveDemoInSecond / 4;

                    this.x1_Lbl.Text = $"{0 * step}";
                    this.x2_Lbl.Text = $"{1 * step}";
                    this.x3_Lbl.Text = $"{2 * step}";
                    this.x4_Lbl.Text = $"{3 * step}";
                    this.x5_Lbl.Text = $"{4 * step}";
                    break;

                default:
                    if (data.Any())
                    {
                        step = data.Count % 4 != 0 ? (int)Math.Floor(data.Count / 4.0) : data.Count / 4;

                        this.x1_Lbl.Text = Util.StringToDateFormat(data[0 * step].Timestamp, ShortDateFormat);
                        this.x2_Lbl.Text = Util.StringToDateFormat(data[1 * step].Timestamp, ShortDateFormat);
                        this.x3_Lbl.Text = Util.StringToDateFormat(data[2 * step].Timestamp, ShortDateFormat);
                        this.x4_Lbl.Text = Util.StringToDateFormat(data[3 * step].Timestamp, ShortDateFormat);
                        this.x5_Lbl.Text = Util.StringToDateFormat(data[data.Count - 1].Timestamp, ShortDateFormat);
                    }
                    break;
                }
            }
        }
        public void InitializeChart(AnomalyDetectionScenarioType scenarioType, AnomalyDetectorServiceType detectionMode, double sensitivy)
        {
            if (AnomalyDetectorScenarioLoader.AllModelData.ContainsKey(scenarioType))
            {
                curScenario = AnomalyDetectorScenarioLoader.AllModelData[scenarioType];
                if (scenarioType == AnomalyDetectionScenarioType.Live)
                {
                    curScenario.AllData.Clear();
                }

                DisplayBasicData(curScenario);

                // set default value: slider and radio buttons
                this.sensitivitySlider.Value = sensitivy;
                SelectedDetectionMode        = detectionMode;
            }
        }
Ejemplo n.º 3
0
        private static async Task <AnomalyDetectionScenario> LoadTimeSeriesData(AnomalyDetectionScenario scenario)
        {
            if (!string.IsNullOrEmpty(scenario.FilePath))
            {
                StorageFile sampleFile = await StorageFolder.GetFileAsync(scenario.FilePath);

                IList <string> csvContents = await FileIO.ReadLinesAsync(sampleFile, UnicodeEncoding.Utf8);

                foreach (string record in csvContents)
                {
                    string[] allValues = record.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                    scenario.AllData.Add(new TimeSeriesData(allValues[0], allValues[1]));
                }
            }

            return(scenario);
        }
        private void DisplayBasicData(AnomalyDetectionScenario scenario)
        {
            // update axis lines
            SetXAxisLabels(scenario);
            SetYAxisLabels(scenario.MaxValue, scenario.MinValue, scenario.ScenarioType);

            // update progress line
            if (progressIndicator != null)
            {
                progressIndicator.Offset = new Vector3(0, (int)resultGrid.ActualHeight, resultGrid.CenterPoint.Z);
                progressLine.X1          = progressIndicator.CenterPoint.X;
                progressLine.X2          = progressIndicator.CenterPoint.X;
                progressLine.Y1          = 0;
                progressLine.Y2          = resultGrid.ActualHeight;
            }

            // update data points
            dataPolyline.Points?.Clear();
        }
        private PointCollection GetPointCollectionByScenarioData(AnomalyDetectionScenario scenario)
        {
            PointCollection dataPoints = new PointCollection();

            if (scenario.AllData != null && scenario.AllData.Any())
            {
                double dataRange = scenario.MaxValue - scenario.MinValue;
                double yScale    = (resultGrid.ActualHeight / dataRange);
                double xOffset   = resultGrid.ActualWidth / (scenario.AllData.Count - 1);
                double yZeroLine = yScale * scenario.MinValue;

                for (int i = 0; i < scenario.AllData.Count; i++)
                {
                    Point point = new Point(xOffset * i, yZeroLine + resultGrid.ActualHeight - (yScale * scenario.AllData[i].Value));
                    dataPoints.Add(point);
                }
            }

            return(dataPoints);
        }