From 839c1934760294bcd11b4154e46ef6d8bffbdcfa Mon Sep 17 00:00:00 2001
From: inso <insomniak.fr@gmail.com>
Date: Mon, 9 Jan 2017 18:59:03 +0100
Subject: [PATCH] Remove unneeded files

---
 src/sakia/app.py                    |   3 +
 src/sakia/data/entities/identity.py |   1 -
 src/sakia/main.py                   |   3 +
 src/sakia/money/__init__.py         |   3 +-
 src/sakia/money/base_referential.py |  16 ++--
 src/sakia/money/dividend_per_day.py | 107 ---------------------
 src/sakia/money/relative.py         |   1 -
 src/sakia/money/relative_to_past.py | 119 ------------------------
 src/sakia/money/udd_to_past.py      | 139 ----------------------------
 9 files changed, 15 insertions(+), 377 deletions(-)
 delete mode 100644 src/sakia/money/dividend_per_day.py
 delete mode 100644 src/sakia/money/relative_to_past.py
 delete mode 100644 src/sakia/money/udd_to_past.py

diff --git a/src/sakia/app.py b/src/sakia/app.py
index 5797ead4..7adcf486 100644
--- a/src/sakia/app.py
+++ b/src/sakia/app.py
@@ -205,3 +205,6 @@ class Application(QObject):
     def change_referential(self, index):
         self.current_ref = Referentials[index]
         self.referential_changed.emit()
+
+    def connection_exists(self):
+        return len(ConnectionsProcessor.instanciate(self).connections()) > 0
diff --git a/src/sakia/data/entities/identity.py b/src/sakia/data/entities/identity.py
index e0bf250f..d070760b 100644
--- a/src/sakia/data/entities/identity.py
+++ b/src/sakia/data/entities/identity.py
@@ -1,7 +1,6 @@
 import attr
 from duniterpy.documents import block_uid, BlockUID
 from duniterpy.documents import Identity as IdentityDoc
-from duniterpy import PROTOCOL_VERSION
 
 
 @attr.s()
diff --git a/src/sakia/main.py b/src/sakia/main.py
index fd6f28ec..c5141cde 100755
--- a/src/sakia/main.py
+++ b/src/sakia/main.py
@@ -91,6 +91,9 @@ if __name__ == '__main__':
 
     with loop:
         app = Application.startup(sys.argv, sakia, loop)
+        if not app.connection_exists():
+            conn_controller = ConnectionConfigController.create(None, app)
+            loop.run_until_complete(conn_controller.async_exec())
         window = MainWindowController.startup(app)
         loop.run_forever()
         try:
diff --git a/src/sakia/money/__init__.py b/src/sakia/money/__init__.py
index dda0375b..05a4b506 100644
--- a/src/sakia/money/__init__.py
+++ b/src/sakia/money/__init__.py
@@ -2,6 +2,5 @@ from .quantitative import Quantitative
 from .relative import Relative
 from .quant_zerosum import QuantitativeZSum
 from .relative_zerosum import RelativeZSum
-from .dividend_per_day import DividendPerDay
 
-Referentials = (Quantitative, Relative, QuantitativeZSum, RelativeZSum, DividendPerDay)
+Referentials = (Quantitative, Relative, QuantitativeZSum, RelativeZSum)
diff --git a/src/sakia/money/base_referential.py b/src/sakia/money/base_referential.py
index 4fd504cd..c4da2710 100644
--- a/src/sakia/money/base_referential.py
+++ b/src/sakia/money/base_referential.py
@@ -23,28 +23,28 @@ class BaseReferential:
 
     @classmethod
     def translated_name(self):
-        pass
+        raise NotImplementedError()
 
     @property
     def units(self):
-        pass
+        raise NotImplementedError()
 
     @property
     def diff_units(self):
-        pass
+        raise NotImplementedError()
 
     def value(self):
-        pass
+        raise NotImplementedError()
 
     def differential(self):
-        pass
+        raise NotImplementedError()
 
     @staticmethod
     def to_si(value, digits):
-        pass
+        raise NotImplementedError()
 
     def localized(self, units=False, international_system=False):
-        pass
+        raise NotImplementedError()
 
     def diff_localized(self, units=False, international_system=False):
-        pass
+        raise NotImplementedError()
diff --git a/src/sakia/money/dividend_per_day.py b/src/sakia/money/dividend_per_day.py
deleted file mode 100644
index 3e2da29a..00000000
--- a/src/sakia/money/dividend_per_day.py
+++ /dev/null
@@ -1,107 +0,0 @@
-from .base_referential import BaseReferential
-from .udd_to_past import UDDToPast
-from .currency import shortened
-from ..data.processors import BlockchainProcessor
-
-from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP, QLocale
-
-
-class DividendPerDay(BaseReferential):
-    _NAME_STR_ = QT_TRANSLATE_NOOP('DividendPerDay', 'UDD')
-    _REF_STR_ = QT_TRANSLATE_NOOP('DividendPerDay', "{0} {1}UDD {2}")
-    _UNITS_STR_ = QT_TRANSLATE_NOOP('DividendPerDay', "UDD {0}")
-    _FORMULA_STR_ = QT_TRANSLATE_NOOP('DividendPerDay',
-                                      """UDD(t) = (Q * 100) / (UD(t) / DT)
-                                        <br >
-                                        <table>
-                                        <tr><td>R</td><td>Dividend per day in percent</td></tr>
-                                        <tr><td>t</td><td>Last UD time</td></tr>
-                                        <tr><td>Q</td><td>Quantitative value</td></tr>
-                                        <tr><td>UD</td><td>Universal Dividend</td></tr>
-                                        <tr><td>DT</td><td>Delay between two UD in days</td></tr>
-                                        </table>"""
-                                      )
-    _DESCRIPTION_STR_ = QT_TRANSLATE_NOOP('DividendPerDay',
-                                          """Universal Dividend per Day displayed in percent.
-                                          The purpose is to have a default unit that is easy to use and understand.
-                                          100 UDD equal the Universal Dividend created per day.
-                                          """.replace('\n', '<br >'))
-
-    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, currency, app, block_number=None):
-        if app.parameters.forgetfulness:
-            return cls(amount, currency, app, block_number)
-        else:
-            return UDDToPast(amount, currency, app, block_number)
-
-    @classmethod
-    def translated_name(cls):
-        return QCoreApplication.translate('DividendPerDay', DividendPerDay._NAME_STR_)
-
-    @property
-    def units(self):
-        return QCoreApplication.translate("DividendPerDay", DividendPerDay._UNITS_STR_).format(shortened(self.currency))
-
-    @property
-    def formula(self):
-        return QCoreApplication.translate('DividendPerDay', DividendPerDay._FORMULA_STR_)
-
-    @property
-    def description(self):
-        return QCoreApplication.translate("DividendPerDay", DividendPerDay._DESCRIPTION_STR_)
-
-    @property
-    def diff_units(self):
-        return self.units
-
-    def value(self):
-        """
-        Return relative value of amount
-
-        value = (Q * 100) / R
-        Q = Quantitative value
-        R = UD(t) of one day
-        t = last UD block time
-
-        :param sakia.core.community.Community community: Community instance
-        :return: float
-        """
-        dividend, base = self._blockchain_processor.last_ud(self.currency)
-        params = self._blockchain_processor.parameters(self.currency)
-        if dividend > 0:
-            return (self.amount * 100) / (float(dividend * (10**base)) / (params.dt / 86400))
-        else:
-            return self.amount
-
-    def differential(self):
-        return self.value()
-
-    def localized(self, units=False, international_system=False):
-        value = self.value()
-        prefix = ""
-        localized_value = QLocale().toString(float(value), 'f', self.app.parameters.digits_after_comma)
-
-        if units or international_system:
-            return QCoreApplication.translate("Relative", DividendPerDay._REF_STR_) \
-                .format(localized_value,
-                        prefix,
-                        shortened(self.currency) if units else "")
-        else:
-            return localized_value
-
-    def diff_localized(self, units=False, international_system=False):
-        value = self.differential()
-        prefix = ""
-        localized_value = QLocale().toString(float(value), 'f', self.app.parameters.digits_after_comma)
-
-        if units or international_system:
-            return QCoreApplication.translate("Relative", DividendPerDay._REF_STR_) \
-                .format(localized_value,
-                        prefix,
-                        shortened(self.currency) if units else "")
-        else:
-            return localized_value
diff --git a/src/sakia/money/relative.py b/src/sakia/money/relative.py
index ddb18de1..648ff427 100644
--- a/src/sakia/money/relative.py
+++ b/src/sakia/money/relative.py
@@ -1,5 +1,4 @@
 from .base_referential import BaseReferential
-from .relative_to_past import RelativeToPast
 from .currency import shortened
 from ..data.processors import BlockchainProcessor
 
diff --git a/src/sakia/money/relative_to_past.py b/src/sakia/money/relative_to_past.py
deleted file mode 100644
index 2062c576..00000000
--- a/src/sakia/money/relative_to_past.py
+++ /dev/null
@@ -1,119 +0,0 @@
-from PyQt5.QtCore import QObject, QCoreApplication, QT_TRANSLATE_NOOP, QLocale, QDateTime
-from .base_referential import BaseReferential
-from .currency import shortened
-from ..data.processors import BlockchainProcessor
-
-
-class RelativeToPast(BaseReferential):
-    _NAME_STR_ = QT_TRANSLATE_NOOP('RelativeToPast', 'Past UD')
-    _REF_STR_ = QT_TRANSLATE_NOOP('RelativeToPast', "{0} {1}UD({2}) {3}")
-    _UNITS_STR_ = QT_TRANSLATE_NOOP('RelativeToPast', "UD({0}) {1}")
-    _FORMULA_STR_ = QT_TRANSLATE_NOOP('RelativeToPast',
-                                      """R = Q / UD(t)
-                                        <br >
-                                        <table>
-                                        <tr><td>R</td><td>Relative value</td></tr>
-                                        <tr><td>Q</td><td>Quantitative value</td></tr>
-                                        <tr><td>UD</td><td>Universal Dividend</td></tr>
-                                        <tr><td>t</td><td>Time when the value appeared</td></tr>
-                                        </table>"""
-                                      )
-    _DESCRIPTION_STR_ = QT_TRANSLATE_NOOP('RelativeToPast',
-                                          """Relative referential using UD at the Time when the value appeared.
-                                          Relative value R is calculated by dividing the quantitative value Q by the
-                                           Universal Dividend UD at the Time when the value appeared.
-                                          All past UD created are displayed with a value of 1 UD.
-                                          This referential is practical to remember what was the value at the Time.
-                                          """.replace('\n', '<br >'))
-
-    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 translated_name(cls):
-        return QCoreApplication.translate('RelativeToPast', RelativeToPast._NAME_STR_)
-
-    @property
-    def units(self):
-        return QCoreApplication.translate("RelativeToPast", RelativeToPast._UNITS_STR_).format('t',
-                                                                                               shortened(self.currency))
-    @property
-    def formula(self):
-        return QCoreApplication.translate('RelativeToPast', RelativeToPast._FORMULA_STR_)
-
-    @property
-    def description(self):
-        return QCoreApplication.translate("RelativeToPast", RelativeToPast._DESCRIPTION_STR_)
-
-    @property
-    def diff_units(self):
-        return self.units
-
-    def value(self):
-        """
-        Return relative to past value of amount
-        :return: float
-        """
-        dividend = self.community.dividend()
-        if dividend > 0:
-            return self.amount / float(dividend)
-        else:
-            return self.amount
-
-    def differential(self):
-        """
-        Return relative to past differential value of amount
-        :return: float
-        """
-        dividend = self.community.dividend(self._block_number)
-        if dividend > 0:
-            return self.amount / float(dividend)
-        else:
-            return self.amount
-
-    def localized(self, units=False, international_system=False):
-        from . import Relative
-        value = self.value()
-        last_ud_time = self._blockchain_processor.last_ud_time(self.currency)
-        prefix = ""
-        if international_system:
-            localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
-        else:
-            localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
-
-        if units or international_system:
-            return QCoreApplication.translate("RelativeToPast", RelativeToPast._REF_STR_) \
-                .format(localized_value,
-                        prefix,
-                        QLocale.toString(
-                            QLocale(),
-                            QDateTime.fromTime_t(last_ud_time).date(),
-                            QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
-                        ),
-                        shortened(self.currency) if units else "")
-        else:
-            return localized_value
-
-    def diff_localized(self, units=False, international_system=False):
-        from . import Relative
-        value = self.differential()
-        block = self.community.get_ud_block(0, self._block_number)
-        prefix = ""
-        if international_system and value != 0:
-            localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
-        else:
-            localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
-
-        if units or international_system:
-            return QCoreApplication.translate("RelativeToPast", RelativeToPast._REF_STR_)\
-                .format(localized_value,
-                    prefix,
-                    QLocale.toString(
-                        QLocale(),
-                        QDateTime.fromTime_t(block['medianTime']).date(),
-                        QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
-                    ),
-                    shortened(self.currency) if units else "")
-        else:
-            return localized_value
diff --git a/src/sakia/money/udd_to_past.py b/src/sakia/money/udd_to_past.py
deleted file mode 100644
index 4c71afff..00000000
--- a/src/sakia/money/udd_to_past.py
+++ /dev/null
@@ -1,139 +0,0 @@
-from PyQt5.QtCore import QObject, QCoreApplication, QT_TRANSLATE_NOOP, QLocale, QDateTime
-from .base_referential import BaseReferential
-from .currency import shortened
-from ..data.processors import BlockchainProcessor
-
-
-class UDDToPast(BaseReferential):
-    _NAME_STR_ = QT_TRANSLATE_NOOP('UDDToPast', 'Past UUD')
-    _REF_STR_ = QT_TRANSLATE_NOOP('UDDToPast', "{0} {1}UUD({2}) {3}")
-    _UNITS_STR_ = QT_TRANSLATE_NOOP('UDDToPast', "UUD({0}) {1}")
-    _FORMULA_STR_ = QT_TRANSLATE_NOOP('UDDToPast',
-                                      """R = Q / UD(t)
-                                        <br >
-                                        <table>
-                                        <tr><td>R</td><td>Dividend per day in percent</td></tr>
-                                        <tr><td>t</td><td>Last UD time</td></tr>
-                                        <tr><td>Q</td><td>Quantitative value</td></tr>
-                                        <tr><td>UD</td><td>Universal Dividend</td></tr>
-                                        <tr><td>t</td><td>Time when the value appeared</td></tr>
-                                        <tr><td>DT</td><td>Delay between two UD in days</td></tr>
-                                        </table>>"""
-                                      )
-    _DESCRIPTION_STR_ = QT_TRANSLATE_NOOP('UDDToPast',
-                                          """Universal Dividend per Day displayed in percent, using UD at the Time
-                                          when the value appeared.
-                                          The purpose is to have a default unit that is easy to use and understand.
-                                          100 UDD equal the Universal Dividend created per day.
-                                          Relative referential
-                                          Relative value R is calculated by dividing the quantitative value Q by the
-                                          """.replace('\n', '<br >'))
-
-    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 translated_name(cls):
-        return QCoreApplication.translate('UDDToPast', UDDToPast._NAME_STR_)
-
-    @property
-    def units(self):
-        return QCoreApplication.translate("UDDToPast", UDDToPast._UNITS_STR_).format('t', self.community.short_currency)
-    @property
-    def formula(self):
-        return QCoreApplication.translate('UDDToPast', UDDToPast._FORMULA_STR_)
-
-    @property
-    def description(self):
-        return QCoreApplication.translate("UDDToPast", UDDToPast._DESCRIPTION_STR_)
-
-    @property
-    def diff_units(self):
-        return self.units
-
-    def value(self):
-        """
-        Return relative value of amount
-
-        value = (Q * 100) / R
-        Q = Quantitative value
-        R = UD(t) of one day
-        t = last UD block time
-
-        :param int amount:   Value
-        :param sakia.core.community.Community community: Community instance
-        :return: float
-        """
-        dividend = self.community.dividend()
-        params = self.community.parameters()
-        if dividend > 0:
-            return (self.amount * 100) / (float(dividend) / (params['dt'] / 86400))
-        else:
-            return self.amount
-
-    def differential(self):
-        """
-        Return relative value of amount
-
-        value = (Q * 100) / R
-        Q = Quantitative value
-        R = UD(t) of one day
-        t = UD block time of when the value was created
-
-        :param int amount:   Value
-        :param sakia.core.community.Community community: Community instance
-        :return: float
-        """
-        dividend = self.community.dividend(self._block_number)
-        params = self.community.parameters()
-        if dividend > 0:
-            return (self.amount * 100) / (float(dividend) / (params['dt'] / 86400))
-        else:
-            return self.amount
-
-    def localized(self, units=False, international_system=False):
-        from . import Relative
-        value = self.value()
-        block = self.community.get_block()
-        prefix = ""
-        if international_system:
-            localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
-        else:
-            localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
-
-        if units or international_system:
-            return QCoreApplication.translate("UDDToPast", UDDToPast._REF_STR_) \
-                .format(localized_value,
-                        prefix,
-                        QLocale.toString(
-                            QLocale(),
-                            QDateTime.fromTime_t(block['medianTime']).date(),
-                            QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
-                        ),
-                        self.community.short_currency if units else "")
-        else:
-            return localized_value
-
-    def diff_localized(self, units=False, international_system=False):
-        from . import Relative
-        value = self.differential()
-        block = self.community.get_block(self._block_number)
-        prefix = ""
-        if international_system and value != 0:
-            localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
-        else:
-            localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
-
-        if units or international_system:
-            return QCoreApplication.translate("UDDToPast", UDDToPast._REF_STR_)\
-                .format(localized_value,
-                    prefix,
-                    QLocale.toString(
-                        QLocale(),
-                        QDateTime.fromTime_t(block['medianTime']).date(),
-                        QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
-                    ),
-                    self.community.short_currency if units else "")
-        else:
-            return localized_value
-- 
GitLab