Skip to content

Commit

Permalink
Merge pull request JoinMarket-Org#174 from adlai/logscale [yapf]
Browse files Browse the repository at this point in the history
add ?scale=log to /ordersize
  • Loading branch information
chris-belcher committed Aug 7, 2015
2 parents 21fe08c + 9693c97 commit 92df9ed
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ob-watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,30 @@ def create_depth_chart(db, cj_amount):
return get_graph_html(fig)


def create_size_histogram(db):
def create_size_histogram(db, args):
try:
import matplotlib.pyplot as plt
except ImportError:
return 'Install matplotlib to see graphs'
rows = db.execute('SELECT maxsize FROM orderbook;').fetchall()
ordersizes = [r['maxsize'] / 1e8 for r in rows]
ordersizes = sorted([r['maxsize'] / 1e8 for r in rows])

fig = plt.figure()
plt.hist(ordersizes, 30, histtype='bar', rwidth=0.8)
scale = args.get("scale")
if (scale is not None) and (scale[0] == "log"):
ratio = ordersizes[-1] / ordersizes[0]
step = ratio ** 0.0333 # 1/30
bins = [ordersizes[0] * (step ** i) for i in range(30)]
else:
bins = 30
plt.hist(ordersizes, bins, histtype='bar', rwidth=0.8)
if bins is not 30:
fig.axes[0].set_xscale('log')
plt.grid()
#plt.title('Order size distribution')
plt.xlabel('Order sizes / btc')
plt.ylabel('Frequency')
return get_graph_html(fig)
return get_graph_html(fig) + ("<br/><a href='?scale=log'>log scale</a>" if
bins == 30 else "<br/><a href='?'>linear</a>")


def get_graph_html(fig):
Expand Down Expand Up @@ -184,7 +193,7 @@ def do_GET(self):
'PAGETITLE': 'JoinMarket Browser Interface',
'MAINHEADING': 'Order Sizes',
'SECONDHEADING': 'Order Size Histogram' + alert_msg,
'MAINBODY': create_size_histogram(self.taker.db)
'MAINBODY': create_size_histogram(self.taker.db, args)
}
elif self.path.startswith('/depth'):
#if self.path[6] == '?':
Expand Down

0 comments on commit 92df9ed

Please sign in to comment.