electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit dbf0a6f7a5ed58f13b21232887c4026ed3a58930
parent 375885deb32bfeb351213e1a9ea28d9aa1bae8c3
Author: ThomasV <thomasv@electrum.org>
Date:   Sat, 17 Dec 2016 17:06:25 +0100

move plot plugin to lib; plot histograms

Diffstat:
Mgui/qt/main_window.py | 17++++++++++++++++-
Alib/plot.py | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -402,7 +402,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.import_privkey_menu = self.private_keys_menu.addAction(_("&Import"), self.do_import_privkey) self.export_menu = self.private_keys_menu.addAction(_("&Export"), self.export_privkeys_dialog) self.import_address_menu = wallet_menu.addAction(_("Import addresses"), self.import_addresses) - wallet_menu.addAction(_("&Export History"), self.export_history_dialog) + + hist_menu = wallet_menu.addMenu(_("&History")) + hist_menu.addAction("Plot", self.plot_history_dialog) + hist_menu.addAction("Export", self.export_history_dialog) + wallet_menu.addAction(_("Find"), self.toggle_search).setShortcut(QKeySequence("Ctrl+F")) wallet_menu.addAction(_("Addresses"), self.toggle_addresses_tab).setShortcut(QKeySequence("Ctrl+A")) @@ -2100,6 +2104,17 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): return self.show_message(_("Your wallet history has been successfully exported.")) + def plot_history_dialog(self): + try: + from electrum.plot import plot_history + except: + return + wallet = self.wallet + history = wallet.get_history() + if len(history) > 0: + plt = plot_history(self.wallet, history) + plt.show() + def do_export_history(self, wallet, fileName, is_csv): history = wallet.get_history() diff --git a/lib/plot.py b/lib/plot.py @@ -0,0 +1,58 @@ +from PyQt4.QtGui import * +from electrum.i18n import _ + + +import datetime +from collections import defaultdict + +from electrum.util import format_satoshis +from electrum.bitcoin import COIN + +import matplotlib +matplotlib.use('Qt4Agg') +import matplotlib.pyplot as plt +import matplotlib.dates as md +from matplotlib.patches import Ellipse +from matplotlib.offsetbox import AnchoredOffsetbox, TextArea, DrawingArea, HPacker + + +def plot_history(wallet, history): + hist_in = defaultdict(int) + hist_out = defaultdict(int) + for item in history: + tx_hash, height, confirmations, timestamp, value, balance = item + if not confirmations: + continue + if timestamp is None: + continue + value = value*1./COIN + date = datetime.datetime.fromtimestamp(timestamp) + datenum = int(md.date2num(datetime.date(date.year, date.month, 1))) + if value > 0: + hist_in[datenum] += value + else: + hist_out[datenum] -= value + + f, axarr = plt.subplots(2, sharex=True) + plt.subplots_adjust(bottom=0.2) + plt.xticks( rotation=25 ) + ax=plt.gca() + + plt.ylabel('BTC') + plt.xlabel('Dates') + xfmt = md.DateFormatter('%Y-%m-%d') + ax.xaxis.set_major_formatter(xfmt) + + axarr[0].set_title('History Transactions') + + xfmt = md.DateFormatter('%Y-%m') + ax.xaxis.set_major_formatter(xfmt) + width = 20 + dates, values = zip(*sorted(hist_in.items())) + r1 = axarr[0].bar(dates, values, width, label='incoming') + axarr[0].legend(loc='upper left') + dates, values = zip(*sorted(hist_out.items())) + r2 = axarr[1].bar(dates, values, width, color='r', label='outgoing') + 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) + return plt