Fix an issue with campaigns reporting incorrect remaining time
This commit is contained in:
1 parent
bb51bf7400
commit
bdf53fb33d
1 file changed
+28
-5
+28
-5
@@ -80,13 +80,24 @@ class BaseDrop:
|
|||||||
return f"Drop({self.rewards_text()}{additional})"
|
return f"Drop({self.rewards_text()}{additional})"
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def preconditions(self) -> bool:
|
def preconditions_met(self) -> bool:
|
||||||
campaign = self.campaign
|
campaign = self.campaign
|
||||||
return all(campaign.timed_drops[pid].is_claimed for pid in self._precondition_drops)
|
return all(campaign.timed_drops[pid].is_claimed for pid in self._precondition_drops)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def _all_preconditions(self) -> set[str]:
|
||||||
|
campaign = self.campaign
|
||||||
|
preconditions: set[str] = set(self._precondition_drops)
|
||||||
|
return preconditions.union(
|
||||||
|
*(
|
||||||
|
campaign.timed_drops[pid]._all_preconditions
|
||||||
|
for pid in self._precondition_drops
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _base_can_earn(self) -> bool:
|
def _base_can_earn(self) -> bool:
|
||||||
return (
|
return (
|
||||||
self.preconditions # preconditions are met
|
self.preconditions_met # preconditions are met
|
||||||
and not self.is_claimed # isn't already claimed
|
and not self.is_claimed # isn't already claimed
|
||||||
# is within the timeframe
|
# is within the timeframe
|
||||||
and self.starts_at <= datetime.now(timezone.utc) < self.ends_at
|
and self.starts_at <= datetime.now(timezone.utc) < self.ends_at
|
||||||
@@ -97,7 +108,7 @@ class BaseDrop:
|
|||||||
|
|
||||||
def can_earn_within(self, stamp: datetime) -> bool:
|
def can_earn_within(self, stamp: datetime) -> bool:
|
||||||
return (
|
return (
|
||||||
self.preconditions # preconditions are met
|
self.preconditions_met # preconditions are met
|
||||||
and not self.is_claimed # isn't already claimed
|
and not self.is_claimed # isn't already claimed
|
||||||
and self.ends_at > datetime.now(timezone.utc)
|
and self.ends_at > datetime.now(timezone.utc)
|
||||||
and self.starts_at < stamp
|
and self.starts_at < stamp
|
||||||
@@ -108,7 +119,7 @@ class BaseDrop:
|
|||||||
return self.claim_id is not None
|
return self.claim_id is not None
|
||||||
|
|
||||||
def _on_claim(self) -> None:
|
def _on_claim(self) -> None:
|
||||||
invalidate_cache(self, "preconditions")
|
invalidate_cache(self, "preconditions_met")
|
||||||
|
|
||||||
def update_claim(self, claim_id: str):
|
def update_claim(self, claim_id: str):
|
||||||
self.claim_id = claim_id
|
self.claim_id = claim_id
|
||||||
@@ -184,6 +195,18 @@ class TimedDrop(BaseDrop):
|
|||||||
def remaining_minutes(self) -> int:
|
def remaining_minutes(self) -> int:
|
||||||
return self.required_minutes - self.current_minutes
|
return self.required_minutes - self.current_minutes
|
||||||
|
|
||||||
|
@property
|
||||||
|
def total_remaining_minutes(self) -> int:
|
||||||
|
return (
|
||||||
|
sum(
|
||||||
|
(
|
||||||
|
self.campaign.timed_drops[pid].remaining_minutes
|
||||||
|
for pid in self._all_preconditions
|
||||||
|
),
|
||||||
|
start=self.remaining_minutes,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def progress(self) -> float:
|
def progress(self) -> float:
|
||||||
return self.current_minutes / self.required_minutes
|
return self.current_minutes / self.required_minutes
|
||||||
@@ -286,7 +309,7 @@ class DropsCampaign:
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def remaining_minutes(self) -> int:
|
def remaining_minutes(self) -> int:
|
||||||
return sum(d.remaining_minutes for d in self.drops)
|
return max(d.total_remaining_minutes for d in self.drops)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def progress(self) -> float:
|
def progress(self) -> float:
|
||||||
|
|||||||
Reference in new issue
Block a user