/// <summary> /// Runs the analyzers. /// </summary> /// <returns><c>true</c>, if analyzers was run, <c>false</c> otherwise.</returns> public bool RunAnalyzers() { if (!Analyzers.Any()) { LogManager.Info("No analysis operations configured.", this); return(true); } bool success = false; if (Analyzers?.Count > 0 && InputData?.Keys?.Count >= 1) { var analyzedData = new Dictionary <string, IEnumerable <ICsvWritable> >(); foreach (var analyzerCommand in Analyzers) { // --------------------------------------------------------- // Retrieve analysis operation details // --------------------------------------------------------- var analyzerName = analyzerCommand.Name; var analyzer = AnalyzerManager.GetAnalyzer(analyzerName); if (analyzer == null) { continue; } // Sanity checking ... LogManager.Info($"Running analysis operation:\n\t{analyzer}", this); // --------------------------------------------------------- // Check to see if user requested a summary // --------------------------------------------------------- bool summaryRequested = Summarizers.Contains(analyzerName); // --------------------------------------------------------- // Group input data by original file name // --------------------------------------------------------- var consolidatedInputFiles = Inputs.SelectMany(x => x.InputFiles.Select(y => y.Key)).ToList(); foreach (var origInputFile in consolidatedInputFiles) { var analysisDataByInputFile = new Dictionary <string, IEnumerable <ICsvWritable> >(); var analysisKeysByInputFile = InputData.Keys.Where(x => x.Contains(origInputFile)); foreach (var key in analysisKeysByInputFile) { // ------------------------------------------------- // Perform the actual analysis operation // ------------------------------------------------- if (analyzerCommand.HasParameters && FilterManager.ContainsFilter(Filters, typeof(ThresholdCalibrationFilter))) { var calibData = CalibrationData[origInputFile]; analyzerCommand.Parameters = ThresholdCalibrationFilter.CalibrateParameters (analyzerCommand.Parameters, calibData); } // ------------------------------------------------- // Any required analyzer-specific prep // ------------------------------------------------- if (analyzer is Analyzers.SciKitPrepAnalysis skpAnalyzer) { skpAnalyzer.CurrentInput = key; } else if (analyzer is Analyzers.SciKitEvalAnalysis skeAnalyzer) { skeAnalyzer.CurrentInput = key; } // ------------------------------------------------- var analysisResult = analyzer.Analyze(InputData[key], analyzerCommand.Parameters); analysisDataByInputFile[key] = analysisResult; // ------------------------------------------------- // Dump output to file if necessary // ------------------------------------------------- if (WriteOutputFile) { CsvFileWriter.WriteResultsToFile (new string[] { OutputDirs.Analyzers, analyzerName }, key, analyzer.HeaderCsv, analysisResult); } // ------------------------------------------------- // If requested, summarize file-specific results // ------------------------------------------------- if (summaryRequested) { ISummarizer summarizer = SummarizerManager.GetSummarizer(analyzerName); var summarizedValues = summarizer.Summarize(analysisDataByInputFile); if (WriteOutputFile) { CsvFileWriter.WriteSummaryToFile (new string[] { OutputDirs.Summarizers, analyzerName }, $"{origInputFile}{Constants.BAT.DEFAULT_INPUT_FILE_EXT}", summarizer.HeaderCsv, summarizedValues, summarizer.FooterCsv, summarizer.FooterValues); } } } // consolidate the results by input file var inputFileResults = analyzer.ConsolidateData(analysisDataByInputFile); if (analyzedData.ContainsKey(origInputFile)) { analyzedData[origInputFile] = inputFileResults; } else { analyzedData.Add(origInputFile, inputFileResults); } } // ----------------------------------------------------- // If requested, aggregate all file-specific summaries // into one high level file in root summarizer directory // ----------------------------------------------------- if (summaryRequested) { ISummarizer summarizer = SummarizerManager.GetSummarizer(analyzerName); var summarizedValues = summarizer.Summarize(analyzedData); if (WriteOutputFile) { CsvFileWriter.WriteSummaryToFile (new string[] { OutputDirs.Summarizers }, $"{analyzerName}Aggregate{Constants.BAT.DEFAULT_INPUT_FILE_EXT}", summarizer.HeaderCsv, summarizedValues, summarizer.FooterCsv, summarizer.FooterValues); } } success = true; } // use different collection to maintain integrity of original input data AnalysisData = analyzedData; } else { LogManager.Error("No input data to run analyzers on.", this); } return(success); }