Commits

Kristin Berry authored d8e244150dc
PIPE-2094: Remove RegressionExtractor as a parent to StatsExtractor and relegate potential restructuring of this to a future ticket.
No tags

pipeline/infrastructure/renderer/stats_extractor.py

Modified
12 12 from pipeline.infrastructure.launcher import Context
13 13 from pipeline.infrastructure import logging
14 14 from pipeline.infrastructure.renderer import regression
15 15 from pipeline.h.tasks.common import flagging_renderer_utils as flagutils
16 16 from pipeline.infrastructure import pipeline_statistics as pstats
17 17 import pipeline.infrastructure.utils as utils
18 18
19 19 LOG = logging.get_logger(__name__)
20 20
21 21
22 -class StatsExtractor(regression.RegressionExtractor):
23 - """Adapted from and interiting from the RegressisonExtractor,
22 +class StatsExtractor(object, metaclass=abc.ABCMeta):
23 + """Adapted from the RegressisonExtractor,
24 24 this class is the base class for a pipeline statistics extractor
25 25 which uses a result to extract statistics information.
26 -
26 + """
27 27 # the Results class this handler is expected to handle
28 28 result_cls = None
29 29 # if result_cls is a list, the type of classes it is expected to contain
30 30 child_cls = None
31 31 # the task class that generated the results, or None if it should handle
32 32 # all results of this type regardless of which task generated it
33 - generating_task = None"""
33 + generating_task = None
34 +
35 + def is_handler_for(self, result:Union[Results, ResultsList]) -> bool:
36 + """
37 + Return True if this StatsExtractor can process the Result.
38 +
39 + :param result: the task Result to inspect
40 + :return: True if the Result can be processed
41 + """
42 + # if the result is not a list or the expected results class,
43 + # return False
44 + if not isinstance(result, self.result_cls):
45 + return False
46 +
47 + # this is the expected class and we weren't expecting any
48 + # children, so we should be able to handle the result
49 + if self.child_cls is None and (self.generating_task is None
50 + or result.task is self.generating_task
51 + or ( hasattr(self.generating_task, 'Task') and result.task is self.generating_task.Task) ):
52 + return True
53 +
54 + try:
55 + if all([isinstance(r, self.child_cls) and
56 + (self.generating_task is None or r.task is self.generating_task)
57 + for r in result]):
58 + return True
59 + return False
60 + except:
61 + # catch case when result does not have a task attribute
62 + return False
34 63
35 64 @abc.abstractmethod
36 65 def handle(self, result: Results, context=None) -> pstats.PipelineStatistics:
37 66 """
38 67 [Abstract] Extract pipeline statistics values
39 68
40 69 This method should return a PipelineStatistics object
41 70
42 71 :param result:
43 72 :return:

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut