public LiveWifiAndBluetoothShellDataViewModel(IBluetoothFinder bluetoothFinder,
                                                      IShellTemperatureRepository <ShellTemp> shellTemperatureRepository,
                                                      IShellTemperatureRepository <SdCardShellTemp> sdCardShellTemperatureRepository,
                                                      IDeviceRepository <DeviceInfo> deviceRepository,
                                                      IConfiguration configuration,
                                                      BluetoothConnectionSubject subject,
                                                      TemperatureSubject temperatureSubject,
                                                      ILogger <LiveBluetoothOnlyShellDataViewModel> logger,
                                                      OutlierDetector outlierDetector,
                                                      ClearList clear,
                                                      IRepository <ShellTemperatureComment> commentRepository,
                                                      IReadingCommentRepository <ReadingComment> readingCommentRepository,
                                                      IRepository <Positions> positionRepository,
                                                      IRepository <ShellTemperaturePosition> shellTempPositionRepository,
                                                      IRepository <SdCardShellTemperatureComment> sdCardCommentRepository)
            : base(bluetoothFinder, shellTemperatureRepository, sdCardShellTemperatureRepository, deviceRepository, configuration, subject,
                   temperatureSubject, logger, outlierDetector, clear, commentRepository, readingCommentRepository,
                   positionRepository, shellTempPositionRepository, sdCardCommentRepository)
        {
            _shellTemperatureRepository = shellTemperatureRepository;

            IList <DeviceInfo> potentialWifiDevices = FindPotentialWifiDevices();

            foreach (DeviceInfo device in potentialWifiDevices.ToList())
            {
                DateTime start = DateTime.Now.AddMinutes(-2);
                DateTime end   = DateTime.Now;

                WifiDevice wifiDevice = new WifiDevice(device.DeviceName, device.DeviceAddress, start);

                IEnumerable <ShellTemp> shellTemps = _shellTemperatureRepository.GetShellTemperatureData(start, end,
                                                                                                         device.DeviceName, device.DeviceAddress);
                ShellTemp[] dataReadings = shellTemps as ShellTemp[] ?? shellTemps.ToArray();

                if (dataReadings.Length == 0)
                {
                    potentialWifiDevices.Remove(device);
                }
                else
                {
                    SetWifiDeviceDataReadings(wifiDevice, dataReadings);
                    SetWifiDeviceDataPoints(wifiDevice);
                    InstantiateNewDevice(wifiDevice);

                    wifiDevice.State.Message = "Connected To - " + wifiDevice.DeviceName;
                }
            }

            SetSelectedDeviceWhenNull();
            if (Devices.Count == 1) // only one in devices so, must be selected
            {
                SetConnectionStatus(SelectedDevice, DeviceConnectionStatus.CONNECTED);
            }

            SetCanRemoveDevices();
        }
        public void TestDetect()
        {
            var values = new double[] { 6.0039, 6.4048, 6.7865, 6.6615, 13.9451 };

            var loged = (from v in values select Math.Log(v)).ToList();

            Assert.AreEqual(4, OutlierDetector.Detect(loged, 0.0001));

            loged.RemoveAt(4);
            Assert.AreEqual(-1, OutlierDetector.Detect(loged, 0.0001));
        }
Ejemplo n.º 3
0
        public void CheckEnabled(double outlierEvalue, int minValidTransitionPair)
        {
            var pips = (from p in this.ProductIonPairs
                        where p.Enabled && p.IsPaired
                        select p).ToList();

            if (pips.Count > 0)
            {
                var values = (from p in pips
                              select Math.Log(p.Ratio)).ToList();

                var outlier = OutlierDetector.Detect(values, outlierEvalue);
                if (outlier != -1)
                {
                    pips[outlier].Enabled = false;
                }
            }

            this.Enabled = this.ProductIonPairs.Count(n => n.Enabled) >= minValidTransitionPair;
        }
Ejemplo n.º 4
0
 public LiveBluetoothOnlyShellDataViewModel(IBluetoothFinder bluetoothFinder,
                                            IShellTemperatureRepository <ShellTemp> shellTemperatureRepository,
                                            IShellTemperatureRepository <SdCardShellTemp> sdCardShellTemperatureRepository,
                                            IDeviceRepository <DeviceInfo> deviceRepository,
                                            IConfiguration configuration,
                                            BluetoothConnectionSubject subject,
                                            TemperatureSubject temperatureSubject,
                                            ILogger <LiveBluetoothOnlyShellDataViewModel> logger,
                                            OutlierDetector outlierDetector,
                                            ClearList clear,
                                            IRepository <ShellTemperatureComment> commentRepository,
                                            IReadingCommentRepository <ReadingComment> readingCommentRepository,
                                            IRepository <Positions> positionRepository,
                                            IRepository <ShellTemperaturePosition> shellTempPositionRepository,
                                            IRepository <SdCardShellTemperatureComment> sdCardCommentRepository)
     : base(bluetoothFinder, shellTemperatureRepository, sdCardShellTemperatureRepository, deviceRepository,
            configuration, subject,
            temperatureSubject, logger, outlierDetector, clear, commentRepository, readingCommentRepository,
            positionRepository, shellTempPositionRepository, sdCardCommentRepository)
 {
 }
Ejemplo n.º 5
0
        public Statistics(IEnumerable <double> values)
        {
            OriginalValues = values.Where(d => !double.IsNaN(d)).ToArray();
            SortedValues   = OriginalValues.OrderBy(value => value).ToArray();
            N = SortedValues.Count;
            if (N == 0)
            {
                throw new InvalidOperationException("Sequence of values contains no elements, Statistics can't be calculated");
            }

            var quartiles = Quartiles.FromSorted(SortedValues);

            Min                = quartiles.Min;
            Q1                 = quartiles.Q1;
            Median             = quartiles.Median;
            Q3                 = quartiles.Q3;
            Max                = quartiles.Max;
            InterquartileRange = quartiles.InterquartileRange;

            var moments = Moments.Create(SortedValues);

            Mean = moments.Mean;
            StandardDeviation = moments.StandardDeviation;
            Variance          = moments.Variance;
            Skewness          = moments.Skewness;
            Kurtosis          = moments.Kurtosis;

            var tukey = TukeyOutlierDetector.FromQuartiles(quartiles);

            LowerFence      = tukey.LowerFence;
            UpperFence      = tukey.UpperFence;
            AllOutliers     = SortedValues.Where(tukey.IsOutlier).ToArray();
            LowerOutliers   = SortedValues.Where(tukey.IsLowerOutlier).ToArray();
            UpperOutliers   = SortedValues.Where(tukey.IsUpperOutlier).ToArray();
            outlierDetector = tukey;

            StandardError      = StandardDeviation / Math.Sqrt(N);
            ConfidenceInterval = new ConfidenceInterval(Mean, StandardError, N);
            Percentiles        = new PercentileValues(SortedValues);
        }
Ejemplo n.º 6
0
        public List <ITraqPeptideRatioItem> Calculate(IIdentifiedProteinGroup protein)
        {
            var result = (from s in protein.GetPeptides()
                          where Filter(s)
                          let i = s.FindIsobaricItem()
                                  where i != null && i.Valid
                                  let si = GetSample(i)
                                           let ri = GetReference(i)
                                                    where !double.IsNaN(si) && !double.IsInfinity(si) && !double.IsNaN(ri) && !double.IsInfinity(ri) && (ri != 0)
                                                    select new ITraqPeptideRatioItem()
            {
                Sample = si, Reference = ri, Ratio = si / ri, IonInjectTime = i.Scan.IonInjectionTime
            }).ToList();

            if (result.Count == 0)
            {
                foreach (var p in protein)
                {
                    p.FindOrCreateITraqChannelItem(DatasetName, ChannelName).RatioStr = "#N/A";
                }
            }
            else
            {
                var ratios = (from l in result
                              select Math.Log(l.Ratio)).ToList();

                var outliers = OutlierDetector.Detect(ratios);

                if (outliers.Count > 0)
                {
                    //  using (StreamWriter sw = new StreamWriter("e:/temp.txt", true))
                    //  {
                    //    sw.WriteLine("{0} outliers detected in {1} ratios", outliers.Count, ratios.Count);
                    //    sw.Write("Outlier");
                    //    foreach (var outlier in outliers)
                    //    {
                    //      sw.Write(",{0:0.0000}", ratios[outlier]);
                    //    }
                    //    sw.WriteLine();

                    //    for (int i = outliers.Count - 1; i >= 0; i--)
                    //    {
                    //      ratios.RemoveAt(outliers[i]);
                    //    }
                    //    sw.Write("Other");
                    //    foreach (var r in ratios)
                    //    {
                    //      sw.Write(",{0:0.0000}", r);
                    //    }
                    //    sw.WriteLine();
                    //    sw.WriteLine();
                    //  }

                    for (int i = outliers.Count - 1; i >= 0; i--)
                    {
                        result[outliers[i]].IsOutlier = true;
                        //result.RemoveAt(outliers[i]);
                    }
                }

                var validItems = (from r in result where !r.IsOutlier select r).ToList();

                var ratio = RatioBuilder.Calculate(validItems);

                foreach (var p in protein)
                {
                    p.FindOrCreateITraqChannelItem(DatasetName, ChannelName).Ratio = ratio.Ratio;
                }
            }
            return(result);
        }