Store allocation factors

issue10959
review351051002
This commit is contained in:
Cédric Krier
2021-12-16 22:31:08 +01:00
parent e58601ef9c
commit 4915cfdacf
2 changed files with 8 additions and 4 deletions
+2
View File
@@ -1,3 +1,5 @@
* Store allocation factors
Version 6.2.0 - 2021-11-01
* Bug fixes (see mercurial logs for details)
+6 -4
View File
@@ -14,10 +14,12 @@ class LandedCost(metaclass=PoolMeta):
cls.allocation_method.selection.append(('weight', 'By Weight'))
def allocate_cost_by_weight(self):
self._allocate_cost(self._get_weight_factors())
self.factors = self._get_weight_factors()
self._allocate_cost(self.factors)
def unallocate_cost_by_weight(self):
self._allocate_cost(self._get_weight_factors(), sign=-1)
factors = self.factors or self._get_weight_factors()
self._allocate_cost(factors, sign=-1)
def _get_weight_factors(self):
"Return the factor for each move based on weight"
@@ -32,7 +34,7 @@ class LandedCost(metaclass=PoolMeta):
length = Decimal(len(moves))
for move in moves:
if not sum_weight:
factors[move.id] = 1 / length
factors[str(move.id)] = 1 / length
else:
factors[move.id] = weights[move.id] / sum_weight
factors[str(move.id)] = weights[move.id] / sum_weight
return factors