track.py (11229B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\campaigns\client\v2\data_model\track.py 2 from campaigns.client.v2.data_model.lifecycle import LifecycleState, LifecycleTriggers, LifecycleSideEffects 3 from campaigns.client.v2.data_model.side_effect import SideEffect 4 from campaigns.client.v2.data_model.track_contribution import contribution_from_proto 5 from campaigns.client.v2.data_model.track_reward import ParticipantContributionTrack 6 from campaigns.client.v2.data_model.ui_definition import UIDefinition 7 from eveProto.generated.eve_public.campaign.track.track_pb2 import Identifier 8 from uuid import UUID 9 10 class TrackID(object): 11 12 def __init__(self, track_uuid): 13 self._track_uuid = track_uuid 14 15 @property 16 def uuid(self): 17 return self._track_uuid 18 19 @classmethod 20 def from_proto(cls, proto): 21 return cls(UUID(bytes=proto.uuid)) 22 23 def to_proto(self): 24 return Identifier(uuid=self._track_uuid.bytes) 25 26 def __eq__(self, other): 27 if not isinstance(other, TrackID): 28 raise NotImplementedError 29 return self._track_uuid == other._track_uuid 30 31 def __ne__(self, other): 32 return not self.__eq__(other) 33 34 def __hash__(self): 35 return hash(self._track_uuid) 36 37 def __repr__(self): 38 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 39 40 41 class TrackThreshold(object): 42 43 def __init__(self, key, value, ui_definition, side_effects): 44 self._key = key 45 self._value = value 46 self._ui_definition = ui_definition 47 self._side_effects = side_effects 48 49 @property 50 def key(self): 51 return self._key 52 53 @property 54 def value(self): 55 return self._value 56 57 @property 58 def ui_definition(self): 59 return self._ui_definition 60 61 @property 62 def side_effects(self): 63 return self._side_effects 64 65 @classmethod 66 def from_proto(cls, threshold): 67 return TrackThreshold(key=threshold.key, value=threshold.value, ui_definition=UIDefinition.from_proto(threshold.ui), side_effects=[ SideEffect.from_proto(side_effect) for side_effect in threshold.side_effects ]) 68 69 def __eq__(self, other): 70 if not isinstance(other, TrackThreshold): 71 raise NotImplementedError 72 return self.key == other.key and self.value == other.value and self.ui_definition == other.ui_definition and self.side_effects == other.side_effects 73 74 def __ne__(self, other): 75 return not self.__eq__(other) 76 77 def __repr__(self): 78 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 79 80 81 class TrackDefinition(object): 82 83 def __init__(self, track_id, key, ui_definition, target_progress, participant_contribution_track, thresholds, contributions, lifecycle_triggers, lifecycle_side_effects): 84 self._track_id = track_id 85 self._key = key 86 self._ui_definition = ui_definition 87 self._target_progress = target_progress 88 self._participant_contribution_track = participant_contribution_track 89 self._thresholds = thresholds 90 self._contributions = contributions 91 self._lifecycle_triggers = lifecycle_triggers 92 self._lifecycle_side_effects = lifecycle_side_effects 93 94 @property 95 def track_id(self): 96 return self._track_id 97 98 @property 99 def key(self): 100 return self._key 101 102 @property 103 def ui_definition(self): 104 return self._ui_definition 105 106 @property 107 def target_progress(self): 108 return self._target_progress 109 110 @property 111 def participant_contribution_track(self): 112 return self._participant_contribution_track 113 114 @property 115 def thresholds(self): 116 return self._thresholds 117 118 @property 119 def contributions(self): 120 return self._contributions 121 122 @property 123 def lifecycle_triggers(self): 124 return self._lifecycle_triggers 125 126 @property 127 def lifecycle_side_effects(self): 128 return self._lifecycle_side_effects 129 130 @classmethod 131 def from_proto(cls, track_id, attributes): 132 target_progress_type = attributes.WhichOneof('target_progress') 133 if target_progress_type == 'target_progress_value': 134 target_progress = attributes.target_progress_value 135 elif target_progress_type == 'no_target_progress': 136 target_progress = None 137 else: 138 raise NotImplementedError('Unknown track target progress: %s' % target_progress_type) 139 participant_contribution_type = attributes.WhichOneof('participant_contribution') 140 if participant_contribution_type == 'participant_contribution_track': 141 participant_contribution_track = ParticipantContributionTrack.from_proto(attributes.participant_contribution_track) 142 elif participant_contribution_type == 'no_participant_contribution_track': 143 participant_contribution_track = None 144 else: 145 raise NotImplementedError('Unknown track participant contribution: %s' % participant_contribution_type) 146 return TrackDefinition(track_id=track_id, key=attributes.key, ui_definition=UIDefinition.from_proto(attributes.ui), target_progress=target_progress, participant_contribution_track=participant_contribution_track, thresholds=[ TrackThreshold.from_proto(threshold) for threshold in attributes.thresholds ], contributions=[ contribution_from_proto(contribution) for contribution in attributes.contributions ], lifecycle_triggers=LifecycleTriggers.from_proto(attributes.lifecycle_triggers), lifecycle_side_effects=LifecycleSideEffects.from_proto(attributes.lifecycle_side_effects)) 147 148 def __eq__(self, other): 149 if not isinstance(other, TrackDefinition): 150 raise NotImplementedError 151 return self.track_id == other.track_id and self.key == other.key and self.ui_definition == other.ui_definition and self.target_progress == other.target_progress and self.participant_contribution_track == other.participant_contribution_track and self.thresholds == other.thresholds and self.contributions == other.contributions and self.lifecycle_triggers == other.lifecycle_triggers and self.lifecycle_side_effects == other.lifecycle_side_effects 152 153 def __ne__(self, other): 154 return not self.__eq__(other) 155 156 def __repr__(self): 157 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 158 159 160 class TickingContributionStatus(object): 161 162 def __init__(self, key, stopped, next_tick_datetime): 163 self._key = key 164 self._stopped = stopped 165 self._next_tick_datetime = next_tick_datetime 166 167 @property 168 def key(self): 169 return self._key 170 171 @property 172 def stopped(self): 173 return self._stopped 174 175 @property 176 def next_tick_datetime(self): 177 return self._next_tick_datetime 178 179 @classmethod 180 def from_proto(cls, ticking_contribution): 181 schedule = ticking_contribution.WhichOneof('schedule') 182 if schedule == 'next_tick': 183 return TickingContributionStatus(ticking_contribution.key, False, ticking_contribution.next_tick.ToDatetime()) 184 if schedule == 'stopped': 185 return TickingContributionStatus(ticking_contribution.key, True, None) 186 raise NotImplementedError('Unknown ticking contribution schedule: %s' % schedule) 187 188 def __eq__(self, other): 189 if not isinstance(other, TickingContributionStatus): 190 raise NotImplementedError 191 return self.key == other.key and self.stopped == other.stopped and self.next_tick_datetime == other.next_tick_datetime 192 193 def __ne__(self, other): 194 return not self.__eq__(other) 195 196 def __repr__(self): 197 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 198 199 200 class TrackStatus(object): 201 202 def __init__(self, track_id, lifecycle_state, current_progress, ticking_contributions): 203 self._track_id = track_id 204 self._lifecycle_state = lifecycle_state 205 self._current_progress = current_progress 206 self._ticking_contributions = ticking_contributions 207 208 @property 209 def track_id(self): 210 return self._track_id 211 212 @property 213 def lifecycle_state(self): 214 return self._lifecycle_state 215 216 @property 217 def current_progress(self): 218 return self._current_progress 219 220 @property 221 def ticking_contributions(self): 222 return self._ticking_contributions 223 224 @classmethod 225 def from_proto(cls, track_id, lifecycle_state, stats): 226 return TrackStatus(track_id=track_id, lifecycle_state=lifecycle_state, current_progress=stats.current_progress, ticking_contributions=[ TickingContributionStatus.from_proto(ticking) for ticking in stats.ticking_contributions ]) 227 228 @classmethod 229 def from_status_proto(cls, track): 230 lifecycle_state = LifecycleState.from_track_proto(track.state) if track.HasField('state') else None 231 return cls.from_proto(TrackID.from_proto(track.id), lifecycle_state, track.stats) 232 233 @classmethod 234 def from_get_proto(cls, track): 235 attributes = track.attributes 236 lifecycle_state = LifecycleState.from_track_proto(attributes.lifecycle_state) if attributes.HasField('lifecycle_state') else None 237 return cls.from_proto(TrackID.from_proto(track.id), lifecycle_state, track.stats) 238 239 def __eq__(self, other): 240 if not isinstance(other, TrackStatus): 241 raise NotImplementedError 242 return self.track_id == other.track_id and self.lifecycle_state == other.lifecycle_state and self.current_progress == other.current_progress and self.ticking_contributions == other.ticking_contributions 243 244 def __ne__(self, other): 245 return not self.__eq__(other) 246 247 def __repr__(self): 248 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 249 250 251 class TrackParticipantStats(object): 252 253 def __init__(self, current_participant_contribution, max_participant_contribution_reached): 254 self._current_participant_contribution = current_participant_contribution 255 self._max_participant_contribution_reached = max_participant_contribution_reached 256 257 @property 258 def current_participant_contribution(self): 259 return self._current_participant_contribution 260 261 @property 262 def max_participant_contribution_reached(self): 263 return self._max_participant_contribution_reached 264 265 @classmethod 266 def from_proto(cls, participant_stats): 267 status = participant_stats.WhichOneof('status') 268 if status == 'participant_track': 269 participant_track = participant_stats.participant_track 270 return TrackParticipantStats(participant_track.current_participant_contribution, participant_track.max_participant_contribution_reached) 271 if status == 'no_participant_track': 272 return None 273 raise NotImplementedError('Unknown track participant stats status: %s' % status) 274 275 def __eq__(self, other): 276 if not isinstance(other, TrackParticipantStats): 277 raise NotImplementedError 278 return self.current_participant_contribution == other.current_participant_contribution and self.max_participant_contribution_reached == other.max_participant_contribution_reached 279 280 def __ne__(self, other): 281 return not self.__eq__(other) 282 283 def __repr__(self): 284 return '<%s %r>' % (self.__class__.__name__, self.__dict__)