Commit 49a54327 authored by Vincent Texier's avatar Vincent Texier

[fix] #807 fix zerosum referentials using "last" fields in blockchain

parent 2ba1c4d1
......@@ -11,14 +11,14 @@ class QuantitativeZSum(BaseReferential):
_UNITS_STR_ = QT_TRANSLATE_NOOP("QuantitativeZSum", "Q0")
_FORMULA_STR_ = QT_TRANSLATE_NOOP(
"QuantitativeZSum",
"""Q0 = Q - ( M(t-1) / N )
"""Q0 = Q - ( M(t) / N(t) )
<br >
<table>
<tr><td>Q0</td><td>Quantitative value at zero sum</td></tr>
<tr><td>Q</td><td>Quantitative value</td></tr>
<tr><td>M</td><td>Monetary mass</td></tr>
<tr><td>N</td><td>Members count</td></tr>
<tr><td>t-1</td><td>Previous UD time</td></tr>
<tr><td>t</td><td>Last UD time</td></tr>
</table>""",
)
_DESCRIPTION_STR_ = QT_TRANSLATE_NOOP(
......@@ -68,12 +68,11 @@ class QuantitativeZSum(BaseReferential):
"""
Return quantitative value of amount minus the average value
Z0 = Q - ( M(t-1) / N(t) )
Z0 = Q - ( M(t) / N(t) )
Z0 = Quantitative value at zero sum
Q = Quantitative value
t = last UD block time
t-1 = penultimate UD block time
M = Monetary mass
N = Members count
......@@ -84,7 +83,7 @@ class QuantitativeZSum(BaseReferential):
last_members_count = self._blockchain_processor.last_members_count(
self.currency
)
monetary_mass = self._blockchain_processor.current_mass(self.currency)
monetary_mass = self._blockchain_processor.last_mass(self.currency)
if last_members_count != 0:
average = int(monetary_mass / last_members_count)
else:
......@@ -112,7 +111,7 @@ class QuantitativeZSum(BaseReferential):
last_members_count = self._blockchain_processor.last_members_count(
self.currency
)
monetary_mass = self._blockchain_processor.current_mass(self.currency)
monetary_mass = self._blockchain_processor.last_mass(self.currency)
if last_members_count != 0:
average = int(monetary_mass / last_members_count)
else:
......
......@@ -11,7 +11,7 @@ class RelativeZSum(BaseReferential):
_UNITS_STR_ = QT_TRANSLATE_NOOP("RelativeZSum", "R0 UD")
_FORMULA_STR_ = QT_TRANSLATE_NOOP(
"RelativeZSum",
"""R0 = (Q / UD(t)) - (( M(t-1) / N ) / UD(t))
"""R0 = (Q / UD(t)) - (( M(t) / N(t) ) / UD(t))
<br >
<table>
<tr><td>R0</td><td>Relative value at zero sum</td></tr>
......@@ -19,7 +19,6 @@ class RelativeZSum(BaseReferential):
<tr><td>M</td><td>Monetary mass</td></tr>
<tr><td>N</td><td>Members count</td></tr>
<tr><td>t</td><td>Last UD time</td></tr>
<tr><td>t-1</td><td>Penultimate UD time</td></tr>
</table>""",
)
_DESCRIPTION_STR_ = QT_TRANSLATE_NOOP(
......@@ -65,24 +64,21 @@ class RelativeZSum(BaseReferential):
"""
Return relative value of amount minus the average value
zsum value = (value / UD(t)) - (( M(t) / N(t) ) / UD(t))
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
"""
dividend, base = self._blockchain_processor.previous_ud(self.currency)
previous_monetary_mass = self._blockchain_processor.previous_monetary_mass(
self.currency
)
members_count = self._blockchain_processor.current_members_count(self.currency)
if previous_monetary_mass and members_count > 0:
median = previous_monetary_mass / members_count
dividend, base = self._blockchain_processor.last_ud(self.currency)
monetary_mass = self._blockchain_processor.last_mass(self.currency)
members_count = self._blockchain_processor.last_members_count(self.currency)
if monetary_mass and members_count > 0:
median = monetary_mass / members_count
relative_value = self.amount / float(dividend * 10 ** base)
relative_median = median / float(dividend * 10 ** base)
else:
......@@ -100,13 +96,11 @@ class RelativeZSum(BaseReferential):
:param value: Value in referential units
:return:
"""
dividend, base = self._blockchain_processor.previous_ud(self.currency)
previous_monetary_mass = self._blockchain_processor.previous_monetary_mass(
self.currency
)
members_count = self._blockchain_processor.current_members_count(self.currency)
if previous_monetary_mass and members_count > 0:
median = previous_monetary_mass / members_count
dividend, base = self._blockchain_processor.last_ud(self.currency)
monetary_mass = self._blockchain_processor.last_mass(self.currency)
members_count = self._blockchain_processor.last_members_count(self.currency)
if monetary_mass and members_count > 0:
median = monetary_mass / members_count
relative_median = median / float(dividend * 10 ** base)
else:
relative_median = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment