diff --git a/src/production_planner/cells/_cells.py b/src/production_planner/cells/_cells.py index ddea6e5..aa990b6 100644 --- a/src/production_planner/cells/_cells.py +++ b/src/production_planner/cells/_cells.py @@ -6,6 +6,7 @@ from ..core import ( get_path, set_path, + smartround, SummaryNode, ) from dataclasses import dataclass @@ -14,6 +15,8 @@ from rich.style import Style from rich.color import Color +from numbers import Number + @dataclass class Bounds: @@ -30,7 +33,7 @@ class SetCellValue: @dataclass class CellValue: value: float = 0 - text = None + text: str = None clamped: bool = False @@ -78,7 +81,7 @@ def get_num(self): def get_styled(self): cell = self.get() value = cell.value - txt = str(cell.text or cell.value) + txt = str(cell.text or (smartround(cell.value) if isinstance(cell.value, Number) else cell.value)) style = Style() if self.style_summary: diff --git a/src/production_planner/cells/ingredient.py b/src/production_planner/cells/ingredient.py index a78bb2d..e36b009 100644 --- a/src/production_planner/cells/ingredient.py +++ b/src/production_planner/cells/ingredient.py @@ -36,11 +36,15 @@ def text_postprocess(self, text: str, style: Style) -> (str, Style): def get(self) -> CellValue: if self.access_guard(): + value = smartround(self.data.node_main.ingredients[self.vispath]) + if self.data.node_main.clamp and self.data.node_main.clamp.name == self.vispath: - return CellValue(self.data.node_main.clamp.count, clamped=True) + if abs(value - self.data.node_main.clamp.count) > 0.01: + return CellValue(value, text=f"{value} !", clamped=True) + else: + return CellValue(value, clamped=True) else: - value = self.data.node_main.ingredients[self.vispath] - return CellValue(smartround(value)) + return CellValue(value) else: return CellValue(self.default_na) diff --git a/src/production_planner/core/node.py b/src/production_planner/core/node.py index 8f30aa4..9efebed 100644 --- a/src/production_planner/core/node.py +++ b/src/production_planner/core/node.py @@ -97,7 +97,8 @@ def update(self): self.ingredients = {} rate_mult = 60 / self.recipe.cycle_rate - if self.clamp: + if self.clamp and self.count: + for ingredient in self.recipe.inputs: if ingredient.name == self.clamp.name: # self.clock_rate = ((abs(int(clamped.count)) * 100) / (rate_mult / self.count)) / ingredient.count @@ -127,9 +128,6 @@ def update(self): else: total = out.count * ingredient_mult self.ingredients[out.name] = total - if self.clamp and self.clamp.name == out.name and abs(self.clamp.count - total) > 0.01: - from ..core import smartround - self.clamp.count = smartround(total) if self.producer.is_pow_gen: pass # TODO diff --git a/tests b/tests index b09c891..a6c7d1b 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit b09c891989d39b81fb4d4acd7d4f5fd1e55bc813 +Subproject commit a6c7d1bdc9d91d3afad55641084f12cac2056169