public void RunTest(string filename)
        {
            log.Info("========================================================");
            log.InfoFormat("Opening file '{0}'", filename);
            log.Info("========================================================");

            HeartContractions.Clear();

            double     SamplingRate = 100;
            List <int> data_list    = new List <int>(1000);

            using (System.IO.StreamReader sr = new System.IO.StreamReader(filename))
            {
                string   FirstLine         = sr.ReadLine();
                string[] samplingRateLines = FirstLine.Split('=');
                if (samplingRateLines.Length < 2)
                {
                    samplingRateLines = new string[] { FirstLine, FirstLine };
                }

                log.DebugFormat("1-st line of the file is \"{0}\"", FirstLine);
                log.DebugFormat("Sampling rate string is \"{0}\"", samplingRateLines[1]);

                SamplingRate = double.Parse(samplingRateLines[1]);

                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (string.Empty != line)
                    {
//            log.DebugFormat("read from file:   {0}", line);
                        data_list.Add(int.Parse(line));
                    }
                }
            }

            int[] data = data_list.ToArray();

            using (var detector = new PpgPulseDetector(SamplingRate, 10))
            {
                detector.HeartContractionDetected += detector_HeartContractionDetected;
                detector.AddData(data, (long)(((double)data.Length) / SamplingRate * 1000000));
            }

            log.Info("....Test results are:");
            log.InfoFormat("....{0} heart contraction(s) detected in the loaded signal", HeartContractions.Count);
            log.Info("=================================================================");
        }
Beispiel #2
0
        /// <summary>
        /// обрабатывает сигнал из указанного файла, начиная со строки
        /// start_line и заканчивая строкой end_line.
        /// если bInteractiveFinish == true, показывает сообщение
        /// и ждет нажатия кнопки ОК перед закрытием результатов.
        /// </summary>
        /// <param name="filename">filename relative to this assembly's folder</param>
        /// <param name="bInteractiveFinish"></param>
        /// <param name="start_line"></param>
        /// <param name="end_line"></param>
        public void RunTest(string filename, int ExpectedContractionsCount, bool bInteractiveFinish, int start_line, int end_line)
        {
            log.Info("========================================================");
            log.InfoFormat("Opening file '{0}'", filename);
            log.Info("========================================================");


            using (ThreadCultureModifier.SetFloatingPointNumberDecimalSeparator(","))
            {
                string path = FileHelpers.GetAssemblyFolderPath(System.Reflection.Assembly.GetExecutingAssembly());
                filename = System.IO.Path.Combine(path, filename);

                HeartContractions.Clear();

                double     SamplingRate = 100;
                List <int> data_list    = new List <int>(1000);

                using (System.IO.StreamReader sr = new System.IO.StreamReader(filename))
                {
                    string   FirstLine         = sr.ReadLine();
                    string[] samplingRateLines = FirstLine.Split('=');
                    if (samplingRateLines.Length < 2)
                    {
                        samplingRateLines = new [] { FirstLine, FirstLine };
                    }

                    log.DebugFormat("1-st line of the file is \"{0}\"", FirstLine);
                    log.DebugFormat("Sampling rate string is \"{0}\"", samplingRateLines[1]);

                    SamplingRate = double.Parse(samplingRateLines[1]);

                    log.DebugFormat("Sampling rate read from the file: {0}", SamplingRate);

                    System.Diagnostics.Debug.Assert(
                        SamplingRate < 1200,
                        "Samping rate too high!\r\n" +
                        "Please check that (decimal separator used for floating-point value is ','.");

                    int data_lines_counter = 0;
                    while ((!sr.EndOfStream) && (data_lines_counter < end_line))
                    {
                        string line = sr.ReadLine();
                        ++data_lines_counter;

                        if (data_lines_counter >= start_line)
                        {
                            if (string.Empty != line)
                            {
                                //  log.DebugFormat("read from file:   {0}", line);
                                data_list.Add(int.Parse(line));
                            }
                        }
                    }
                }

                int[] data = data_list.ToArray();

                using (PpgPulseDetectorByDerivative detector = new PpgPulseDetectorByDerivative(SamplingRate, 10, true))
                {
                    detector.HeartContractionDetected += detector_HeartContractionDetected;
                    detector.AddData(data, (long)(((double)data.Length) / SamplingRate * 1000000));

                    if (bInteractiveFinish)
                    {
                        // System.Windows.Forms.MessageBox.Show("Click OK to finish the test!");
                        throw new NotImplementedException();
                    }
                }

                log.Info("....Test results are:");
                log.InfoFormat("....{0} heart contraction(s) detected in the loaded signal", HeartContractions.Count);
                log.Info("=================================================================");

                // Критерий успешности теста: количество
                // обнаруженных сердечных сокращений
                // равно ожидаемому предварительно вычисленному количеству
                NUnit.Framework.Assert.AreEqual(ExpectedContractionsCount, HeartContractions.Count);
            }
        }