Ejemplo n.º 1
0
        /// <summary>
        /// Filter the specified phaseInput.
        /// </summary>
        /// <returns>The filter.</returns>
        /// <param name="phaseInput">Phase input.</param>
        public IEnumerable <PhaseData <SensorReading> > Filter(PhaseInput <SensorReading> phaseInput)
        {
            CalibratedThresholds = new List <KeyValuePair <string, decimal> >();
            var calibrationResults = new List <CalibrationResult>();

            foreach (var input in phaseInput.Input)
            {
                foreach (var param in phaseInput.Parameters)
                {
                    var calibrationField = typeof(SensorReading).GetProperty(param.Field);
                    var fieldTypeCode    = Type.GetTypeCode(calibrationField.PropertyType);
                    var calibStep        = param.GetClauseValue(CommandParameters.Step);
                    var calibPercentage  = param.GetClauseValue(CommandParameters.Percentage);

                    if (fieldTypeCode == TypeCode.Decimal && calibStep != null && calibPercentage != null)
                    {
                        var calibRecords = input.Data.Where(x => x.Label.Contains(calibStep)).ToList();
                        var calibVals    = calibRecords.Select(x => (decimal)calibrationField.GetValue(x, null)).ToList();
                        var avgVal       = MathService.Average(calibVals);
                        var threshVal    = avgVal * (decimal.Parse(calibPercentage) / 100.0M);

                        CalibratedThresholds.Add(new KeyValuePair <string, decimal>(param.Field, threshVal));
                        calibrationResults.Add(new CalibrationResult
                        {
                            Source       = input.Name,
                            AvgVal       = avgVal,
                            ThresholdVal = threshVal
                        });
                    }
                }

                // dump own results to file
                CsvFileWriter.WriteResultsToFile
                    (new string[] { OutputDirs.Filters, "ThresholdCalibration" },
                    input.Name, HeaderCsv, calibrationResults);
            }

            // return empty list ... we don't actually want to
            // affect the post-phase data set
            return(new List <PhaseData <SensorReading> >());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Summarize the specified input.
        /// </summary>
        /// <returns>The summarize.</returns>
        /// <param name="input">Input.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public IEnumerable <string[]> Summarize <T>(Dictionary <string, IEnumerable <T> > input) where T : ICsvWritable
        {
            var results = new List <string[]>();

            durations = new List <decimal>();

            foreach (var key in input.Keys)
            {
                if (input[key] is List <PauseResult> )
                {
                    List <PauseResult> analysisResults = (List <PauseResult>)input[key];
                    var sourceDurations = analysisResults.Select(x => x.Duration).ToList();
                    durations.AddRange(sourceDurations);
                    results.Add(new string[] {
                        key,                                         // source
                        $"{sourceDurations.Count}",                  // num of pauses
                        $"{MathService.Total(sourceDurations)}",     // total time paused
                        $"{MathService.Average(sourceDurations)}"    // average time paused
                    });
                }
            }

            return(results);
        }