Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
821cfcc2
Commit
821cfcc2
authored
4 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#807
add Percent of Average referential
parent
316b1de7
No related branches found
No related tags found
2 merge requests
!781
0.52.0
,
!780
Issue 807
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/sakia/money/__init__.py
+8
-1
8 additions, 1 deletion
src/sakia/money/__init__.py
src/sakia/money/base_referential.py
+11
-5
11 additions, 5 deletions
src/sakia/money/base_referential.py
src/sakia/money/percent_of_average.py
+131
-0
131 additions, 0 deletions
src/sakia/money/percent_of_average.py
with
150 additions
and
6 deletions
src/sakia/money/__init__.py
+
8
−
1
View file @
821cfcc2
...
@@ -2,5 +2,12 @@ from .quantitative import Quantitative
...
@@ -2,5 +2,12 @@ from .quantitative import Quantitative
from
.relative
import
Relative
from
.relative
import
Relative
from
.quant_zerosum
import
QuantitativeZSum
from
.quant_zerosum
import
QuantitativeZSum
from
.relative_zerosum
import
RelativeZSum
from
.relative_zerosum
import
RelativeZSum
from
.percent_of_average
import
PercentOfAverage
Referentials
=
(
Quantitative
,
Relative
,
QuantitativeZSum
,
RelativeZSum
)
Referentials
=
(
Quantitative
,
Relative
,
PercentOfAverage
,
QuantitativeZSum
,
RelativeZSum
,
)
This diff is collapsed.
Click to expand it.
src/sakia/money/base_referential.py
+
11
−
5
View file @
821cfcc2
from
typing
import
Optional
class
BaseReferential
:
class
BaseReferential
:
"""
"""
Interface to all referentials
Interface to all referentials
"""
"""
def
__init__
(
self
,
amount
,
currency
,
app
,
block_number
=
None
):
def
__init__
(
self
,
amount
:
float
,
currency
:
str
,
app
,
block_number
:
Optional
[
int
]
=
None
):
"""
"""
Init base referential instance
:param
int
amount:
:param amount:
Amount to transform
:param
str
currency
:
:param
currency: Name of
currency
:param
sakia.
app
.
Application
app:
:param app
:
Application
instance
:param
int
block_number:
:param block_number:
Block number
"""
"""
self
.
amount
=
amount
self
.
amount
=
amount
self
.
app
=
app
self
.
app
=
app
...
...
This diff is collapsed.
Click to expand it.
src/sakia/money/percent_of_average.py
0 → 100644
+
131
−
0
View file @
821cfcc2
from
typing
import
Optional
from
.base_referential
import
BaseReferential
from
..data.processors
import
BlockchainProcessor
from
PyQt5.QtCore
import
QCoreApplication
,
QT_TRANSLATE_NOOP
,
QLocale
class
PercentOfAverage
(
BaseReferential
):
_NAME_STR_
=
QT_TRANSLATE_NOOP
(
"
PercentOfAverage
"
,
"
PoA
"
)
_REF_STR_
=
QT_TRANSLATE_NOOP
(
"
PercentOfAverage
"
,
"
{0} {1}{2}
"
)
_UNITS_STR_
=
QT_TRANSLATE_NOOP
(
"
PercentOfAverage
"
,
"
PoA
"
)
_FORMULA_STR_
=
QT_TRANSLATE_NOOP
(
"
PercentOfAverage
"
,
"""
PoA = (Q / ( M(t-1) / N)) / 100
<br >
<table>
<tr><td>PoA</td><td>Percent of Average value</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>
</table>
"""
,
)
_DESCRIPTION_STR_
=
QT_TRANSLATE_NOOP
(
"
PercentOfAverage
"
,
"""
Percent of Average referential of the money.<br />
Percent of Average value PoA is calculated by dividing the quantitative value Q by the average<br />
then multiply by one hundred.<br />
This referential is relative and more reliable to display prices and accounts, when UD is two low.<br />
No money creation or destruction is apparent here and every account tend to<br />
the average.
"""
,
)
def
__init__
(
self
,
amount
,
currency
,
app
,
block_number
=
None
):
super
().
__init__
(
amount
,
currency
,
app
,
block_number
)
self
.
_blockchain_processor
=
BlockchainProcessor
.
instanciate
(
self
.
app
)
@classmethod
def
instance
(
cls
,
amount
:
float
,
currency
:
str
,
app
,
block_number
:
Optional
[
int
]
=
None
):
"""
Init PercentOfAverage referential instance
:param amount: Amount to transform
:param currency: Name of currency
:param app: Application instance
:param block_number: Block number
:return:
"""
return
cls
(
amount
,
currency
,
app
,
block_number
)
@classmethod
def
translated_name
(
cls
):
return
QCoreApplication
.
translate
(
"
PercentOfAverage
"
,
PercentOfAverage
.
_NAME_STR_
)
@property
def
units
(
self
):
return
QCoreApplication
.
translate
(
"
PercentOfAverage
"
,
PercentOfAverage
.
_UNITS_STR_
)
@property
def
formula
(
self
):
return
QCoreApplication
.
translate
(
"
PercentOfAverage
"
,
PercentOfAverage
.
_FORMULA_STR_
)
@property
def
description
(
self
):
return
QCoreApplication
.
translate
(
"
PercentOfAverage
"
,
PercentOfAverage
.
_DESCRIPTION_STR_
)
@property
def
diff_units
(
self
):
return
self
.
units
@staticmethod
def
base_str
(
base
):
return
""
def
value
(
self
):
"""
Return relative value of amount
value = amount / UD(t)
:param int amount: Value
:param sakia.core.community.Community community: Community instance
:return: float
"""
mass
=
self
.
_blockchain_processor
.
last_mass
(
self
.
currency
)
members
=
self
.
_blockchain_processor
.
last_members_count
(
self
.
currency
)
average
=
mass
/
members
if
average
>
0
:
return
self
.
amount
/
average
*
100
else
:
return
self
.
amount
def
differential
(
self
):
return
self
.
value
()
def
localized
(
self
,
units
=
False
,
show_base
=
False
):
value
=
self
.
value
()
localized_value
=
QLocale
().
toString
(
float
(
value
),
"
f
"
,
self
.
app
.
parameters
.
digits_after_comma
)
if
units
:
return
QCoreApplication
.
translate
(
"
PercentOfAverage
"
,
PercentOfAverage
.
_REF_STR_
).
format
(
localized_value
,
""
,
(
self
.
units
if
units
else
""
))
else
:
return
localized_value
def
diff_localized
(
self
,
units
=
False
,
show_base
=
False
):
value
=
self
.
differential
()
localized_value
=
QLocale
().
toString
(
float
(
value
),
"
f
"
,
self
.
app
.
parameters
.
digits_after_comma
)
if
units
:
return
QCoreApplication
.
translate
(
"
PercentOfAverage
"
,
PercentOfAverage
.
_REF_STR_
).
format
(
localized_value
,
""
,
(
self
.
diff_units
if
units
else
""
))
else
:
return
localized_value
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment