mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-22 00:35:34 +00:00
Fix: Handle ZeroDivisionError when calculating progress
This commit is contained in:
parent
50303fe6ab
commit
0707c269d1
@ -508,4 +508,4 @@ class Synthesize(CombatObtain, ItemUI):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
self = Synthesize('src')
|
self = Synthesize('src')
|
||||||
self.device.screenshot()
|
self.device.screenshot()
|
||||||
self.synthesize_obtain_get()
|
self.synthesize_planner()
|
||||||
|
@ -118,17 +118,23 @@ class StoredPlannerProxy(BaseModelWithFallback):
|
|||||||
def val_value(self):
|
def val_value(self):
|
||||||
if self.item.has_group_base:
|
if self.item.has_group_base:
|
||||||
if not isinstance(self.value, MultiValue):
|
if not isinstance(self.value, MultiValue):
|
||||||
|
logger.warning(f'Planner item {self.item} has_group_base but given `value` is not a MultiValue')
|
||||||
self.value = MultiValue()
|
self.value = MultiValue()
|
||||||
if not isinstance(self.total, MultiValue):
|
if not isinstance(self.total, MultiValue):
|
||||||
|
logger.warning(f'Planner item {self.item} has_group_base but given `total` is not a MultiValue')
|
||||||
self.total = MultiValue()
|
self.total = MultiValue()
|
||||||
if not isinstance(self.synthesize, MultiValue):
|
if not isinstance(self.synthesize, MultiValue):
|
||||||
|
logger.warning(f'Planner item {self.item} has_group_base but given `synthesize` is not a MultiValue')
|
||||||
self.synthesize = MultiValue()
|
self.synthesize = MultiValue()
|
||||||
else:
|
else:
|
||||||
if not isinstance(self.value, int):
|
if not isinstance(self.value, int):
|
||||||
|
logger.warning(f'Planner item {self.item} has no group base but given `value` is not an int')
|
||||||
self.value = 0
|
self.value = 0
|
||||||
if not isinstance(self.total, int):
|
if not isinstance(self.total, int):
|
||||||
|
logger.warning(f'Planner item {self.item} has no group base but given `total` is not an int')
|
||||||
self.total = 0
|
self.total = 0
|
||||||
if not isinstance(self.synthesize, int):
|
if not isinstance(self.synthesize, int):
|
||||||
|
logger.warning(f'Planner item {self.item} has no group base but given `synthesize` is not an int')
|
||||||
self.synthesize = 0
|
self.synthesize = 0
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -247,9 +253,11 @@ class StoredPlannerProxy(BaseModelWithFallback):
|
|||||||
@computed_field
|
@computed_field
|
||||||
@functools_cached_property
|
@functools_cached_property
|
||||||
def progress(self) -> float:
|
def progress(self) -> float:
|
||||||
# 0 to 100
|
try:
|
||||||
progress = self.progress_current / self.progress_total * 100
|
progress = self.progress_current / self.progress_total * 100
|
||||||
return round(min(max(progress, 0), 100), 2)
|
return round(min(max(progress, 0), 100), 2)
|
||||||
|
except ZeroDivisionError:
|
||||||
|
return 100.
|
||||||
|
|
||||||
def is_approaching_total(self, wave_done: int = 0):
|
def is_approaching_total(self, wave_done: int = 0):
|
||||||
"""
|
"""
|
||||||
@ -506,7 +514,10 @@ class PlannerProgressParser:
|
|||||||
progress_current += row.progress_current
|
progress_current += row.progress_current
|
||||||
progress_total += row.progress_total
|
progress_total += row.progress_total
|
||||||
|
|
||||||
progress = round(progress_current / progress_total * 100, 2)
|
try:
|
||||||
|
progress = round(progress_current / progress_total * 100, 2)
|
||||||
|
except ZeroDivisionError:
|
||||||
|
progress = 100.
|
||||||
return progress, eta
|
return progress, eta
|
||||||
|
|
||||||
def iter_row_to_farm(self, need_farm=True) -> t.Iterable[StoredPlannerProxy]:
|
def iter_row_to_farm(self, need_farm=True) -> t.Iterable[StoredPlannerProxy]:
|
||||||
@ -605,9 +616,10 @@ class PlannerMixin(UI):
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def planner(self) -> PlannerProgressParser:
|
def planner(self) -> PlannerProgressParser:
|
||||||
data = self.config.cross_get('Dungeon.Planner', default={})
|
|
||||||
model = PlannerProgressParser().from_config(data)
|
|
||||||
logger.hr('Planner')
|
logger.hr('Planner')
|
||||||
|
data = self.config.cross_get('Dungeon.Planner', default={})
|
||||||
|
model = PlannerProgressParser()
|
||||||
|
model.from_config(data)
|
||||||
for row in model.rows.values():
|
for row in model.rows.values():
|
||||||
logger.info(row)
|
logger.info(row)
|
||||||
return model
|
return model
|
||||||
|
Loading…
Reference in New Issue
Block a user