From fcf23c37d8661582e1a02da835eb866b62958fbe Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Sun, 1 Feb 2015 11:48:52 +0100 Subject: [PATCH] Remove tables and use labels in informations tab Add money rules --- src/cutecoin/gui/informations_tab.py | 200 +++++++++++++++------------ src/cutecoin/models/parameters.py | 107 -------------- 2 files changed, 109 insertions(+), 198 deletions(-) delete mode 100644 src/cutecoin/models/parameters.py diff --git a/src/cutecoin/gui/informations_tab.py b/src/cutecoin/gui/informations_tab.py index 86fe7789..207d4a51 100644 --- a/src/cutecoin/gui/informations_tab.py +++ b/src/cutecoin/gui/informations_tab.py @@ -1,18 +1,15 @@ """ -Created on 2 févr. 2014 +Created on 31 janv. 2015 -@author: inso +@author: vit """ import logging -from PyQt5.QtWidgets import QWidget, QHeaderView -from PyQt5.QtCore import Qt -from ..models.parameters import ParametersModel +from PyQt5.QtWidgets import QWidget from ..gen_resources.informations_tab_uic import Ui_InformationsTabWidget class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): - """ classdocs """ @@ -26,101 +23,122 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): self.community = community self.account = account - self.table_general.HorizontalHeader = QHeaderView(Qt.Orientation(Qt.Horizontal)) - #self.table_general.HorizontalHeader.setSectionResizeMode(QHeaderView.ResizeToContents) - self.table_general.HorizontalHeader.setStretchLastSection(True) - self.table_general.setHorizontalHeader(self.table_general.HorizontalHeader) - self.table_general.horizontalHeader().hide() - self.table_general.verticalHeader().hide() - - self.table_money.HorizontalHeader = QHeaderView(Qt.Orientation(Qt.Horizontal)) - #self.table_money.HorizontalHeader.setSectionResizeMode(QHeaderView.ResizeToContents) - self.table_money.HorizontalHeader.setStretchLastSection(True) - self.table_money.setHorizontalHeader(self.table_money.HorizontalHeader) - self.table_money.horizontalHeader().hide() - self.table_money.verticalHeader().hide() - - self.table_wot.HorizontalHeader = QHeaderView(Qt.Orientation(Qt.Horizontal)) - #self.table_wot.HorizontalHeader.setSectionResizeMode(QHeaderView.ResizeToContents) - self.table_wot.HorizontalHeader.setStretchLastSection(True) - self.table_wot.setHorizontalHeader(self.table_wot.HorizontalHeader) - self.table_wot.horizontalHeader().hide() - self.table_wot.verticalHeader().hide() - - self.display_tables() + self.refresh() - def display_tables(self): + def refresh(self): + # try to request money parameters try: params = self.community.get_parameters() except Exception as e: logging.debug('community get_parameters error : ' + str(e)) return False + # try to request money variables from last ud block try: block = self.community.get_ud_block() except Exception as e: logging.debug('community get_ud_block error : ' + str(e)) return False - general = [ - {'name': 'dividend', 'value': block['dividend'], - 'description': 'Universal Dividend UD(t) in currency units'}, - {'name': 'monetaryMass', 'value': block['monetaryMass'], - 'description': 'Monetary Mass M(t) in currency units'}, - {'name': 'membersCount', 'value': block['membersCount'], - 'description': 'Members N(t)'}, - {'name': 'monetaryMassPerMember', 'value': "{:.2f}".format(block['monetaryMass'] / block['membersCount']), - 'description': 'Monetary Mass per member M(t)/N(t) in currency units'}, - {'name': 'actualGrowth', - 'value': "{:2.2%}".format(block['dividend'] / ((block['monetaryMass'] - (block['membersCount'] * block['dividend'])) / block['membersCount'])), - 'description': 'Actual % Growth (UD(t) / (M(t-1)/Nt))'} - ] - self.table_general.setModel(ParametersModel(general)) - update_table_height(self.table_general, len(general)) - - money = [ - # money params - {'name': 'c', 'value': "{:2.0%}".format(params['c']), - 'description': '% growth'}, - {'name': 'ud0', 'value': params['ud0'], - 'description': 'Initial Universal Dividend in currency units'}, - {'name': 'dt', 'value': params['dt'] / 86400, - 'description': 'Time period in days between two UD'}, - {'name': 'medianTimeBlocks', 'value': params['medianTimeBlocks'], - 'description': 'Number of blocks used for calculating median time'}, - {'name': 'avgGenTime', 'value': params['avgGenTime'], - 'description': 'The average time in seconds for writing 1 block (wished time)'}, - {'name': 'dtDiffEval', 'value': params['dtDiffEval'], - 'description': 'The number of blocks required to evaluate again PoWMin value'}, - {'name': 'blocksRot', 'value': params['blocksRot'], - 'description': 'The number of previous blocks to check for personalized difficulty'}, - {'name': 'percentRot', 'value': "{:2.0%}".format(params['percentRot']), - 'description': 'The percent of previous issuers to reach for personalized difficulty'} - ] - self.table_money.setModel(ParametersModel(money)) - update_table_height(self.table_money, len(money)) - - wot = [ - # wot params - {'name': 'sigDelay', 'value': params['sigDelay'] / 86400, - 'description': 'Minimum delay between 2 identical certifications (in days)'}, - {'name': 'sigValidity', 'value': params['sigValidity'] / 86400, - 'description': 'Maximum age of a valid signature (in days)'}, - {'name': 'sigQty', 'value': params['sigQty'], - 'description': 'Minimum quantity of signatures to be part of the WoT'}, - {'name': 'sigWoT', 'value': params['sigWoT'], - 'description': 'Minimum quantity of valid made certifications to be part of the WoT for distance rule'}, - {'name': 'msValidity', 'value': params['msValidity'] / 86400, - 'description': 'Maximum age of a valid membership (in days)'}, - {'name': 'stepMax', 'value': params['stepMax'], - 'description': 'Maximum distance between each WoT member and a newcomer'}, - ] - self.table_wot.setModel(ParametersModel(wot)) - update_table_height(self.table_wot, len(wot)) - - -def update_table_height(table, rows): - row_height = table.rowHeight(0) - table_height = (rows * row_height) + table.horizontalHeader().height() + (2 * table.frameWidth()) - table.setMinimumHeight(table_height) - table.setMaximumHeight(table_height) + # set infos in label + self.label_general.setText( + """ + <table cellpadding="5"> + <tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:.2f}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:2.2%}</b></td><td>{:}</td></tr> + </table> + """.format( + block['dividend'], + 'Universal Dividend UD(t) in currency units', + block['monetaryMass'], + 'Monetary Mass M(t) in currency units', + block['membersCount'], + 'Members N(t)', + block['monetaryMass'] / block['membersCount'], + 'Monetary Mass per member M(t)/N(t) in currency units', + block['dividend'] / (block['monetaryMass'] - (block['membersCount'] * block['dividend'])) / block[ + 'membersCount'], + 'Actual % Growth (UD(t) / (M(t-1)/Nt))' + ) + ) + + # set infos in label + self.label_money.setText( + """ + <table cellpadding="5"> + <tr><td align="right"><b>{:2.0%}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:2.0%}</b></td><td>{:}</td></tr> + </table> + """.format( + params['c'], + 'Growth (c)', + params['ud0'], + 'Initial Universal Dividend in currency units', + params['dt'] / 86400, + 'Time period in days between two UD', + params['medianTimeBlocks'], + 'Number of blocks used for calculating median time', + params['avgGenTime'], + 'The average time in seconds for writing 1 block (wished time)', + params['dtDiffEval'], + 'The number of blocks required to evaluate again PoWMin value', + params['blocksRot'], + 'The number of previous blocks to check for personalized difficulty', + params['percentRot'], + 'The percent of previous issuers to reach for personalized difficulty' + ) + ) + + # set infos in label + self.label_wot.setText( + """ + <table cellpadding="5"> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + </table> + """.format( + params['sigDelay'] / 86400, + 'Minimum delay between 2 identical certifications (in days)', + params['sigValidity'] / 86400, + 'Maximum age of a valid signature (in days)', + params['sigQty'], + 'Minimum quantity of signatures to be part of the WoT', + params['sigWoT'], + 'Minimum quantity of valid made certifications to be part of the WoT for distance rule', + params['msValidity'] / 86400, + 'Maximum age of a valid membership (in days)', + params['stepMax'], + 'Maximum distance between each WoT member and a newcomer', + ) + ) + + # set infos in label + self.label_rules.setText( + """ + <table cellpadding="5"> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + </table> + """.format( + "{:2.0%} / {:} days".format(params['c'], params['dt'] / 86400), + 'Growth percent (c)', + "UD t+1 = MAX ( UD t ; c * Mt / Nt+1 )", + 'Universal Dividend (formula)', + "UD t+1 = MAX ( {:} {:} ; {:2.0%} * {:} {:} / Nt+1 )".format(params['ud0'], 'units', params['c'], block['monetaryMass'], 'units'), + 'Universal Dividend (computed)' + ) + ) diff --git a/src/cutecoin/models/parameters.py b/src/cutecoin/models/parameters.py deleted file mode 100644 index f97e632e..00000000 --- a/src/cutecoin/models/parameters.py +++ /dev/null @@ -1,107 +0,0 @@ -# -*- coding: utf-8 -*- - -from PyQt5.QtCore import (Qt, QAbstractTableModel, QModelIndex) -from PyQt5.QtGui import QFont, QColor - - -class ParametersModel(QAbstractTableModel): - - def __init__(self, infos=list(), parent=None): - super().__init__(parent) - self.infos = infos - - def rowCount(self, index=QModelIndex()): - """ Returns the number of rows the model holds. """ - return len(self.infos) - - def columnCount(self, index=QModelIndex()): - """ Returns the number of columns the model holds. """ - return 3 - - def data(self, index, role=Qt.DisplayRole): - """ Depending on the index and role given, return data. If not - returning data, return None - """ - if not index.isValid(): - return None - - if not 0 <= index.row() < len(self.infos): - return None - - if role == Qt.DisplayRole: - if index.column() == 0: - return self.infos[index.row()]["name"] - elif index.column() == 1: - return self.infos[index.row()]["value"] - elif index.column() == 2: - return self.infos[index.row()]["description"] - elif role == Qt.TextAlignmentRole and index.column() == 0: - return int(Qt.AlignRight | Qt.AlignVCenter) - elif role == Qt.FontRole and index.column() == 0: - font = QFont() - font.setBold(True) - return font - return None - - def headerData(self, section, orientation, role=Qt.DisplayRole): - """ Set the headers to be displayed. """ - if role != Qt.DisplayRole: - return None - - if orientation == Qt.Horizontal: - if section == 0: - return "Name" - elif section == 1: - return "Value" - - return None - - def insertRows(self, position, rows=1, index=QModelIndex()): - """ Insert a row into the model. """ - self.beginInsertRows(QModelIndex(), position, position + rows - 1) - - for row in range(rows): - self.infos.insert(position + row, {"name": "", "value": ""}) - - self.endInsertRows() - return True - - def removeRows(self, position, rows=1, index=QModelIndex()): - """ Remove a row from the model. """ - self.beginRemoveRows(QModelIndex(), position, position + rows - 1) - - del self.infos[position:position+rows] - - self.endRemoveRows() - return True - - def setData(self, index, value, role=Qt.EditRole): - """ Adjust the data (set it to <value>) depending on the given - index and role. - """ - if role != Qt.EditRole: - return False - - if index.isValid() and 0 <= index.row() < len(self.infos): - info = self.infos[index.row()] - if index.column() == 0: - info["name"] = value - elif index.column() == 1: - info["value"] = value - else: - return False - - self.dataChanged.emit(index, index) - return True - - return False - - def flags(self, index): - """ Set the item flags at the given index. Seems like we're - implementing this function just to see how it's done, as we - manually adjust each tableView to have NoEditTriggers. - """ - if not index.isValid(): - return Qt.ItemIsEnabled | Qt.Item - return Qt.ItemFlags(QAbstractTableModel.flags(self, index)) - -- GitLab