objective.py (27996B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\campaigns\client\v1\data_model\objective.py 2 import campaigns.client.v1.data_model.flatbuffer.campaigndefinition_generated as fb_campaign 3 from campaigns.client.v1.data_model.career_paths import PROTO_CAREER_TO_FDS_CAREER 4 from campaigns.client.v1.data_model.contribution_method import ContributionMethodConfiguration 5 from datetimeutils import datetime_to_filetime, filetime_to_datetime 6 from eve.common.script.sys.idCheckers import IsCorporation, IsCharacter, IsFaction, IsAlliance 7 from eveProto import get_single_value_from_split_precision_message 8 from eveProto.generated.eve_public.campaign.objective.objective_pb2 import Identifier, STATE_UNSPECIFIED, STATE_ACTIVE, STATE_COMPLETED, STATE_EXPIRED, STATE_CANCELLED, PARTICIPANT_STATE_UNSPECIFIED, PARTICIPANT_STATE_COMMITTED, PARTICIPANT_STATE_RESIGNED, PARTICIPANT_STATE_CONTRIBUTION_COMPLETED 9 from itertoolsext.Enum import Enum 10 from uuid import UUID 11 12 class FutureObjective(object): 13 14 def __init__(self, start_datetime, career_path, contribution_method_name, campaign_id = None): 15 self._start_datetime = start_datetime 16 self._career_path = career_path 17 self._contribution_method_name = contribution_method_name 18 self._campaign_id = campaign_id 19 20 @property 21 def start_datetime(self): 22 return self._start_datetime 23 24 @property 25 def career_path(self): 26 return self._career_path 27 28 @property 29 def contribution_method_name(self): 30 return self._contribution_method_name 31 32 @property 33 def campaign_id(self): 34 return self._campaign_id 35 36 @campaign_id.setter 37 def campaign_id(self, value): 38 self._campaign_id = value 39 40 def __repr__(self): 41 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 42 43 def __eq__(self, other): 44 if not isinstance(other, FutureObjective): 45 return NotImplemented 46 return self.start_datetime == other.start_datetime and self.career_path == other.career_path and self.contribution_method_name == other.contribution_method_name and self.campaign_id == other.campaign_id 47 48 49 class ObjectiveID(object): 50 51 def __init__(self, objective_uuid): 52 self._objective_uuid = objective_uuid 53 54 @property 55 def uuid(self): 56 return self._objective_uuid 57 58 @classmethod 59 def from_proto(cls, proto): 60 return ObjectiveID(UUID(bytes=proto.uuid)) 61 62 @classmethod 63 def from_flatbuffer(cls, uuid_fb): 64 objective_id_bytes = [ chr(byte) for byte in uuid_fb.Bytes() ] 65 return ObjectiveID(UUID(bytes=objective_id_bytes)) 66 67 def to_proto(self): 68 return Identifier(uuid=self._objective_uuid.bytes) 69 70 def __eq__(self, other): 71 if not isinstance(other, ObjectiveID): 72 return NotImplemented 73 return self._objective_uuid == other._objective_uuid 74 75 def __ne__(self, other): 76 return not self == other 77 78 def __repr__(self): 79 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 80 81 def __hash__(self): 82 return hash(self._objective_uuid) 83 84 85 class Objective(object): 86 87 def __init__(self, objective_id, title, subtitle, issuer, presenting_character, content_tags, scheduled_start_datetime, finished_datetime, career_path, target_progress, max_progress_per_participant, contribution_method_configuration, rewards, objective_state, annotations, campaign_id = None): 88 self._objective_id = objective_id 89 self._title = title 90 self._subtitle = subtitle 91 self._issuer = issuer 92 self._presenting_character = presenting_character 93 self._content_tags = content_tags 94 self._scheduled_start_datetime = scheduled_start_datetime 95 self._finished_datetime = finished_datetime 96 self._career_path = career_path 97 self._target_progress = target_progress 98 self._max_progress_per_participant = max_progress_per_participant 99 self._contribution_method_configuration = contribution_method_configuration 100 self._rewards = rewards 101 self._objective_state = objective_state 102 self._annotations = annotations 103 self._campaign_id = campaign_id 104 105 @property 106 def id(self): 107 return self._objective_id 108 109 @property 110 def title(self): 111 return self._title 112 113 @property 114 def subtitle(self): 115 return self._subtitle 116 117 @property 118 def issuer(self): 119 return self._issuer 120 121 @property 122 def is_corporation_issuer(self): 123 return IsCorporation(self._issuer) 124 125 @property 126 def is_character_issuer(self): 127 return IsCharacter(self._issuer) 128 129 @property 130 def presenting_character(self): 131 return self._presenting_character 132 133 @property 134 def content_tags(self): 135 return self._content_tags 136 137 @property 138 def scheduled_start_datetime(self): 139 return self._scheduled_start_datetime 140 141 @property 142 def finished_datetime(self): 143 return self._finished_datetime 144 145 @property 146 def is_finished(self): 147 return self._finished_datetime is not None 148 149 @property 150 def career_path(self): 151 return self._career_path 152 153 @property 154 def target_progress(self): 155 return self._target_progress 156 157 @property 158 def max_progress_per_participant(self): 159 return self._max_progress_per_participant 160 161 @property 162 def contribution_method_configuration(self): 163 return self._contribution_method_configuration 164 165 @property 166 def rewards(self): 167 return self._rewards 168 169 @property 170 def objective_state(self): 171 return self._objective_state 172 173 @property 174 def annotations(self): 175 return self._annotations 176 177 @property 178 def campaign_id(self): 179 return self._campaign_id 180 181 @campaign_id.setter 182 def campaign_id(self, value): 183 self._campaign_id = value 184 185 def __repr__(self): 186 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 187 188 @classmethod 189 def from_proto(cls, objective_id, attributes): 190 issuer = attributes.issuer.character.sequential if attributes.issuer.WhichOneof('issuer') == 'character' else attributes.issuer.corporation.sequential 191 content_tags = [ content_tag.name for content_tag in attributes.content_tags ] 192 finished_datetime = None if attributes.WhichOneof('finished') == 'not_finished' else attributes.finish_time.ToDatetime() 193 annotations = {annotation.key:annotation.value for annotation in attributes.annotations} 194 return Objective(objective_id=ObjectiveID.from_proto(objective_id), title=attributes.title.sequential, subtitle=attributes.subtitle.sequential, issuer=issuer, presenting_character=attributes.presenting_character.sequential, content_tags=content_tags, scheduled_start_datetime=attributes.scheduled_start_time.ToDatetime(), finished_datetime=finished_datetime, career_path=PROTO_CAREER_TO_FDS_CAREER[attributes.career], target_progress=attributes.target_progress, max_progress_per_participant=attributes.max_progress_per_participant, contribution_method_configuration=ContributionMethodConfiguration.from_proto(attributes.contribution_method_configuration), rewards=Rewards.from_proto(attributes.rewards), objective_state=ObjectiveState.from_proto(attributes.state), annotations=annotations) 195 196 @classmethod 197 def from_flatbuffer(cls, objective): 198 objective_id = ObjectiveID.from_flatbuffer(objective.Uuid()) 199 finished_datetime = None 200 if objective.FinishedTimeType() != fb_campaign.FinishedTime.NONE: 201 union_data = objective.FinishedTime() 202 finished = fb_campaign.Finished() 203 finished.Init(union_data.Bytes, union_data.Pos) 204 finished_datetime = filetime_to_datetime(finished.Timestamp()) 205 annotations = {} 206 for i in range(objective.AnnotationsLength()): 207 annotation = objective.Annotations(i) 208 annotations[annotation.Key().decode('utf-8')] = annotation.Value().decode('utf-8') 209 210 return Objective(objective_id=objective_id, title=objective.Title(), subtitle=objective.Subtitle(), issuer=objective.Issuer(), presenting_character=objective.PresentingCharacter(), content_tags=[ objective.ContentTags(i).decode('utf-8') for i in range(objective.ContentTagsLength()) ], scheduled_start_datetime=filetime_to_datetime(objective.ScheduledStartTime()), finished_datetime=finished_datetime, career_path=objective.Career(), target_progress=objective.TargetProgress(), max_progress_per_participant=objective.MaxProgressPerParticipant(), objective_state=objective.ObjectiveState(), contribution_method_configuration=ContributionMethodConfiguration.from_flatbuffer(objective.ContributionMethodConfig()), rewards=Rewards.from_flatbuffer(objective.Rewards()), annotations=annotations) 211 212 def to_flatbuffer(self, builder): 213 uuid_bytes = [ ord(byte) for byte in self.id.uuid.bytes ] 214 content_tag_offsets = [] 215 for content_tag in self.content_tags: 216 content_tag_offsets.append(builder.CreateString(content_tag)) 217 218 fb_campaign.ObjectiveStartContentTagsVector(builder, len(content_tag_offsets)) 219 for content_tag_offset in reversed(content_tag_offsets): 220 builder.PrependUOffsetTRelative(content_tag_offset) 221 222 content_tags_fb = builder.EndVector() 223 annotations_list = [] 224 for key, value in self.annotations.iteritems(): 225 key_fb = builder.CreateString(key) 226 value_fb = builder.CreateString(value) 227 fb_campaign.AnnotationStart(builder) 228 fb_campaign.AnnotationAddKey(builder, key_fb) 229 fb_campaign.AnnotationAddValue(builder, value_fb) 230 annotation_fb = fb_campaign.AnnotationEnd(builder) 231 annotations_list.append(annotation_fb) 232 233 fb_campaign.ObjectiveStartAnnotationsVector(builder, len(annotations_list)) 234 for annotation in reversed(annotations_list): 235 builder.PrependUOffsetTRelative(annotation) 236 237 annotations_fb = builder.EndVector() 238 if self.finished_datetime is not None: 239 finished_type = fb_campaign.FinishedTime.FinishedTime 240 else: 241 finished_type = fb_campaign.FinishedTime.NONE 242 finished_time_fb = None 243 if self.finished_datetime is not None: 244 fb_campaign.FinishedStart(builder) 245 fb_campaign.FinishedAddTimestamp(builder, datetime_to_filetime(self.finished_datetime)) 246 finished_time_fb = fb_campaign.FinishedEnd(builder) 247 rewards_db = self.rewards.to_flatbuffer(builder) 248 contribution_method_config_fb = self.contribution_method_configuration.to_flatbuffer(builder) 249 fb_campaign.ObjectiveStart(builder) 250 fb_campaign.ObjectiveAddUuid(builder, fb_campaign.CreateUuid(builder, uuid_bytes)) 251 fb_campaign.ObjectiveAddTitle(builder, self.title) 252 fb_campaign.ObjectiveAddSubtitle(builder, self.subtitle) 253 fb_campaign.ObjectiveAddIssuer(builder, self.issuer) 254 fb_campaign.ObjectiveAddPresentingCharacter(builder, self.presenting_character) 255 fb_campaign.ObjectiveAddContentTags(builder, content_tags_fb) 256 fb_campaign.ObjectiveAddScheduledStartTime(builder, datetime_to_filetime(self.scheduled_start_datetime)) 257 fb_campaign.ObjectiveAddFinishedTimeType(builder, finished_type) 258 if finished_time_fb is not None: 259 fb_campaign.ObjectiveAddFinishedTime(builder, finished_time_fb) 260 fb_campaign.ObjectiveAddCareer(builder, self.career_path) 261 fb_campaign.ObjectiveAddTargetProgress(builder, self.target_progress) 262 fb_campaign.ObjectiveAddMaxProgressPerParticipant(builder, self.max_progress_per_participant) 263 fb_campaign.ObjectiveAddContributionMethodConfig(builder, contribution_method_config_fb) 264 fb_campaign.ObjectiveAddRewards(builder, rewards_db) 265 fb_campaign.ObjectiveAddObjectiveState(builder, self.objective_state) 266 fb_campaign.ObjectiveAddAnnotations(builder, annotations_fb) 267 return fb_campaign.ObjectiveEnd(builder) 268 269 def __eq__(self, other): 270 if not isinstance(other, Objective): 271 return NotImplemented 272 return self.id == other.id and self.title == other.title and self.subtitle == other.subtitle and self.issuer == other.issuer and self.presenting_character == other.presenting_character and self.content_tags == other.content_tags and self.scheduled_start_datetime == other.scheduled_start_datetime and self.finished_datetime == other.finished_datetime and self.career_path == other.career_path and self.target_progress == other.target_progress and self.max_progress_per_participant == other.max_progress_per_participant and self.contribution_method_configuration == other.contribution_method_configuration and self.rewards == other.rewards and self.objective_state == other.objective_state and self.annotations == other.annotations 273 274 def __ne__(self, other): 275 return not self.__eq__(other) 276 277 278 @Enum 279 280 class ObjectiveState(object): 281 UNSPECIFIED = 0 282 ACTIVE = 1 283 COMPLETED = 2 284 EXPIRED = 3 285 CANCELLED = 4 286 287 @classmethod 288 def from_proto(cls, objective_state): 289 enum_value = _objective_state_proto_to_enum.get(objective_state, None) 290 if enum_value is None: 291 raise ValueError('ObjectiveState: Conversion to enum failed with unrecognized value: %s' % objective_state) 292 return enum_value 293 294 295 _objective_state_proto_to_enum = {STATE_UNSPECIFIED: ObjectiveState.UNSPECIFIED, 296 STATE_ACTIVE: ObjectiveState.ACTIVE, 297 STATE_COMPLETED: ObjectiveState.COMPLETED, 298 STATE_EXPIRED: ObjectiveState.EXPIRED, 299 STATE_CANCELLED: ObjectiveState.CANCELLED} 300 301 class ObjectiveStats(object): 302 303 def __init__(self, objective_id, current_objective_progress, committed_participants, total_participants, total_contributors): 304 self._objective_id = objective_id 305 self._current_objective_progress = current_objective_progress 306 self._committed_participants = committed_participants 307 self._total_participants = total_participants 308 self._total_contributors = total_contributors 309 310 @property 311 def objective_id(self): 312 return self._objective_id 313 314 @property 315 def current_objective_progress(self): 316 return self._current_objective_progress 317 318 @property 319 def committed_participants(self): 320 return self._committed_participants 321 322 @property 323 def total_participants(self): 324 return self._total_participants 325 326 @property 327 def total_contributors(self): 328 return self._total_contributors 329 330 def __repr__(self): 331 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 332 333 @classmethod 334 def from_proto(cls, objective_id, stats): 335 return ObjectiveStats(objective_id=ObjectiveID.from_proto(objective_id), current_objective_progress=stats.current_objective_progress, committed_participants=stats.committed_participants, total_participants=stats.total_participants, total_contributors=stats.total_contributors) 336 337 def __eq__(self, other): 338 if not isinstance(other, ObjectiveStats): 339 return NotImplemented 340 return (self.objective_id == other.objective_id, 341 self.current_objective_progress == other.current_objective_progress, 342 self.committed_participants == other.committed_participants, 343 self.total_participants == other.total_participants, 344 self.total_contributors == other.total_contributors) 345 346 def __ne__(self, other): 347 return not self == other 348 349 350 @Enum 351 352 class ParticipantState(object): 353 UNSPECIFIED = 0 354 COMMITTED = 1 355 RESIGNED = 2 356 CONTRIBUTION_COMPLETED = 3 357 358 @classmethod 359 def from_proto(cls, participant_state): 360 enum_value = _participant_state_proto_to_enum.get(participant_state, None) 361 if enum_value is None: 362 raise ValueError('ParticipantState: Conversion to enum failed with unrecognized value: %s' % participant_state) 363 return enum_value 364 365 366 _participant_state_proto_to_enum = {PARTICIPANT_STATE_UNSPECIFIED: ParticipantState.UNSPECIFIED, 367 PARTICIPANT_STATE_COMMITTED: ParticipantState.COMMITTED, 368 PARTICIPANT_STATE_RESIGNED: ParticipantState.RESIGNED, 369 PARTICIPANT_STATE_CONTRIBUTION_COMPLETED: ParticipantState.CONTRIBUTION_COMPLETED} 370 371 class ObjectiveParticipantStats(object): 372 373 def __init__(self, objective_id, participant_state, current_participant_progress): 374 self._objective_id = objective_id 375 self._participant_state = participant_state 376 self._current_participant_progress = current_participant_progress 377 378 @property 379 def objective_id(self): 380 return self._objective_id 381 382 @property 383 def participant_state(self): 384 return self._participant_state 385 386 @participant_state.setter 387 def participant_state(self, participant_state): 388 self._participant_state = participant_state 389 390 @property 391 def current_participant_progress(self): 392 return self._current_participant_progress 393 394 @current_participant_progress.setter 395 def current_participant_progress(self, value): 396 self._current_participant_progress = value 397 398 def __repr__(self): 399 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 400 401 @classmethod 402 def from_proto(cls, participant_stats): 403 return ObjectiveParticipantStats(objective_id=ObjectiveID.from_proto(participant_stats.objective), participant_state=ParticipantState.from_proto(participant_stats.stats.state), current_participant_progress=participant_stats.stats.current_participant_progress) 404 405 def __eq__(self, other): 406 if not isinstance(other, ObjectiveParticipantStats): 407 return NotImplemented 408 return self.objective_id == other.objective_id and self.participant_state == other.participant_state and self.current_participant_progress == other.current_participant_progress 409 410 def __ne__(self, other): 411 return not self == other 412 413 414 class Rewards(object): 415 416 def __init__(self, isk_reward, lp_reward, standings_reward): 417 self._isk_reward = isk_reward 418 self._lp_reward = lp_reward 419 self._standings_reward = standings_reward 420 421 @property 422 def isk_reward(self): 423 return self._isk_reward 424 425 @property 426 def lp_reward(self): 427 return self._lp_reward 428 429 @property 430 def standings_reward(self): 431 return self._standings_reward 432 433 @property 434 def has_isk_reward(self): 435 return self._isk_reward is not None 436 437 @property 438 def has_lp_reward(self): 439 return self._lp_reward is not None 440 441 @property 442 def has_standings_reward(self): 443 return self._standings_reward is not None 444 445 def __repr__(self): 446 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 447 448 @classmethod 449 def from_proto(cls, rewards): 450 isk_reward = None if rewards.WhichOneof('isk') == 'no_isk_reward' else ISKReward.from_proto(rewards.isk_reward) 451 lp_reward = None if rewards.WhichOneof('lp') == 'no_lp_reward' else LPReward.from_proto(rewards.lp_reward) 452 standing_reward = None if rewards.WhichOneof('standing') == 'no_standing_reward' else StandingReward.from_proto(rewards.standing_reward) 453 return Rewards(isk_reward, lp_reward, standing_reward) 454 455 @classmethod 456 def from_flatbuffer(cls, rewards): 457 if rewards.IskType() == fb_campaign.IskReward.NONE: 458 isk_reward = None 459 else: 460 union_data = rewards.Isk() 461 isk_fb = fb_campaign.RewardDetails() 462 isk_fb.Init(union_data.Bytes, union_data.Pos) 463 isk_reward = ISKReward(amount_per_interval=isk_fb.AmountPerInterval(), issuer=isk_fb.Issuer(), interval_size=isk_fb.IntervalSize()) 464 if rewards.LpType() == fb_campaign.LpReward.NONE: 465 lp_reward = None 466 else: 467 union_data = rewards.Lp() 468 lp_fb = fb_campaign.RewardDetails() 469 lp_fb.Init(union_data.Bytes, union_data.Pos) 470 lp_reward = LPReward(amount_per_interval=lp_fb.AmountPerInterval(), issuing_corporation=lp_fb.Issuer(), interval_size=lp_fb.IntervalSize()) 471 if rewards.StandingType() == fb_campaign.StandingReward.NONE: 472 standing_reward = None 473 else: 474 union_data = rewards.Standing() 475 standing_fb = fb_campaign.RewardDetails() 476 standing_fb.Init(union_data.Bytes, union_data.Pos) 477 standing_reward = StandingReward(gain_percentage_per_interval=standing_fb.AmountPerInterval(), issuer=standing_fb.Issuer(), interval_size=standing_fb.IntervalSize()) 478 return Rewards(isk_reward=isk_reward, lp_reward=lp_reward, standings_reward=standing_reward) 479 480 def to_flatbuffer(self, builder): 481 isk_type = fb_campaign.IskReward.NONE if self.isk_reward is None else fb_campaign.IskReward.details 482 lp_type = fb_campaign.LpReward.NONE if self.lp_reward is None else fb_campaign.LpReward.details 483 standing_type = fb_campaign.StandingReward.NONE if self.standings_reward is None else fb_campaign.StandingReward.details 484 isk_fb = None 485 if self.isk_reward is not None: 486 fb_campaign.RewardDetailsStart(builder) 487 fb_campaign.RewardDetailsAddAmountPerInterval(builder, self.isk_reward.amount_per_interval) 488 fb_campaign.RewardDetailsAddIssuer(builder, self.isk_reward.issuer) 489 fb_campaign.RewardDetailsAddIntervalSize(builder, self.isk_reward.interval_size) 490 isk_fb = fb_campaign.RewardDetailsEnd(builder) 491 lp_fb = None 492 if self.lp_reward is not None: 493 fb_campaign.RewardDetailsStart(builder) 494 fb_campaign.RewardDetailsAddAmountPerInterval(builder, self.lp_reward.amount_per_interval) 495 fb_campaign.RewardDetailsAddIssuer(builder, self.lp_reward.issuing_corporation) 496 fb_campaign.RewardDetailsAddIntervalSize(builder, self.lp_reward.interval_size) 497 lp_fb = fb_campaign.RewardDetailsEnd(builder) 498 standing_fb = None 499 if self.standings_reward is not None: 500 fb_campaign.RewardDetailsStart(builder) 501 fb_campaign.RewardDetailsAddAmountPerInterval(builder, self.standings_reward.gain_percentage_per_interval) 502 fb_campaign.RewardDetailsAddIssuer(builder, self.standings_reward.issuer) 503 fb_campaign.RewardDetailsAddIntervalSize(builder, self.standings_reward.interval_size) 504 standing_fb = fb_campaign.RewardDetailsEnd(builder) 505 fb_campaign.RewardsStart(builder) 506 fb_campaign.RewardsAddIskType(builder, isk_type) 507 fb_campaign.RewardsAddLpType(builder, lp_type) 508 fb_campaign.RewardsAddStandingType(builder, standing_type) 509 if isk_fb is not None: 510 fb_campaign.RewardsAddIsk(builder, isk_fb) 511 if lp_fb is not None: 512 fb_campaign.RewardsAddLp(builder, lp_fb) 513 if standing_fb is not None: 514 fb_campaign.RewardsAddStanding(builder, standing_fb) 515 return fb_campaign.RewardsEnd(builder) 516 517 def __eq__(self, other): 518 if not isinstance(other, Rewards): 519 return NotImplemented 520 return self.isk_reward == other.isk_reward and self.lp_reward == other.lp_reward and self.standings_reward == other.standings_reward 521 522 def __ne__(self, other): 523 return not self == other 524 525 526 class ISKReward(object): 527 528 def __init__(self, amount_per_interval, issuer, interval_size): 529 self._amount_per_interval = amount_per_interval 530 self._issuer = issuer 531 self._interval_size = interval_size 532 533 @property 534 def amount_per_interval(self): 535 return self._amount_per_interval 536 537 @property 538 def issuer(self): 539 return self._issuer 540 541 @property 542 def interval_size(self): 543 return self._interval_size 544 545 @property 546 def is_corporation_issuer(self): 547 return IsCorporation(self._issuer) 548 549 @property 550 def is_character_issuer(self): 551 return IsCharacter(self._issuer) 552 553 def __repr__(self): 554 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 555 556 @classmethod 557 def from_proto(cls, isk_reward): 558 issuer = isk_reward.issuer.character.sequential if isk_reward.issuer.WhichOneof('owner_type') == 'character' else isk_reward.issuer.corporation.sequential 559 return ISKReward(amount_per_interval=get_single_value_from_split_precision_message(isk_reward.amount_per_interval), issuer=issuer, interval_size=isk_reward.progress_interval) 560 561 def __eq__(self, other): 562 if not isinstance(other, ISKReward): 563 return NotImplemented 564 return self.amount_per_interval == other.amount_per_interval and self.issuer == other.issuer and self.interval_size == other.interval_size 565 566 def __ne__(self, other): 567 return not self == other 568 569 570 class LPReward(object): 571 572 def __init__(self, amount_per_interval, issuing_corporation, interval_size): 573 self._amount_per_interval = amount_per_interval 574 self._issuing_corporation = issuing_corporation 575 self._interval_size = interval_size 576 577 @property 578 def amount_per_interval(self): 579 return self._amount_per_interval 580 581 @property 582 def issuing_corporation(self): 583 return self._issuing_corporation 584 585 @property 586 def interval_size(self): 587 return self._interval_size 588 589 def __repr__(self): 590 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 591 592 @classmethod 593 def from_proto(cls, lp_reward): 594 return LPReward(amount_per_interval=lp_reward.amount_per_interval.amount, issuing_corporation=lp_reward.amount_per_interval.associated_corporation.sequential, interval_size=lp_reward.progress_interval) 595 596 def __eq__(self, other): 597 if not isinstance(other, LPReward): 598 return NotImplemented 599 return self.amount_per_interval == other.amount_per_interval and self.issuing_corporation == other.issuing_corporation and self.interval_size == other.interval_size 600 601 602 class StandingReward(object): 603 604 def __init__(self, gain_percentage_per_interval, issuer, interval_size): 605 self._gain_percentage_per_interval = gain_percentage_per_interval 606 self._issuer = issuer 607 self._interval_size = interval_size 608 609 @property 610 def gain_percentage_per_interval(self): 611 return self._gain_percentage_per_interval 612 613 @property 614 def issuer(self): 615 return self._issuer 616 617 @property 618 def is_corporation_issuer(self): 619 return IsCorporation(self._issuer) 620 621 @property 622 def is_character_issuer(self): 623 return IsCharacter(self._issuer) 624 625 @property 626 def is_faction_issuer(self): 627 return IsFaction(self._issuer) 628 629 @property 630 def is_alliance_issuer(self): 631 return IsAlliance(self._issuer) 632 633 @property 634 def interval_size(self): 635 return self._interval_size 636 637 def __repr__(self): 638 return '<%s %r>' % (self.__class__.__name__, self.__dict__) 639 640 @classmethod 641 def from_proto(cls, standing_reward): 642 which_one_of = standing_reward.issuer.WhichOneof('source') 643 if which_one_of == 'character': 644 issuer = standing_reward.issuer.character.sequential 645 elif which_one_of == 'corporation': 646 issuer = standing_reward.issuer.corporation.sequential 647 elif which_one_of == 'alliance': 648 issuer = standing_reward.issuer.alliance.sequential 649 elif which_one_of == 'faction': 650 issuer = standing_reward.issuer.faction.sequential 651 else: 652 raise ValueError('Unrecognized issuer') 653 return StandingReward(gain_percentage_per_interval=get_single_value_from_split_precision_message(standing_reward.gain_percent_per_interval), issuer=issuer, interval_size=standing_reward.progress_interval) 654 655 def __eq__(self, other): 656 if not isinstance(other, StandingReward): 657 return NotImplemented 658 return self.gain_percentage_per_interval == other.gain_percentage_per_interval and self.issuer == other.issuer and self.interval_size == other.interval_size 659 660 def __ne__(self, other): 661 return not self == other