From 067f29649b085aaf627f4052ff175087dfbfee2a Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Sun, 10 Jan 2016 12:22:15 +0100 Subject: [PATCH] refs #335 Fix wrong ZSUM values calculation UD(t) is included in the monetary mass M(t) so we can only use it on M(t-1) to calculate relative values. Formulae for ZSUM values : t = last UD block t-1 = penultimate UD block M = Monetary mass N = Members count Q0 value = value - ( M(t-1) / N(t) ) R0 value = (value / UD(t)) - (( M(t-1) / N(t) ) / UD(t)) --- src/sakia/core/money/quant_zerosum.py | 13 ++++++++++--- src/sakia/core/money/relative_zerosum.py | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/sakia/core/money/quant_zerosum.py b/src/sakia/core/money/quant_zerosum.py index 703441e6..04ab1487 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 79d3a9f6..0e755413 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 -- GitLab