diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index 04021a4e1adb68eacd8a617768c31bab62443eec..2a8f01a376073f3cfff35bba7e4392eb3c65de52 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -21,7 +21,7 @@ from .person import Person from ..tools.exceptions import NoPeerAvailable -def units(units, community): +def quantitative(units, community): return units @@ -31,6 +31,19 @@ def relative(units, community): return relative_value +def quantitative_zerosum(units, community): + median = community.monetary_mass / community.nb_members + return units - median + + +def relative_zerosum(units, community): + median = community.monetary_mass / community.nb_members + ud = community.dividend() + relative_value = units / float(ud) + relative_median = median / ud + return relative_value - relative_median + + class Account(object): ''' @@ -38,8 +51,10 @@ class Account(object): Each account has only one key, and a key can be locally referenced by only one account. ''' - referentials = {'Units': (units, '{0}'), - 'UD': (relative, 'ud {0}') + referentials = {'Units': (quantitative, '{0}'), + 'UD': (relative, 'ud {0}'), + 'Quant Z-sum': (quantitative_zerosum, 'q0 {0}'), + 'Relat Z-sum': (relative_zerosum, 'r0 {0}') } def __init__(self, salt, pubkey, name, communities, wallets, contacts, @@ -106,7 +121,6 @@ class Account(object): def add_contact(self, person): same_contact = [contact for contact in self.contacts if person.pubkey == contact.pubkey] if len(same_contact) == 0: - print("add contact") self.contacts.append(person) return True return False diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index 0eb1330cdffba52b6e6bf29da0c6cd27c47f9c16..52d4e7870b4122928045974e3e8550862b32f7cc 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -150,6 +150,7 @@ class Community(object): else: return 1 + @property def monetary_mass(self): try: block = self.request(bma.blockchain.Current) @@ -158,6 +159,15 @@ class Community(object): if '404' in e: return 0 + @property + def nb_members(self): + try: + block = self.request(bma.blockchain.Current) + return block['membersCount'] + except ValueError as e: + if '404' in e: + return 0 + def _peering_traversal(self, peer, found_peers, traversed_pubkeys): logging.debug("Read {0} peering".format(peer.pubkey)) traversed_pubkeys.append(peer.pubkey) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index f21d2d3821dddd5874a20753944f269a650274b2..ab7e74bd48a38e3edf3e44d2b962503e71f3d161 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -191,8 +191,11 @@ class MainWindow(QMainWindow, Ui_MainWindow): != self.app.default_account) self.password_asker = PasswordAskerDialog(self.app.current_account) - self.combo_referential.addItems(Account.referentials.keys()) + self.combo_referential.blockSignals(True) + self.combo_referential.addItems(sorted(Account.referentials.keys())) self.combo_referential.setEnabled(True) + self.combo_referential.blockSignals(False) + self.combo_referential.setCurrentText(self.app.current_account.referential) self.menu_contacts.setEnabled(True) self.action_configure_parameters.setEnabled(True) self.menu_actions.setEnabled(True) diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index f296d7145aab031a87e2f8bf1ee56e1cf56be2f6..a8affe829b16b36cf03b69ca0d68d1ab485baf0c 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -92,7 +92,7 @@ class HistoryTableModel(QAbstractTableModel): amount_ref = self.account.units_to_ref(amount, self.community) ref_name = self.account.ref_name(self.community.short_currency) - return (date.date(), sender, "", "{0} {1}".format(amount_ref, ref_name), + return (date.date(), sender, "", "{0:.2f} {1}".format(amount_ref, ref_name), comment) def data_sent(self, tx): @@ -116,7 +116,7 @@ class HistoryTableModel(QAbstractTableModel): amount_ref = self.account.units_to_ref(-amount, self.community) ref_name = self.account.ref_name(self.community.short_currency) - return (date.date(), receiver, "{0} {1}".format(amount_ref, ref_name), + return (date.date(), receiver, "{0:.2f} {1}".format(amount_ref, ref_name), "", comment) def data(self, index, role): diff --git a/src/cutecoin/models/wallets.py b/src/cutecoin/models/wallets.py index 10b462f06054691fdf120cbcad81f3c60fd26157..3887b36dff3abb30316de793fc8fc2984080db1b 100644 --- a/src/cutecoin/models/wallets.py +++ b/src/cutecoin/models/wallets.py @@ -34,7 +34,7 @@ class WalletsListModel(QAbstractListModel): ref_amount = self.account.units_to_ref(amount, self.community) ref_name = self.account.ref_name(self.community.currency) return """{0} -{1} {2}""".format(w.name, ref_amount, ref_name) +{1:.2f} {2}""".format(w.name, ref_amount, ref_name) elif role == Qt.EditRole: return self.wallets[row].name