예제 #1
0
        public static void CompareAnswers(LinkedList <FrequencyFileName> dftAnswer, LinkedList <FrequencyFileName> fftAnswer, string outputPath)
        {
            var res = new LinkedList <CSVAnswerErrorRecord>();

            foreach (var filename in dftAnswer.Select(x => x.FileName))
            {
                var dft         = dftAnswer.Single(x => x.FileName == filename);
                var fft         = fftAnswer.Single(x => x.FileName == filename);
                var errorRecord = new CSVAnswerErrorRecord();

                errorRecord.FileName     = filename;
                errorRecord.DFTFrequency = dft.Frequency;
                errorRecord.FFTFrequency = fft.Frequency;

                if (Math.Max(dft.Frequency, fft.Frequency) == 0)
                {
                    errorRecord.Error = 0;
                }
                else
                {
                    errorRecord.Error = (Math.Abs(dft.Frequency - fft.Frequency) / Math.Max(dft.Frequency, fft.Frequency)) * 100;
                }

                res.AddLast(errorRecord);
            }

            CSVUtils.WriteCSVFile <CSVAnswerErrorRecord>(outputPath, res.OrderBy(x => x.Error));
        }
예제 #2
0
        void ParallelProcessWaveForms(string inputDirectoryPath, string filenamePattern, string outputDirectoryPath, string answerPath, Func <string, string, LinkedList <FrequencyMagnitude> > algorithm)
        {
            var cumulativeStopWatch = new System.Diagnostics.Stopwatch();

            cumulativeStopWatch.Start();

            var lockObject     = new object();
            var result         = new LinkedList <FrequencyFileName>();
            var files          = Directory.GetFiles(inputDirectoryPath, filenamePattern);
            var filesRemaining = files.Length;

            Parallel.ForEach(files, (filePath) =>
            {
                Console.WriteLine("Processing File: " + filePath);
                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                //------------------------------------------------

                var frequencyDomain = algorithm(filePath, outputDirectoryPath);

                //------------------------------------------------
                var highestMagnitude = frequencyDomain.Aggregate(
                    (max, current) => (max == null || max.Magnitude < current.Magnitude) ? current : max);

                var fileName = Path.GetFileName(filePath);

                var ff = new FrequencyFileName()
                {
                    FileName  = Path.GetFileName(filePath),
                    Frequency = highestMagnitude.Frequency
                };

                lock (lockObject)
                {
                    result.AddLast(ff);

                    sw.Stop();
                    Console.WriteLine(string.Format("Processed File: {0} , Duration: {1}", fileName, sw.Elapsed));

                    filesRemaining--;
                    Console.WriteLine("Files Remaining: " + filesRemaining);
                    Console.WriteLine("Cumulative Duration: " + cumulativeStopWatch.Elapsed);
                }
            });

            cumulativeStopWatch.Stop();
            Console.WriteLine("Total Duration: " + cumulativeStopWatch.Elapsed);

            CSVUtils.WriteCSVFile <FrequencyFileName>(answerPath, result.OrderBy(x => x.Frequency));
        }