From 374182e4bf9f5945c232535333d1e310c2e24bc6 Mon Sep 17 00:00:00 2001 From: waheebyaqub Date: Sat, 27 Sep 2014 16:56:26 +0400 Subject: [PATCH 1/5] Update setup.py plugin name added --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 454c7770..080d32b7 100644 --- a/setup.py +++ b/setup.py @@ -133,6 +133,8 @@ setup( 'electrum_plugins.labels', 'electrum_plugins.trezor', 'electrum_plugins.virtualkeyboard', + 'electrum_plugins.plot', + ], description="Lightweight Bitcoin Wallet", author="Thomas Voegtlin", From 2045043212a00a02ed0406280a2e30bf9cb621a8 Mon Sep 17 00:00:00 2001 From: waheebyaqub Date: Sat, 27 Sep 2014 16:59:23 +0400 Subject: [PATCH 2/5] Update main_window.py --- gui/qt/main_window.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 9be2a7ad..11f05ea1 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -2382,6 +2382,10 @@ class ElectrumWindow(QMainWindow): h, b = ok_cancel_buttons2(d, _('Export')) vbox.addLayout(h) + + run_hook('export_history_dialog', self,hbox) + self.update() + if not d.exec_(): return From 8e3e2fc1f6b6e5060129bf6c97ad707cfd31e97e Mon Sep 17 00:00:00 2001 From: waheebyaqub Date: Sat, 27 Sep 2014 17:02:00 +0400 Subject: [PATCH 3/5] Create plot.py --- plugins/plot.py | 145 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 plugins/plot.py diff --git a/plugins/plot.py b/plugins/plot.py new file mode 100644 index 00000000..ceb17503 --- /dev/null +++ b/plugins/plot.py @@ -0,0 +1,145 @@ +from PyQt4.QtGui import * +from electrum.plugins import BasePlugin, hook +from electrum.i18n import _ + + +import datetime +from electrum.util import format_satoshis + + +import matplotlib.pyplot as plt +import matplotlib.dates as md + +from matplotlib.patches import Ellipse +from matplotlib.offsetbox import AnchoredOffsetbox, TextArea, DrawingArea, HPacker + + +class Plugin(BasePlugin): + + + def fullname(self): + return 'Plot History' + + def description(self): + return '%s\n%s' % (_("Ability to plot transaction history in graphical mode."), _("Warning: Requires matplotlib library.")) + + @hook + def init_qt(self, gui): + self.win = gui.main_window + + @hook + def export_history_dialog(self, d,hbox): + self.wallet = d.wallet + + history = self.wallet.get_tx_history() + + if len(history) > 0: + b = QPushButton(_("Preview plot")) + hbox.addWidget(b) + b.clicked.connect(lambda: self.do_plot(self.wallet)) + else: + b = QPushButton(_("No history to plot")) + hbox.addWidget(b) + + + + def do_plot(self,wallet): + history = wallet.get_tx_history() + balance_Val=[] + fee_val=[] + value_val=[] + datenums=[] + unknown_trans=0 + pending_trans=0 + counter_trans=0 + for item in history: + tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item + if confirmations: + if timestamp is not None: + try: + datenums.append(md.date2num(datetime.datetime.fromtimestamp(timestamp))) + except [RuntimeError, TypeError, NameError] as reason: + unknown_trans=unknown_trans+1 + pass + else: + unknown_trans=unknown_trans+1 + else: + pending_trans=pending_trans+1 + + if value is not None: + value_string = format_satoshis(value, True) + else: + value_string = '--' + + if fee is not None: + fee_string = format_satoshis(fee, True) + else: + fee_string = '0' + + if tx_hash: + label, is_default_label = wallet.get_label(tx_hash) + label = label.encode('utf-8') + else: + label = "" + + balance_string = format_satoshis(balance, False) + balance_Val.append(float((format_satoshis(balance,False)))*1000.0) + print "fee",fee_string + fee_val.append(float(fee_string)) + value_val.append(float(value_string)*1000.0) + + + + + + f, axarr = plt.subplots(2, sharex=True) + + plt.subplots_adjust(bottom=0.2) + plt.xticks( rotation=25 ) + ax=plt.gca() + x=19 + test11="Unknown transactions = "+str(unknown_trans)+" Pending transactions = "+str(pending_trans)+" ." + box1 = TextArea(" Test : Number of pending transactions", textprops=dict(color="k")) + box1.set_text(test11) + print test11 + + + + box = HPacker(children=[box1], + align="center", + pad=0.1, sep=15) + + anchored_box = AnchoredOffsetbox(loc=3, + child=box, pad=0.5, + frameon=True, + bbox_to_anchor=(0.5, 1.02), + bbox_transform=ax.transAxes, + borderpad=0.5, + ) + + + ax.add_artist(anchored_box) + + + plt.ylabel('mBTC') + plt.xlabel('Dates') + xfmt = md.DateFormatter('%Y-%m-%d') + ax.xaxis.set_major_formatter(xfmt) + + + axarr[0].plot(datenums,balance_Val,marker='o',linestyle='-',color='blue',label='Balance') + axarr[0].legend(loc='upper left') + axarr[0].set_title('History Transactions') + + + xfmt = md.DateFormatter('%Y-%m-%d') + ax.xaxis.set_major_formatter(xfmt) + axarr[1].plot(datenums,fee_val,marker='o',linestyle='-',color='red',label='Fee') + axarr[1].plot(datenums,value_val,marker='o',linestyle='-',color='green',label='Value') + + + + + axarr[1].legend(loc='upper left') + # plt.annotate('unknown transaction = %d \n pending transactions = %d' %(unknown_trans,pending_trans),xy=(0.7,0.05),xycoords='axes fraction',size=12) + plt.show() From 7cff7e31d59e81df2d141d9767bca63f5f0d6da5 Mon Sep 17 00:00:00 2001 From: waheebyaqub Date: Sat, 27 Sep 2014 17:05:17 +0400 Subject: [PATCH 4/5] Update plot.py --- plugins/plot.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/plot.py b/plugins/plot.py index ceb17503..81740263 100644 --- a/plugins/plot.py +++ b/plugins/plot.py @@ -84,7 +84,6 @@ class Plugin(BasePlugin): balance_string = format_satoshis(balance, False) balance_Val.append(float((format_satoshis(balance,False)))*1000.0) - print "fee",fee_string fee_val.append(float(fee_string)) value_val.append(float(value_string)*1000.0) @@ -101,7 +100,6 @@ class Plugin(BasePlugin): test11="Unknown transactions = "+str(unknown_trans)+" Pending transactions = "+str(pending_trans)+" ." box1 = TextArea(" Test : Number of pending transactions", textprops=dict(color="k")) box1.set_text(test11) - print test11 From fb7136227bd1bd2385516fb2a4e4be1987aade31 Mon Sep 17 00:00:00 2001 From: waheebyaqub Date: Sun, 28 Sep 2014 18:20:33 +0400 Subject: [PATCH 5/5] Update plot.py --- plugins/plot.py | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/plugins/plot.py b/plugins/plot.py index 81740263..450a7369 100644 --- a/plugins/plot.py +++ b/plugins/plot.py @@ -7,11 +7,17 @@ import datetime from electrum.util import format_satoshis -import matplotlib.pyplot as plt -import matplotlib.dates as md +try: + import matplotlib.pyplot as plt + import matplotlib.dates as md + from matplotlib.patches import Ellipse + from matplotlib.offsetbox import AnchoredOffsetbox, TextArea, DrawingArea, HPacker + flag_matlib=True +except: + flag_matlib=False + + -from matplotlib.patches import Ellipse -from matplotlib.offsetbox import AnchoredOffsetbox, TextArea, DrawingArea, HPacker class Plugin(BasePlugin): @@ -23,6 +29,21 @@ class Plugin(BasePlugin): def description(self): return '%s\n%s' % (_("Ability to plot transaction history in graphical mode."), _("Warning: Requires matplotlib library.")) + def is_available(self): + if flag_matlib: + return True + else: + return False + + + + def is_enabled(self): + if not self.is_available(): + return False + else: + return True + + @hook def init_qt(self, gui): self.win = gui.main_window @@ -58,6 +79,8 @@ class Plugin(BasePlugin): if timestamp is not None: try: datenums.append(md.date2num(datetime.datetime.fromtimestamp(timestamp))) + balance_string = format_satoshis(balance, False) + balance_Val.append(float((format_satoshis(balance,False)))*1000.0) except [RuntimeError, TypeError, NameError] as reason: unknown_trans=unknown_trans+1 pass @@ -68,11 +91,13 @@ class Plugin(BasePlugin): if value is not None: value_string = format_satoshis(value, True) + value_val.append(float(value_string)*1000.0) else: value_string = '--' if fee is not None: fee_string = format_satoshis(fee, True) + fee_val.append(float(fee_string)) else: fee_string = '0' @@ -82,14 +107,6 @@ class Plugin(BasePlugin): else: label = "" - balance_string = format_satoshis(balance, False) - balance_Val.append(float((format_satoshis(balance,False)))*1000.0) - fee_val.append(float(fee_string)) - value_val.append(float(value_string)*1000.0) - - - - f, axarr = plt.subplots(2, sharex=True) @@ -102,7 +119,6 @@ class Plugin(BasePlugin): box1.set_text(test11) - box = HPacker(children=[box1], align="center", pad=0.1, sep=15)