Commit 5e1de7ec authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the empty plot.

parent b2f8503c
......@@ -7,7 +7,7 @@ import re
from gluon import current
from pandas import DataFrame, DatetimeIndex
from pandas import DataFrame, DatetimeIndex, to_datetime
from reporting_tools import repr_team_project
from regex import REG_SUBMITTED
from StringIO import StringIO
......@@ -19,6 +19,46 @@ TITLE_CUMSUM = "Cumulative sum of publications"
TITLE_Y = "Number of publications"
def do_empty(db, selector):
"""Empty graph as a function of month.
Args:
db (gluon.DAL): database connection
selector (plugin_dbui.Selector): selector with user critera
Returns:
ax (matplotlib.AxesSubplot): axes subplot
"""
T = current.T
year_start = selector.year_start
year_end = selector.year_end
if year_start and not year_end:
nyear = 1
year = int(year_start)
months = to_datetime(["%i-%02i" % (year, i) for i in xrange(1, 13)])
else:
year_start = int(year_start)
year_end = int(year_end)
nyear = year_end - year_start + 1
li = []
for year in xrange(int(year_start), int(year_end)+1):
li.extend(["%i-%02i" % (year, i) for i in xrange(1, 13)])
months = to_datetime(li)
df = DataFrame([0]*12*nyear, index=months)
ax = df.plot(legend=False, x_compat=True, ylim=(0, 100))
do_labels(ax, '', T(TITLE_Y))
do_tick(ax)
do_title(ax, db, selector)
return ax
def do_labels(ax, xlabel, ylabel):
"""Deal with axes label.
......@@ -73,11 +113,15 @@ def do_linechart(publications, selector):
# they are grouped per year and and per month
group_by = [publications.submitted[:4], publications.submitted[5:7]]
setrows = db(query)
if setrows.count() == 0:
return do_empty(db, selector)
count = publications.id.count()
rows = db(query).select(publications.submitted,
count,
groupby=group_by,
orderby=group_by)
rows = setrows.select(publications.submitted,
count,
groupby=group_by,
orderby=group_by)
# build the dataframe
# the index of the DataSerie is the time (month, ...)
......@@ -174,12 +218,16 @@ def do_stackedchart(publications, selector, graph):
publications.submitted[5:7],
stackedfield]
setrows = db(query)
if setrows.count() == 0:
return do_empty(db, selector)
count = publications.id.count()
rows = db(query).select(publications.submitted,
stackedfield,
count,
groupby=group_by,
orderby=group_by)
rows = setrows.select(publications.submitted,
stackedfield,
count,
groupby=group_by,
orderby=group_by)
# build the dataframe
data = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment