@@ -17,6 +17,12 @@ class Trigger(EqualityMixin):
1717 relative error of scores.
1818 threshold : float
1919 The threshold for the trigger type.
20+ ignore_zeros : bool
21+ Whether to allow zero tally bins to be ignored. Note that this option
22+ can cause the trigger to fire prematurely if there are zero scores in
23+ any bin at the first evaluation.
24+
25+ .. versionadded:: 0.14.1
2026
2127 Attributes
2228 ----------
@@ -27,18 +33,22 @@ class Trigger(EqualityMixin):
2733 The threshold for the trigger type.
2834 scores : list of str
2935 Scores which should be checked against the trigger
36+ ignore_zeros : bool
37+ Whether to allow zero tally bins to be ignored.
3038
3139 """
3240
33- def __init__ (self , trigger_type : str , threshold : float ):
41+ def __init__ (self , trigger_type : str , threshold : float , ignore_zeros : bool = False ):
3442 self .trigger_type = trigger_type
3543 self .threshold = threshold
44+ self .ignore_zeros = ignore_zeros
3645 self ._scores = []
3746
3847 def __repr__ (self ):
3948 string = 'Trigger\n '
4049 string += '{: <16}=\t {}\n ' .format ('\t Type' , self ._trigger_type )
4150 string += '{: <16}=\t {}\n ' .format ('\t Threshold' , self ._threshold )
51+ string += '{: <16}=\t {}\n ' .format ('\t Ignore Zeros' , self ._ignore_zeros )
4252 string += '{: <16}=\t {}\n ' .format ('\t Scores' , self ._scores )
4353 return string
4454
@@ -61,6 +71,15 @@ def threshold(self, threshold):
6171 cv .check_type ('tally trigger threshold' , threshold , Real )
6272 self ._threshold = threshold
6373
74+ @property
75+ def ignore_zeros (self ):
76+ return self ._ignore_zeros
77+
78+ @ignore_zeros .setter
79+ def ignore_zeros (self , ignore_zeros ):
80+ cv .check_type ('tally trigger ignores zeros' , ignore_zeros , bool )
81+ self ._ignore_zeros = ignore_zeros
82+
6483 @property
6584 def scores (self ):
6685 return self ._scores
@@ -88,6 +107,8 @@ def to_xml_element(self):
88107 element = ET .Element ("trigger" )
89108 element .set ("type" , self ._trigger_type )
90109 element .set ("threshold" , str (self ._threshold ))
110+ if self ._ignore_zeros :
111+ element .set ("ignore_zeros" , "true" )
91112 if len (self ._scores ) != 0 :
92113 element .set ("scores" , ' ' .join (self ._scores ))
93114 return element
@@ -110,7 +131,10 @@ def from_xml_element(cls, elem: ET.Element):
110131 # Generate trigger object
111132 trigger_type = elem .get ("type" )
112133 threshold = float (elem .get ("threshold" ))
113- trigger = cls (trigger_type , threshold )
134+ ignore_zeros = str (elem .get ("ignore_zeros" , "false" )).lower ()
135+ # Try to convert to bool. Let Trigger error out on instantiation.
136+ ignore_zeros = ignore_zeros in ('true' , '1' )
137+ trigger = cls (trigger_type , threshold , ignore_zeros )
114138
115139 # Add scores if present
116140 scores = elem .get ("scores" )
0 commit comments