objective.py (11262B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\campaigns\client\v2\data_model\objective.py 2 from __future__ import absolute_import, division, print_function 3 from campaigns.client.v2.data_model.campaign_version import CampaignVersion 4 from campaigns.client.v2.data_model.campaign_parameters import ParameterDefinition, ParameterConfiguration 5 from campaigns.client.v2.data_model.lifecycle import LifecycleState, LifecycleTriggers, LifecycleSideEffects 6 from campaigns.client.v2.data_model.participation import ParticipationConfiguration 7 from campaigns.client.v2.data_model.track import TrackDefinition, TrackID 8 from campaigns.client.v2.data_model.ui_definition import UIDefinition 9 from eveProto.generated.eve_public.campaign.objective import objective_pb2 10 from eveProto.generated.eve_public.campaign.objective.objective_pb2 import Identifier 11 from uuid import UUID 12 13 class CommitmentState(object): 14 UNSPECIFIED = 'unspecified' 15 COMMITTED = 'committed' 16 RESIGNED = 'resigned' 17 18 19 COMMITMENT_STATE_BY_PROTO = {objective_pb2.COMMITMENT_STATE_UNSPECIFIED: CommitmentState.UNSPECIFIED, 20 objective_pb2.COMMITMENT_STATE_COMMITTED: CommitmentState.COMMITTED, 21 objective_pb2.COMMITMENT_STATE_RESIGNED: CommitmentState.RESIGNED} 22 23 class ObjectiveID(object): 24 25 def __init__(self, objective_uuid): 26 self._objective_uuid = objective_uuid 27 28 @property 29 def uuid(self): 30 return self._objective_uuid 31 32 @classmethod 33 def from_proto(cls, proto): 34 return cls(UUID(bytes=proto.uuid)) 35 36 def to_proto(self): 37 return Identifier(uuid=self._objective_uuid.bytes) 38 39 def __eq__(self, other): 40 if not isinstance(other, ObjectiveID): 41 raise NotImplementedError 42 return self._objective_uuid == other._objective_uuid 43 44 def __ne__(self, other): 45 return not self.__eq__(other) 46 47 def __hash__(self): 48 return hash(self._objective_uuid) 49 50 def __repr__(self): 51 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 52 53 54 class UpcomingObjective(object): 55 56 def __init__(self, key, ui_definition, lifecycle_triggers): 57 self._key = key 58 self._ui_definition = ui_definition 59 self._lifecycle_triggers = lifecycle_triggers 60 61 @property 62 def key(self): 63 return self._key 64 65 @property 66 def ui_definition(self): 67 return self._ui_definition 68 69 @property 70 def lifecycle_triggers(self): 71 return self._lifecycle_triggers 72 73 @classmethod 74 def from_proto(cls, upcoming): 75 return UpcomingObjective(upcoming.key, UIDefinition.from_proto(upcoming.ui), LifecycleTriggers.from_proto(upcoming.lifecycle_triggers)) 76 77 def __eq__(self, other): 78 if not isinstance(other, UpcomingObjective): 79 raise NotImplementedError 80 return self.key == other.key and self.ui_definition == other.ui_definition and self.lifecycle_triggers == other.lifecycle_triggers 81 82 def __ne__(self, other): 83 return not self.__eq__(other) 84 85 def __repr__(self): 86 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 87 88 89 class ObjectiveParameter(object): 90 91 def __init__(self, definition, configuration): 92 self._definition = definition 93 self._configuration = configuration 94 95 @property 96 def definition(self): 97 return self._definition 98 99 @property 100 def configuration(self): 101 return self._configuration 102 103 @classmethod 104 def from_proto(cls, parameter): 105 definition = None 106 if parameter.HasField('definition'): 107 definition = ParameterDefinition.from_proto(parameter.definition) 108 configuration = None 109 if parameter.HasField('configuration'): 110 configuration = ParameterConfiguration.from_proto(parameter.configuration) 111 return ObjectiveParameter(definition, configuration) 112 113 def __eq__(self, other): 114 if not isinstance(other, ObjectiveParameter): 115 raise NotImplementedError 116 return self.definition == other.definition and self.configuration == other.configuration 117 118 def __ne__(self, other): 119 return not self.__eq__(other) 120 121 def __repr__(self): 122 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 123 124 125 class ObjectiveDefinition(object): 126 127 def __init__(self, objective_id, key, ui_definition, participation, parameters, lifecycle_triggers, lifecycle_side_effects, tracks, campaign_version): 128 self._objective_id = objective_id 129 self._key = key 130 self._ui_definition = ui_definition 131 self._participation = participation 132 self._parameters = parameters 133 self._lifecycle_triggers = lifecycle_triggers 134 self._lifecycle_side_effects = lifecycle_side_effects 135 self._tracks = tracks 136 self._campaign_version = campaign_version 137 138 @property 139 def objective_id(self): 140 return self._objective_id 141 142 @property 143 def key(self): 144 return self._key 145 146 @property 147 def ui_definition(self): 148 return self._ui_definition 149 150 @property 151 def participation(self): 152 return self._participation 153 154 @property 155 def parameters(self): 156 return self._parameters 157 158 @property 159 def lifecycle_triggers(self): 160 return self._lifecycle_triggers 161 162 @property 163 def lifecycle_side_effects(self): 164 return self._lifecycle_side_effects 165 166 @property 167 def tracks(self): 168 return self._tracks 169 170 @property 171 def campaign_version(self): 172 return self._campaign_version 173 174 @classmethod 175 def from_proto(cls, objective_id, response): 176 attributes = response.attributes 177 return ObjectiveDefinition(objective_id=objective_id, key=attributes.key, ui_definition=UIDefinition.from_proto(attributes.ui), participation=ParticipationConfiguration.from_proto(attributes.participation) if attributes.HasField('participation') else None, parameters=[ ObjectiveParameter.from_proto(parameter) for parameter in attributes.parameters ], lifecycle_triggers=LifecycleTriggers.from_proto(attributes.lifecycle_triggers), lifecycle_side_effects=LifecycleSideEffects.from_proto(attributes.lifecycle_side_effects), tracks=[ TrackDefinition.from_proto(TrackID.from_proto(track.id), track.attributes) for track in response.tracks ], campaign_version=CampaignVersion.from_proto(response.version) if response.HasField('version') else None) 178 179 def __eq__(self, other): 180 if not isinstance(other, ObjectiveDefinition): 181 raise NotImplementedError 182 return self.objective_id == other.objective_id and self.key == other.key and self.ui_definition == other.ui_definition and self.participation == other.participation and self.parameters == other.parameters and self.lifecycle_triggers == other.lifecycle_triggers and self.lifecycle_side_effects == other.lifecycle_side_effects and self.tracks == other.tracks and self.campaign_version == other.campaign_version 183 184 def __ne__(self, other): 185 return not self.__eq__(other) 186 187 def __repr__(self): 188 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 189 190 191 class CommitmentStats(object): 192 193 def __init__(self, committed_participants, total_participants): 194 self._committed_participants = committed_participants 195 self._total_participants = total_participants 196 197 @property 198 def committed_participants(self): 199 return self._committed_participants 200 201 @property 202 def total_participants(self): 203 return self._total_participants 204 205 @classmethod 206 def from_proto(cls, commitment_stats): 207 return CommitmentStats(commitment_stats.committed_participants, commitment_stats.total_participants) 208 209 def __eq__(self, other): 210 if not isinstance(other, CommitmentStats): 211 raise NotImplementedError 212 return self.committed_participants == other.committed_participants and self.total_participants == other.total_participants 213 214 def __ne__(self, other): 215 return not self.__eq__(other) 216 217 def __repr__(self): 218 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 219 220 221 class ObjectiveStatus(object): 222 223 def __init__(self, objective_id, lifecycle_state, total_contributors, commitment_stats): 224 self._objective_id = objective_id 225 self._lifecycle_state = lifecycle_state 226 self._total_contributors = total_contributors 227 self._commitment_stats = commitment_stats 228 229 @property 230 def objective_id(self): 231 return self._objective_id 232 233 @property 234 def lifecycle_state(self): 235 return self._lifecycle_state 236 237 @property 238 def total_contributors(self): 239 return self._total_contributors 240 241 @property 242 def commitment_stats(self): 243 return self._commitment_stats 244 245 @classmethod 246 def from_proto(cls, objective_id, lifecycle_state, stats): 247 commitment = stats.WhichOneof('commitment') 248 if commitment == 'commitment_stats': 249 commitment_stats = CommitmentStats.from_proto(stats.commitment_stats) 250 elif commitment == 'no_commitment': 251 commitment_stats = None 252 else: 253 raise NotImplementedError('Unknown objective commitment stats: %s' % commitment) 254 return ObjectiveStatus(objective_id, lifecycle_state, stats.total_contributors, commitment_stats) 255 256 @classmethod 257 def from_status_proto(cls, objective_id, response): 258 lifecycle_state = LifecycleState.from_objective_proto(response.state) if response.HasField('state') else None 259 return cls.from_proto(objective_id, lifecycle_state, response.stats) 260 261 def __eq__(self, other): 262 if not isinstance(other, ObjectiveStatus): 263 raise NotImplementedError 264 return self.objective_id == other.objective_id and self.lifecycle_state == other.lifecycle_state and self.total_contributors == other.total_contributors and self.commitment_stats == other.commitment_stats 265 266 def __ne__(self, other): 267 return not self.__eq__(other) 268 269 def __repr__(self): 270 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 271 272 273 class ObjectiveParticipantStats(object): 274 275 def __init__(self, commitment_state): 276 self._commitment_state = commitment_state 277 278 @property 279 def commitment_state(self): 280 return self._commitment_state 281 282 @classmethod 283 def from_proto(cls, response): 284 commitment = response.WhichOneof('commitment') 285 if commitment == 'commitment_state': 286 if response.commitment_state not in COMMITMENT_STATE_BY_PROTO: 287 raise NotImplementedError('Unknown commitment state: %s' % response.commitment_state) 288 commitment_state = COMMITMENT_STATE_BY_PROTO[response.commitment_state] 289 elif commitment == 'no_commitment': 290 commitment_state = None 291 else: 292 raise NotImplementedError('Unknown objective participant commitment: %s' % commitment) 293 return ObjectiveParticipantStats(commitment_state) 294 295 def __eq__(self, other): 296 if not isinstance(other, ObjectiveParticipantStats): 297 raise NotImplementedError 298 return self.commitment_state == other.commitment_state 299 300 def __ne__(self, other): 301 return not self.__eq__(other) 302 303 def __repr__(self): 304 return '<%s %r>' % (self.__class__.__name__, self.__dict__)