diff --git a/src/calibre/trac/donations/server.py b/src/calibre/trac/donations/server.py
index a251206df7..2472524e95 100644
--- a/src/calibre/trac/donations/server.py
+++ b/src/calibre/trac/donations/server.py
@@ -184,13 +184,27 @@ def expose(func):
class Server(object):
TRENDS = '/tmp/donations_trend.png'
+ MONTH_TRENDS = '/tmp/donations_month_trend.png'
def __init__(self, apache=False, root='/', data_file='/tmp/donations.xml'):
self.apache = apache
self.document_root = root
self.data_file = data_file
self.read_records()
-
+
+ def calculate_month_trend(self, days=31):
+ stats = self.get_slice(date.today()-timedelta(days=days-1), date.today())
+ fig = plt.figure(2, (8, 3), 96)#, facecolor, edgecolor, frameon, FigureClass)
+ ax = fig.add_subplot(111)
+ x = list(range(days-1, -1, -1))
+ y = stats.daily_totals
+ ax.plot(x, y)#, align='center', width=20, color='g')
+ ax.set_xlabel('Day')
+ ax.set_ylabel('Income ($)')
+ ax.hlines([stats.daily_average], 0, days-1)
+ ax.set_xlim([0, days-1])
+ fig.savefig(self.MONTH_TRENDS)
+
def calculate_trend(self):
def months(start, end):
pos = range_for_month(start.year, start.month)[0]
@@ -208,7 +222,7 @@ class Server(object):
x = [m.min for m in _months]
y = [m.total for m in _months]
ml = mdates.MonthLocator() # every month
- fig = plt.figure(None, (8, 3), 96)#, facecolor, edgecolor, frameon, FigureClass)
+ fig = plt.figure(1, (8, 3), 96)#, facecolor, edgecolor, frameon, FigureClass)
ax = fig.add_subplot(111)
ax.bar(x, y, align='center', width=20, color='g')
ax.xaxis.set_major_locator(ml)
@@ -235,6 +249,7 @@ class Server(object):
max_date = max(max_date, d)
self.earliest, self.latest = min_date, max_date
self.calculate_trend()
+ self.calculate_month_trend()
def get_slice(self, start_date, end_date):
stats = Stats([r for r in self.records if r.date >= start_date and r.date <= end_date],
@@ -299,6 +314,8 @@ class Server(object):
else:
range_stats = self.get_slice(*range_stats).to_html(num_of_countries=10)
+ today = self.get_slice(date.today(), date.today())
+
return textwrap.dedent('''\
@@ -420,6 +437,7 @@ class Server(object):
+ Donations today: $%(today).2f
%(range_stats)s
@@ -428,6 +446,8 @@ class Server(object):