private void PostProcessFrequency(PatternTestResult pattern, PatternTestSummary patternSummary) { foreach (var e in pattern.Events.Where(n => n.Options.Frequency || n.Options.FrequencyPerFile)) { if (e.Options.Frequency && e.Options.FrequencyParameters.ToMinAndMax(out int _min, out int _max)) { Frequency _freq; if (patternSummary.Frequencies.Any(n => n.EventName == e.Name && n.FrequencyType == FrequencyType.PerPattern && n.PatternIdentifier == pattern.Identifier)) { patternSummary.Frequencies.FirstOrDefault(n => n.EventName == e.Name && n.FrequencyType == FrequencyType.PerPattern && n.PatternIdentifier == pattern.Identifier).Events.Add(e); } else { _freq = new Frequency() { EventName = e.Name, FrequencyType = FrequencyType.PerPattern, iline = pattern.StartiLine, Path = pattern.Path, Min = _min, Max = _max, PatternIdentifier = pattern.Identifier }; _freq.Events.Add(e); patternSummary.Frequencies.Add(_freq); } } if (e.Options.FrequencyPerFile && e.Options.FrequencyPerFileParameters.ToMinAndMax(out _min, out _max)) { if (patternSummary.Frequencies.Any(n => n.FrequencyType == FrequencyType.PerFile && n.EventName == e.Name && n.Path == e.Path)) { patternSummary.Frequencies.FirstOrDefault(n => n.FrequencyType == FrequencyType.PerFile && n.EventName == e.Name && n.Path == e.Path).Events.Add(e); } else { Frequency _freq; _freq = new Frequency() { EventName = e.Name, FrequencyType = FrequencyType.PerFile, Min = _min, Max = _max, Path = pattern.Path }; _freq.Events.Add(e); patternSummary.Frequencies.Add(_freq); } } } for (int i = patternSummary.Frequencies.Count - 1; i >= 0; i--) { var freq = patternSummary.Frequencies[i]; if (freq.Count >= freq.Min && freq.Count <= freq.Max && freq.Count > 0) { patternSummary.Frequencies.RemoveAt(i); } } patternSummary.Frequencies = patternSummary.Frequencies.OrderByDescending(n => n.Count).ToList(); }
private void PostProcessUnexpected(List <PatternTestResultEventPattern> events, PatternTestSummary summary) { foreach (var @event in events.Where(n => n.Options.Unexpected)) { summary.Unexpected.FirstOrDefault(n => n.EventName == (@event.EventName ?? @event.Name)).Events.Add(@event); } }
private void PostProcessKnownIdle(List <PatternTestResultEventPattern> events, PatternTestSummary summary) { foreach (var @event in events.Where(n => n.OutsideBaseline && n.EventType == EventType.IdleDuration)) { var _temp = summary.KnownIdle.FirstOrDefault(n => n.EventName == @event.EventName); if (_temp == null) { _temp = new Duration() { EventName = @event.EventName, Min = @event.BaselineMin, Max = @event.BaselineMax }; summary.KnownIdle.Add(_temp); } _temp.Events.Add(@event); } }
private void PostProcessDuration(List <PatternTestResultEventPattern> events, PatternTestSummary summary) { foreach (var @event in events.Where(n => n.OutsideBaseline && n.EventType == EventType.Duration)) { summary.Durations.FirstOrDefault(n => n.EventName == @event.EventName).Events.Add(@event); } }
private void AddResult(PatternComplex r) { var p = new PatternTestResult { Name = r.Name, PatternName = r.Name, Path = _path, StartiLine = r.Events.Any() ? r.Events.First(n => n.Found).iLine : 0, EndiLine = r.Events.Any() ? r.Events.Last(n => n.Found).iLine : 0, Warnings = r.Warnings, TotalDuration = r.TotalDuration, Options = r.Options.Clone() }; r.Events = r.Events.OrderBy(n => n.iLine).ToList(); foreach (var e in r.Events.Where(n => n.Found)) { e.Path = _path; #region Process Search if (e.EventType == EventType.Search) { _result.Log.Add($@"{DateTime.Now.ToShortTimeString()} Pattern Search EventPattern ""{e.EventTag}"" found {e.iLineSearchMatches.Count} matches."); foreach (var i in e.iLineSearchMatches) { var res = new PatternTestResultEventPattern(e, i.iLine); e.iLine = i.iLine; e.Line = i.Line; ProcessValues(e, res); p.Events.Add(res); } continue; } #endregion Process Search var re = new PatternTestResultEventPattern(e, e.iLine); ProcessDuration(r.Events, p.Events, e, re); ProcessValues(e, re); p.Events.Add(re); // TODO: What is this for, should it be moved to a Summary of Totals section? - Sara #region Process Stop if (e.BodyStopFound && e.DateTime.HasValue && e.DateTimeBodyStop.HasValue) { var _duration = e.DateTimeBodyStop.Value - e.DateTime; var b = new PatternTestResultEventPattern($"{_duration.Value.ToFixedTimeString()}", EventType.Duration, e.Path, e.iLineBodyStop, 0, null, e.DateTimeBodyStop, _duration.Value); p.Events.Add(b); } #endregion Process Stop } #region Add Processed Pattern to List p.Events = p.Events.OrderBy(n => n.StartiLine).ToList(); var _summary = _result.PatternSummaries.Where(n => n.PatternName == p.PatternName).FirstOrDefault(); if (_summary == null) { _summary = new PatternTestSummary(p.PatternName); _result.PatternSummaries.Add(_summary); } _summary.Patterns.Add(p); #endregion }
/// <summary> /// Look for all the attributes that determine 'Clean', meaning that we meet a set of critera /// Per each Clean attriute on an eventPattern, create a PatternTestCleanEvent record /// These Clean events will be used to compare against the pattern results and for rendering. /// </summary> private static void PreProcessPatterns(TestArgs args) { foreach (var p in args.Patterns) { var summary = new PatternTestSummary(p.Name) { Options = p.Options.Clone() }; // Collect all of the validation attributes for the given pattern foreach (var e in p.Events.Where(n => (n.Options.Unexpected || n.Options.Frequency || n.Options.FrequencyPerFile || // Known Idle n.Options.TimeToNextKnownIdle || // Duration n.Options.TimeFrom || n.Options.TimeTo || n.Options.TimeToNext || n.Options.TimeToOr))) { if (e.Options.Unexpected) { summary.Unexpected.Add(new CleanAttribute() { EventName = e.Name }); } if (e.Options.Frequency && e.Options.FrequencyParameters.ToMinAndMax(out int _min, out int _max)) { summary.Frequencies.Add(new Frequency() { EventName = e.Name, FrequencyType = FrequencyType.PerPattern, Min = _min, Max = _max }); } if (e.Options.FrequencyPerFile && e.Options.FrequencyPerFileParameters.ToMinAndMax(out _min, out _max)) { summary.Frequencies.Add(new Frequency() { EventName = e.Name, FrequencyType = FrequencyType.PerFile, Min = _min, Max = _max }); } if (e.Options.TimeToNextKnownIdle) { var _baseLine = e.Options.TimeToNextKnownIdleParameters.ToBaseLineList().First(); summary.KnownIdle.Add(new Duration() { EventName = e.Name, Min = _baseLine.Min, Max = _baseLine.Max }); } if (e.Options.TimeFrom) { var parameters = e.Options.TimeFromParameters.ToBaseLineList(); foreach (var param in parameters) { summary.Durations.Add(new Duration() { EventName = e.Name, Min = param.Min, Max = param.Max }); } } if (e.Options.TimeTo) { var parameters = e.Options.TimeToParameters.ToBaseLineList(); foreach (var param in parameters) { summary.Durations.Add(new Duration() { EventName = e.Name, Min = param.Min, Max = param.Max }); } } if (e.Options.TimeToNext) { var _baseLine = e.Options.TimeToNextParameters.ToBaseLineList().First(); summary.Durations.Add(new Duration() { EventName = e.Name, Min = _baseLine.Min, Max = _baseLine.Max }); } if (e.Options.TimeToOr) { var parameters = e.Options.TimeToOrParameters.ToBaseLineList(); foreach (var param in parameters) { summary.Durations.Add(new Duration() { EventName = e.Name, Min = param.Min, Max = param.Max }); } } } args.Result.CleanPatternSummaries.Add(summary); } }