track_prediction.py (2418B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\campaigns\client\v2\data_model\track_prediction.py 2 3 4 class TickingContributionPrediction(object): 5 6 def __init__(self, key, value, evaluations): 7 self._key = key 8 self._value = value 9 self._evaluations = evaluations 10 11 @property 12 def key(self): 13 return self._key 14 15 @property 16 def value(self): 17 return self._value 18 19 @property 20 def evaluations(self): 21 return self._evaluations 22 23 @classmethod 24 def from_proto(cls, contribution): 25 return TickingContributionPrediction(key=contribution.key, value=contribution.value, evaluations=[ evaluation_prediction_from_proto(evaluation) for evaluation in contribution.evaluations ]) 26 27 def __eq__(self, other): 28 if not isinstance(other, TickingContributionPrediction): 29 raise NotImplementedError 30 return self.key == other.key and self.value == other.value and self.evaluations == other.evaluations 31 32 def __ne__(self, other): 33 return not self.__eq__(other) 34 35 def __repr__(self): 36 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 37 38 39 class EvaluationPrediction(object): 40 41 def __init__(self, key, value): 42 self._key = key 43 self._value = value 44 45 @property 46 def key(self): 47 return self._key 48 49 @property 50 def value(self): 51 return self._value 52 53 def __eq__(self, other): 54 if type(other) is not type(self): 55 return NotImplemented 56 return self.__dict__ == other.__dict__ 57 58 def __ne__(self, other): 59 result = self.__eq__(other) 60 if result is NotImplemented: 61 return result 62 return not result 63 64 def __repr__(self): 65 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 66 67 68 class ConstantEvaluationPrediction(EvaluationPrediction): 69 pass 70 71 72 class PerUnitEvaluationPrediction(EvaluationPrediction): 73 pass 74 75 76 def evaluation_prediction_from_proto(evaluation): 77 evaluation_type = evaluation.WhichOneof('evaluation') 78 if evaluation_type == 'constant': 79 return ConstantEvaluationPrediction(evaluation.key, evaluation.constant) 80 if evaluation_type == 'units_count': 81 return PerUnitEvaluationPrediction(evaluation.key, evaluation.units_count) 82 raise NotImplementedError('Unknown ticking evaluation prediction type: %s' % evaluation_type)