示例#1
0
        /// <summary>
        /// Sets a set of erroneous values to a specific value
        /// </summary>
        /// <param name="values">The values to set</param>
        /// <param name="methodCheckedAgainst">The method used to find the values</param>
        private void SpecifyValue(IEnumerable<ErroneousValue> values, IDetectionMethod methodCheckedAgainst)
        {
            values = values.ToList();
            var usingSelection = false;
            if (_graphEnabled && Selection != null && (!values.Any() || Common.Confirm("Should we use the values you've selected?", "Should we use the all the values in the range you've selected instead of those selected from the list of detected values?")))
            {
                var list = new List<ErroneousValue>();
                if (ApplyToAllSensors && !Common.Confirm("Are you sure?",
                                   "You've set to apply changes to all sensors.\r\nThis means you're editing values you can't see"))
                    return;
                foreach (var sensor in ApplyToAllSensors ? Sensors : SensorsToCheckMethodsAgainst.ToList())
                {
                    var sensorCopy = sensor;
                    list.AddRange(sensor.CurrentState.Values.Where(
                        x =>
                        x.Key >= Selection.LowerX && x.Key <= Selection.UpperX && (_selectionBehaviour.UseFullYAxis || x.Value >= Selection.LowerY) &&
                        (_selectionBehaviour.UseFullYAxis || x.Value <= Selection.UpperY)).Select(x => new ErroneousValue(x.Key, sensorCopy)));
                }
                values = list;
                usingSelection = true;
            }

            if (!_graphEnabled && _erroneousValuesFromDataTable.Count > 0 && (!values.Any() || Common.Confirm("Should we use the values you've selected?", "Should we use the values that you've selceted from the table instead of those selected from the list of detected values?")))
            {
                values = _erroneousValuesFromDataTable;
                usingSelection = true;
            }

            if (values.Count() < 0)
            {
                Common.ShowMessageBox("No values to set value to", "You haven't given us any values to work with!", false, false);
                return;
            }

            var sensorList = values.Select(x => x.Owner).Distinct().ToList();

            var specifyValueView = _container.GetInstance(typeof(SpecifyValueViewModel), "SpecifyValueViewModel") as SpecifyValueViewModel;

            if (specifyValueView == null)
                return;

            float value;

            _windowManager.ShowDialog(specifyValueView);

            if (specifyValueView.WasCanceled)
                return;

            try
            {
                value = float.Parse(specifyValueView.Text);
            }
            catch (Exception)
            {
                Common.ShowMessageBox("An Error Occured", "Please enter a valid number.", true, true);
                return;
            }

            var reason = Common.RequestReason(_container, _windowManager, (!usingSelection && methodCheckedAgainst != null) ? methodCheckedAgainst.DefaultReasonNumber : 7);

            if (reason == null)
                return;

            var bw = new BackgroundWorker();

            bw.DoWork += (o, e) =>
            {
                foreach (var sensor in sensorList)
                {
                    sensor.AddState(sensor.CurrentState.MakeValue(values.Where(x => x.Owner == sensor).Select(x => x.TimeStamp).ToList(), value, reason));
                    sensor.CurrentState.LogChange(sensor.Name, "Specified Values");
                }
            };

            bw.RunWorkerCompleted += (o, e) =>
            {
                FeaturesEnabled = true;
                ShowProgressArea = false;
                //Update the needed graphed items
                foreach (var graphableSensor in GraphableSensors.Where(x => sensorList.Contains(x.Sensor)))
                    graphableSensor.RefreshDataPoints();
                SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "SpecifyValues");
                UpdateUndoRedo();
                Common.ShowMessageBox("Values Updated", "The selected values set to " + value, false, false);
                CheckTheseMethods(new Collection<IDetectionMethod> { methodCheckedAgainst });
            };

            if (_manualPreviewTextBlock.Text == "Reject")
                _manualPreviewTextBlock.Text = "Preview";

            if (_automaticPreviewTextBlock.Text == "Reject")
                _automaticPreviewTextBlock.Text = "Preview";

            FeaturesEnabled = false;
            ShowProgressArea = true;
            ProgressIndeterminate = true;
            WaitEventString = "Removing values";
            bw.RunWorkerAsync();
        }
示例#2
0
 public ErroneousValue(DateTime timeStamp, IDetectionMethod detector, Sensor owner)
     : this(timeStamp, owner)
 {
     Detectors.Add(detector);
 }
示例#3
0
        /// <summary>
        /// Removes a set of erroneous values
        /// </summary>
        /// <param name="values">The values to remove</param>
        /// <param name="methodCheckedAgainst">The method used to find the values</param>
        private void RemoveValues(IEnumerable<ErroneousValue> values, IDetectionMethod methodCheckedAgainst)
        {
            values = values.ToList();
            var usingSelection = false;

            if (_graphEnabled && Selection != null && (!values.Any() || Common.Confirm("Should we use the values you've selected?", "To remove values should we use the all the values in the range you've selected instead of those selected from the list of detected values?")))
            {
                var list = new List<ErroneousValue>();
                if (ApplyToAllSensors && !Common.Confirm("Are you sure?",
                                   "You've set to apply changes to all sensors.\r\nThis means you're editing values you can't see"))
                    return;
                foreach (var sensor in ApplyToAllSensors ? Sensors : SensorsToCheckMethodsAgainst.ToList())
                {
                    var sensorCopy = sensor;
                    list.AddRange(sensor.CurrentState.Values.Where(
                        x =>
                        x.Key >= Selection.LowerX && x.Key <= Selection.UpperX && (_selectionBehaviour.UseFullYAxis || x.Value >= Selection.LowerY) &&
                        (_selectionBehaviour.UseFullYAxis || x.Value <= Selection.UpperY)).Select(x => new ErroneousValue(x.Key, sensorCopy)));
                }
                values = list;
                usingSelection = true;
            }

            if (!_graphEnabled && _erroneousValuesFromDataTable.Count > 0 && (!values.Any() || Common.Confirm("Should we use the values you've selected?", "When removing values should we use the values you've selected from the grid or those selected from the list of detected values?")))
            {
                values = _erroneousValuesFromDataTable;
                usingSelection = true;
            }

            if (values.Count() < 0)
            {
                Common.ShowMessageBox("No values to remove", "You haven't given us any values to work with!", false, false);
                return;
            }

            if (methodCheckedAgainst == _missingValuesDetector && !usingSelection)
            {
                Common.ShowMessageBox("Sorry, but that's a little hard",
                                      "We can't remove values that are already removed! Try another option", false,
                                      false);
                return;
            }

            var sensorList = values.Select(x => x.Owner).Distinct().ToList();

            var bw = new BackgroundWorker();
            var reason = Common.RequestReason(_container, _windowManager, (!usingSelection && methodCheckedAgainst != null) ? methodCheckedAgainst.DefaultReasonNumber : 7);

            if (reason == null)
                return;

            bw.DoWork += (o, e) =>
            {
                foreach (var sensor in sensorList)
                {
                    sensor.AddState(sensor.CurrentState.RemoveValues(values.Where(x => x.Owner == sensor).Select(x => x.TimeStamp).ToList(), reason));
                    sensor.CurrentState.LogChange(sensor.Name, "Removed Values");
                }
            };

            bw.RunWorkerCompleted += (o, e) =>
            {
                FeaturesEnabled = true;
                ShowProgressArea = false;
                //Update the needed graphed items
                foreach (var graphableSensor in GraphableSensors.Where(x => sensorList.Contains(x.Sensor)))
                    graphableSensor.RefreshDataPoints();
                SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "RemoveValues");
                UpdateUndoRedo();
                Common.ShowMessageBox("Values Updated", "The selected values were removed", false, false);
                CheckTheseMethods(new Collection<IDetectionMethod> { methodCheckedAgainst });
            };

            if (_manualPreviewTextBlock.Text == "Reject")
                _manualPreviewTextBlock.Text = "Preview";

            if (_automaticPreviewTextBlock.Text == "Reject")
                _automaticPreviewTextBlock.Text = "Preview";

            FeaturesEnabled = false;
            ShowProgressArea = true;
            ProgressIndeterminate = true;
            WaitEventString = "Removing values";
            bw.RunWorkerAsync();
        }
示例#4
0
        /// <summary>
        /// Builds a tab item for a detection method
        /// </summary>
        /// <param name="method">The detection method to build it from</param>
        /// <returns>The constructed tab item</returns>
        private TabItem GenerateTabItemFromDetectionMethod(IDetectionMethod method)
        {
            var tabItem = new TabItem { Header = new TextBlock { Text = method.Abbreviation }, IsEnabled = FeaturesEnabled };

            var tabItemGrid = new Grid();
            tabItemGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            tabItemGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            tabItemGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });

            var title = new TextBlock { Text = method.Name, FontWeight = FontWeights.Bold, FontSize = 16, Margin = new Thickness(3), TextWrapping = TextWrapping.Wrap };

            Grid.SetRow(title, 0);

            tabItemGrid.Children.Add(title);

            var aboutButton = new Button
                                  {
                                      Content = new Image
                                                    {
                                                        Source = new BitmapImage(new Uri("pack://application:,,,/Images/help_32.png", UriKind.Absolute)),
                                                        Width = 16,
                                                        Height = 16
                                                    },
                                      Margin = new Thickness(3),
                                      HorizontalAlignment = HorizontalAlignment.Right,
                                      HorizontalContentAlignment = HorizontalAlignment.Center
                                  };
            aboutButton.Click +=
                (o, e) => Common.ShowMessageBox(string.Format("  About {0}  ", method.Name), method.About, false, false);

            Grid.SetRow(aboutButton, 0);

            tabItemGrid.Children.Add(aboutButton);

            var detectionMethodOptions = new GroupBox { Header = new TextBlock { Text = "Options" }, BorderBrush = Brushes.OrangeRed };

            var optionsStackPanel = new StackPanel { Orientation = Orientation.Vertical };
            detectionMethodOptions.Content = optionsStackPanel;

            var detectionMethodListBox = new GroupBox { Header = new TextBlock { Text = "Detected Values" }, BorderBrush = Brushes.OrangeRed };
            var settingsGrid = method.SettingsGrid;
            var listBox = new ListBox { SelectionMode = SelectionMode.Extended, IsEnabled = method.IsEnabled };

            settingsGrid.IsEnabled = method.IsEnabled;

            optionsStackPanel.Children.Add(settingsGrid);

            Grid.SetRow(detectionMethodOptions, 1);

            if (method.HasSettings)
                tabItemGrid.Children.Add(detectionMethodOptions);

            method.ListBox = listBox;

            detectionMethodListBox.Content = listBox;

            listBox.SelectionChanged += (o, e) =>
                                            {
                                                if (e.AddedItems.Count > 0)
                                                    _selectionBehaviour.ResetSelection();
                                            };

            _selectionBehaviour.SelectionMade += (o, e) => listBox.UnselectAll();

            Grid.SetRow(detectionMethodListBox, 2);

            tabItemGrid.Children.Add(detectionMethodListBox);

            listBox.SelectionChanged += (o, e) =>
                                            {
                                                var box = o as ListBox;
                                                if (box != null)
                                                    ActionsEnabled = Selection != null || box.SelectedItems.Count > 0;
                                                else
                                                    ActionsEnabled = Selection != null;
                                            };

            tabItem.Content = tabItemGrid;
            return tabItem;
        }
示例#5
0
        public MainWindowViewModel(IWindowManager windowManager, SimpleContainer container)
        {
            _windowManager = windowManager;
            _container = container;

            _sensorsToGraph = new ObservableCollection<GraphableSensor>();
            SensorsToCheckMethodsAgainst = new ObservableCollection<Sensor>();

            _erroneousValuesFromDataTable = new List<ErroneousValue>();

            #region Set Up Detection Methods
            ShowLastZoom = false;
            _minMaxDetector = new MinMaxDetector();
            _minMaxDetector.GraphUpdateNeeded += () =>
                                                     {
                                                         SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph,
                                                                      "MinMaxDetectorGraphUpdate");
                                                         CalculateYAxis(false);
                                                     };

            _runningMeanStandardDeviationDetector = new RunningMeanStandardDeviationDetector();
            _runningMeanStandardDeviationDetector.GraphUpdateNeeded += () => SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "RunningMeanGraphUpdate");

            _runningMeanStandardDeviationDetector.RefreshDetectedValues +=
                () => CheckTheseMethods(new Collection<IDetectionMethod> { _runningMeanStandardDeviationDetector });

            _missingValuesDetector = new MissingValuesDetector { IsEnabled = true };
            _selectedMethod = _missingValuesDetector;

            var repeatedValuesDetector = new RepeatedValuesDetector();

            repeatedValuesDetector.RefreshDetectedValues +=
                () => CheckTheseMethods(new Collection<IDetectionMethod> { repeatedValuesDetector });

            _detectionMethods = new List<IDetectionMethod> { _missingValuesDetector, repeatedValuesDetector, _minMaxDetector, new ToHighRateOfChangeDetector(), _runningMeanStandardDeviationDetector };

            #endregion

            #region Set Up Behaviours

            var behaviourManager = new BehaviourManager { AllowMultipleEnabled = true };

            #region Zoom Behaviour
            _zoomBehaviour = new CustomZoomBehaviour { IsEnabled = true };
            _zoomBehaviour.ZoomRequested += (o, e) =>
                                                {
                                                    ZoomState z = new ZoomState(StartTime, EndTime, Range);
                                                    _previousZoom.Add(z);
                                                    StartTime = e.LowerX;
                                                    EndTime = e.UpperX;
                                                    Range = new DoubleRange(e.LowerY, e.UpperY);
                                                    foreach (var detectionMethod in _detectionMethods.Where(x => x.IsEnabled))
                                                    {
                                                        var itemsToKeep =
                                                            detectionMethod.ListBox.Items.Cast<ErroneousValue>().Where(
                                                                x => x.TimeStamp >= StartTime && x.TimeStamp <= EndTime)
                                                                .ToList();
                                                        detectionMethod.ListBox.Items.Clear();
                                                        itemsToKeep.ForEach(x => detectionMethod.ListBox.Items.Add(x));
                                                    }
                                                    foreach (var sensor in _sensorsToGraph)
                                                    {
                                                        sensor.SetUpperAndLowerBounds(StartTime, EndTime);
                                                    }
                                                    SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "Zoom");
                                                    ShowLastZoom = true;
                                                };
            _zoomBehaviour.ZoomResetRequested += o =>
                                                     {
                                                         _previousZoom.Clear();
                                                         foreach (var sensor in _sensorsToGraph)
                                                         {
                                                             sensor.RemoveBounds();
                                                         }
                                                         CalculateGraphedEndPoints();
                                                         SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "ZoomReset");
                                                         CalculateYAxis();
                                                         CheckTheseMethods(_detectionMethods.Where(x => x.IsEnabled));
                                                         ShowLastZoom = false;
                                                         _previousZoom.Clear();
                                                     };
            _zoomBehaviour.LastZoomRequested += (o, e) =>
            {
                if (ShowLastZoom == true)
                {
                    ZoomState z = _previousZoom.GetLast();
                    StartTime = z.StartTime;
                    EndTime = z.EndTime;
                    Range = z.Range;
                    foreach (var detectionMethod in _detectionMethods.Where(x => x.IsEnabled))
                    {
                        var itemsToKeep =
                            detectionMethod.ListBox.Items.Cast<ErroneousValue>().Where(
                                x => x.TimeStamp >= StartTime && x.TimeStamp <= EndTime)
                                .ToList();
                        detectionMethod.ListBox.Items.Clear();
                        itemsToKeep.ForEach(x => detectionMethod.ListBox.Items.Add(x));
                    }
                    foreach (var sensor in _sensorsToGraph)
                    {
                        sensor.SetUpperAndLowerBounds(StartTime, EndTime);
                    }
                    SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "Zoom");
                    if (_previousZoom.Count == 0)
                    {
                        ShowLastZoom = false;
                    }
                }

            };

            behaviourManager.Behaviours.Add(_zoomBehaviour);
            #endregion

            #region Background Behaviour
            _background = new Canvas { Visibility = Visibility.Collapsed };
            var backgroundBehaviour = new GraphBackgroundBehaviour(_background);
            behaviourManager.Behaviours.Add(backgroundBehaviour);
            #endregion

            #region Selection Behaviour

            _selectionBehaviour = new CustomSelectionBehaviour { IsEnabled = true };
            _selectionBehaviour.SelectionMade += (sender, args) =>
                                                     {
                                                         Selection = args;
                                                     };

            _selectionBehaviour.SelectionReset += sender =>
                                                      {
                                                          Selection = null;
                                                      };
            behaviourManager.Behaviours.Add(_selectionBehaviour);
            #endregion

            _dateAnnotator = new DateAnnotationBehaviour { IsEnabled = true };
            behaviourManager.Behaviours.Add(_dateAnnotator);

            _calibrationAnnotator = new CalibrationAnnotatorBehaviour(this) { IsEnabled = true };
            behaviourManager.Behaviours.Add(_calibrationAnnotator);

            behaviourManager.Behaviours.Add(new ChangesAnnotatorBehaviour(this) { IsEnabled = true });

            Behaviour = behaviourManager;

            #endregion

            PropertyChanged += (o, e) =>
                                   {
                                       if (e.PropertyName == "Selection")
                                           ActionsEnabled = Selection != null;
                                   };

            BuildDetectionMethodTabItems();

            var autoSaveTimer = new System.Timers.Timer();
            autoSaveTimer.Elapsed += (o, e) =>
                                         {
                                             if (CurrentDataset != null)
                                             {
                                                 Save();
                                             }
                                         };
            autoSaveTimer.AutoReset = true;
            autoSaveTimer.Interval = Properties.Settings.Default.AutoSaveTimerInterval;
            if (Properties.Settings.Default.AutoSaveTimerEnabled)
                autoSaveTimer.Start();

            Properties.Settings.Default.PropertyChanged += (o, e) =>
                                                               {
                                                                   switch (e.PropertyName)
                                                                   {
                                                                       case "AutoSaveTimerInterval":
                                                                           autoSaveTimer.Interval =
                                                                               Properties.Settings.Default.
                                                                                   AutoSaveTimerInterval;
                                                                           break;
                                                                       case "AutoSaveTimerEnabled":
                                                                           if (Properties.Settings.Default.AutoSaveTimerEnabled)
                                                                               autoSaveTimer.Start();
                                                                           else
                                                                               autoSaveTimer.Stop();
                                                                           break;
                                                                   }
                                                               };
        }
示例#6
0
        /// <summary>
        /// Handles the detection method currenly being used change
        /// </summary>
        /// <param name="eventArgs">The selection changed event arguments</param>
        public void DetectionMethodChanged(SelectionChangedEventArgs eventArgs)
        {
            //Remove all previews
            GraphableSensors.ForEach(x => x.RemovePreview());
            _automaticPreviewTextBlock.Text = "Preview";
            _manualPreviewTextBlock.Text = "Preview";

            if (eventArgs.RemovedItems.Count > 0)
            {
                var oldTabItem = eventArgs.RemovedItems[0] as TabItem;
                if (oldTabItem != null)
                {
                    var oldTabItemHeader = oldTabItem.Header as TextBlock;
                    var oldDetectionMethod = _detectionMethods.FirstOrDefault(x => oldTabItemHeader != null && x.Abbreviation == oldTabItemHeader.Text);
                    if (oldDetectionMethod != null)
                    {
                        Debug.Print("Turning off: {0}", oldDetectionMethod.Name);
                        oldDetectionMethod.IsEnabled = false;
                        oldDetectionMethod.SettingsGrid.IsEnabled = false;
                        oldDetectionMethod.ListBox.Items.Clear();
                        oldDetectionMethod.ListBox.IsEnabled = false;
                        SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "DetectionMethodChanged");
                    }
                    else
                        SampleValues(Common.MaximumGraphablePoints, _sensorsToGraph, "ForcePreviewReset");
                    _selectedMethod = null;
                }
            }

            if (eventArgs.AddedItems.Count > 0)
            {
                var newTabItem = eventArgs.AddedItems[0] as TabItem;
                if (newTabItem != null)
                {
                    var newTabItemHeader = newTabItem.Header as TextBlock;
                    _selectionBehaviour.UseFullYAxis = _useFullYAxis || (newTabItem.Header is string &&
                                                       (String.CompareOrdinal((newTabItem.Header as string), "Calibration") == 0 || String.CompareOrdinal((newTabItem.Header as string), "Automatic") == 0 || String.CompareOrdinal((newTabItem.Header as string), "Manual") == 0));
                    NotInCalibrationMode = !(newTabItem.Header is string &&
                                             (String.CompareOrdinal((newTabItem.Header as string), "Calibration") == 0 ||
                                              String.CompareOrdinal((newTabItem.Header as string), "Automatic") == 0 ||
                                              String.CompareOrdinal((newTabItem.Header as string), "Manual") == 0));
                    var newDetectionMethod = _detectionMethods.FirstOrDefault(x => newTabItemHeader != null && x.Abbreviation == newTabItemHeader.Text);
                    if (newDetectionMethod != null)
                    {
                        Debug.Print("Turning on: {0}", newDetectionMethod.Name);
                        newDetectionMethod.IsEnabled = true;
                        newDetectionMethod.SettingsGrid.IsEnabled = true;
                        newDetectionMethod.ListBox.IsEnabled = true;
                        CheckTheseMethods(new Collection<IDetectionMethod> { newDetectionMethod });
                    }
                    _selectedMethod = newDetectionMethod;
                }
            }
        }
示例#7
0
 public ErroneousValue(DateTime timeStamp, IDetectionMethod detector, Sensor owner)
     : this(timeStamp, owner)
 {
     Detectors.Add(detector);
 }