diff --git a/common/python/nomadcore/annotator.py b/common/python/nomadcore/annotator.py index f69bb639bda76093dfd67029f7c4e6e0e049c504..4d27cf123a1137f6a0ba2ffa995e3524a08ac257 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 a572f678d97611d40cad873781b83ad6dcdd294b..089dea027df57f31fb2256feb812b6cbe4e2fb42 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)