From 4fe15e3a79617d8347a32d0e0bf8b58b494c54bd Mon Sep 17 00:00:00 2001 From: Henning Glawe <glaweh@debian.org> Date: Wed, 17 Aug 2016 08:36:00 +0200 Subject: [PATCH] build global match statistics via SimpleParser.updateTelemetryCounters --- common/python/nomadcore/annotator.py | 14 -------------- common/python/nomadcore/simple_parser.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/common/python/nomadcore/annotator.py b/common/python/nomadcore/annotator.py index f69bb63..4d27cf1 100644 --- a/common/python/nomadcore/annotator.py +++ b/common/python/nomadcore/annotator.py @@ -20,9 +20,6 @@ class Annotator(object): self._formatNameWidth = formatNameWidth self._formatSourceWidth = formatSourceWidth self._update_annotate_format() - self.counter = {} - for counter in ['total', 'ignore', 'match', 'partial', 'unmatched']: - self.counter[counter] = 0 def _update_annotate_format(self): self._annotate_format = '%%%ds:%%04d %%%ds %%9s|%%s' % ( @@ -37,17 +34,6 @@ class Annotator(object): self._update_annotate_format() def annotate(self, minfo): - # update counters - self.counter['total'] += 1 - if minfo['coverageIgnore']: - self.counter['ignore'] += 1 - elif minfo['match'] > 1: - self.counter['match'] += 1 - elif minfo['match']: - self.counter['partial'] += 1 - else: - self.counter['unmatched'] += 1 - # don't write to file unless it is there if not self.annotateFile: return 1 diff --git a/common/python/nomadcore/simple_parser.py b/common/python/nomadcore/simple_parser.py index a572f67..089dea0 100644 --- a/common/python/nomadcore/simple_parser.py +++ b/common/python/nomadcore/simple_parser.py @@ -738,6 +738,7 @@ class CompiledMatcher(object): def handleMatchTelemetry(self, parser, match, line, targetStartEnd): match_telemetry = self.getMatchTelemetry(parser, match, line, targetStartEnd) + parser.updateTelemetryCounters(match_telemetry) parser.annotator.annotate(match_telemetry) class ParsingContext(object): # use slots? @@ -1047,6 +1048,9 @@ class SimpleParser(object): # by default, ignore empty lines in coverage analysis self.coverageIgnore = getattr(superContext, 'coverageIgnore', re.compile(r"^\s*$")) + self.telemetry_counter = {} + for counter in ['total', 'ignore', 'match', 'partial', 'unmatched']: + self.telemetry_counter[counter] = 0 if annotate: annofilename=fIn.fIn.name + ".annotate" else: @@ -1144,6 +1148,19 @@ class SimpleParser(object): while self.parseStep(): pass + def updateTelemetryCounters(self, matchTelemetry): + # update counters + self.telemetry_counter['total'] += 1 + if matchTelemetry['coverageIgnore']: + self.telemetry_counter['ignore'] += 1 + elif matchTelemetry['match'] > 1: + self.telemetry_counter['match'] += 1 + elif matchTelemetry['match']: + self.telemetry_counter['partial'] += 1 + else: + self.telemetry_counter['unmatched'] += 1 + + def compileParser(simpleParser, metaInfo, metaInfoToKeep, default_units=None, metainfo_units=None, strValueTransform=None): """compiles the given simple parser""" parserBuilder = SimpleParserBuilder(simpleParser, metaInfo, metaInfoToKeep, default_units, metainfo_units, strValueTransform) -- GitLab