diff --git a/src/sakia/core/money/quant_zerosum.py b/src/sakia/core/money/quant_zerosum.py index 703441e6530e5a81eaa0d69a3c6e08b738f8bdf0..04ab148762af9e8c36ec410e5b9aed89dfaa803a 100644 --- a/src/sakia/core/money/quant_zerosum.py +++ b/src/sakia/core/money/quant_zerosum.py @@ -30,14 +30,21 @@ class QuantitativeZSum: """ Return quantitative value of amount minus the average value + t = last UD block + t-1 = penultimate UD block + M = Monetary mass + N = Members count + + zsum value = value - ( M(t-1) / N(t) ) + :param int amount: Value :param sakia.core.community.Community community: Community instance :return: int """ ud_block = yield from self.community.get_ud_block() - if ud_block and ud_block['membersCount'] > 0: - monetary_mass = yield from self.community.monetary_mass() - average = monetary_mass / ud_block['membersCount'] + ud_block_minus_1 = yield from self.community.get_ud_block(1) + if ud_block_minus_1 and ud_block['membersCount'] > 0: + average = ud_block_minus_1['monetaryMass'] / ud_block['membersCount'] else: average = 0 return self.amount - average diff --git a/src/sakia/core/money/relative_zerosum.py b/src/sakia/core/money/relative_zerosum.py index 79d3a9f64ac95e6126929ba9c2769ccf341e919b..0e755413802765b2b0afc56d7cc2f110da2b6967 100644 --- a/src/sakia/core/money/relative_zerosum.py +++ b/src/sakia/core/money/relative_zerosum.py @@ -29,17 +29,23 @@ class RelativeZSum: """ Return relative value of amount minus the average value + t = last UD block + t-1 = penultimate UD block + M = Monetary mass + N = Members count + + zsum value = (value / UD(t)) - (( M(t-1) / N(t) ) / UD(t)) + :param int amount: Value :param sakia.core.community.Community community: Community instance :return: float """ ud_block = yield from self.community.get_ud_block() - if ud_block and ud_block['membersCount'] > 0: - monetary_mass = yield from self.community.monetary_mass() - dividend = yield from self.community.dividend() - median = monetary_mass / ud_block['membersCount'] - relative_value = self.amount / float(dividend) - relative_median = median / dividend + ud_block_minus_1 = yield from self.community.get_ud_block(1) + if ud_block_minus_1 and ud_block['membersCount'] > 0: + median = ud_block_minus_1['monetaryMass'] / ud_block['membersCount'] + relative_value = self.amount / float(ud_block['dividend']) + relative_median = median / ud_block['dividend'] else: relative_value = self.amount relative_median = 0