Skip to content
Snippets Groups Projects
Commit 8e852220 authored by inso's avatar inso
Browse files

Multiple fixes in referentials

parent da58e28e
No related branches found
No related tags found
No related merge requests found
from enum import Enum
class RefType(Enum):
q = 0
r = 1
from .quantitative import Quantitative
from .relative import Relative
from .quant_zerosum import QuantitativeZSum
......
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale
from . import Quantitative
......@@ -24,7 +24,7 @@ class QuantitativeZSum:
def diff_units(cls, currency):
return QuantitativeZSum.units(currency)
def compute(self):
def value(self):
"""
Return quantitative value of amount minus the average value
......@@ -43,8 +43,15 @@ class QuantitativeZSum:
return Quantitative(self.amount, self.community, self.app).compute()
def localized(self, pretty_print=False):
value = self.compute()
return QCoreApplication.translate("Quantitative", Quantitative._REF_STR_).format(value, self.community.currency)
value = self.value()
if pretty_print:
pass
else:
strvalue = QLocale().toString(float(value), 'f', 0)
return QCoreApplication.translate("QuantitativeZSum",
QuantitativeZSum._REF_STR_) \
.format(strvalue,
self.community.short_currency)
def diff_localized(self, pretty_print=False):
return Quantitative(self.amount, self.community, self.app).amount_to_str(pretty_print)
\ No newline at end of file
return Quantitative(self.amount, self.community, self.app).localized(pretty_print)
\ No newline at end of file
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QObject, QLocale
class Quantitative(QObject):
class Quantitative():
_NAME_STR_ = QT_TRANSLATE_NOOP('Quantitative', 'Units')
_REF_STR_ = QT_TRANSLATE_NOOP('Quantitative', "{0} {1}")
_UNITS_STR_ = QT_TRANSLATE_NOOP('Quantitative', "{0}")
......@@ -13,7 +13,7 @@ class Quantitative(QObject):
@classmethod
def translated_name(cls):
return QCoreApplication.translate('Quantitative', 'UD')
return QCoreApplication.translate('Quantitative', Quantitative._NAME_STR_)
@classmethod
def units(cls, currency):
......@@ -23,7 +23,7 @@ class Quantitative(QObject):
def diff_units(cls, currency):
return Quantitative.units(currency)
def compute(self):
def value(self):
"""
Return quantitative value of amount
......@@ -34,11 +34,26 @@ class Quantitative(QObject):
return int(self.amount)
def differential(self):
return self.compute()
return self.value()
def localized(self, pretty_print=False):
return QCoreApplication.translate("Quantitative", Quantitative._REF_STR_).format(self.amount, self.currency)
value = self.value()
if pretty_print:
pass
else:
strvalue = QLocale().toString(float(value), 'f', 0)
return QCoreApplication.translate("Quantitative",
Quantitative._REF_STR_) \
.format(strvalue,
self.community.short_currency)
def diff_localized(self, pretty_print=False):
strvalue = QLocale().toString(float(self.amount), 'f', 0)
return QCoreApplication.translate("Quantitative", Quantitative._REF_STR_).format(strvalue, self.currency)
value = self.differential()
if pretty_print:
pass
else:
strvalue = QLocale().toString(float(value), 'f', 0)
return QCoreApplication.translate("Quantitative",
Quantitative._REF_STR_) \
.format(strvalue,
self.community.short_currency)
from PyQt5.QtCore import QObject, QCoreApplication, QT_TRANSLATE_NOOP, QLocale
class Relative(QObject):
class Relative():
_NAME_STR_ = QT_TRANSLATE_NOOP('Relative', 'UD')
_REF_STR_ = QT_TRANSLATE_NOOP('Relative', "{0} UD {1}")
_UNITS_STR_ = QT_TRANSLATE_NOOP('Relative', "UD {0}")
......@@ -23,7 +23,7 @@ class Relative(QObject):
def diff_units(self, currency):
return self.units(currency)
def compute(self):
def value(self):
"""
Return relaive value of amount
type
......@@ -37,16 +37,16 @@ class Relative(QObject):
return 0
def differential(self):
return self.compute()
return self.value()
def localized(self, pretty_print=False):
value = self.compute()
value = self.value()
if pretty_print:
pass
else:
strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
return QCoreApplication.translate("Relative", Relative._REF_STR_).format(strvalue,
self.community.currency)
self.community.short_currency)
def diff_localized(self, pretty_print=False):
value = self.differential()
......@@ -55,4 +55,4 @@ class Relative(QObject):
else:
strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
return QCoreApplication.translate("Relative", Relative._REF_STR_).format(strvalue,
self.community.currency)
self.community.short_currency)
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP
from . import relative
from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale
from .relative import Relative
class RelativeZSum:
......@@ -42,11 +42,22 @@ class RelativeZSum:
return relative_value - relative_median
def differential(self):
return relative.compute(self.amount, self.community)
return Relative(self.amount, self.community, self.app).value()
def localized(self, pretty_print=False):
value = self.compute(self.amount, self.community)
return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_).format(value, self.community)
value = self.value()
if pretty_print:
pass
else:
strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_).format(strvalue,
self.community.short_currency)
def diff_localized(self, pretty_print=False):
return relative.amount_to_str(self.amount, self.community, pretty_print)
\ No newline at end of file
value = self.differential()
if pretty_print:
pass
else:
strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_).format(strvalue,
self.community.short_currency)
......@@ -147,18 +147,16 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
# set infos in label
self.label_balance.setText(
self.tr("{:} {:}")
self.tr("{:}")
.format(
localized_amount,
self.account.current_ref.units(self.community.currency)
localized_amount
)
)
self.label_balance_range.setText(
self.tr("in [{:} ; {:}] {:}")
self.tr("in [{:} ; {:}]")
.format(
localized_minimum,
localized_maximum,
self.account.current_ref.units(self.community.currency)
localized_maximum
)
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment