Commit a34aaa3d authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Use pandas.DatetimeIndex.

parent 9521891e
......@@ -6,9 +6,8 @@ import matplotlib
import re
from datetime import datetime
from gluon import current
from pandas import DataFrame
from pandas import DataFrame, DatetimeIndex
from reporting_tools import repr_team_project
from regex import REG_SUBMITTED
from StringIO import StringIO
......@@ -97,12 +96,12 @@ def do_linechart(publications, selector):
if selector.cumulative:
df = df.cumsum()
# polish the label for the time axis (YYYY-MM)
cvt = get_time_converter(selector.year_start, selector.year_end)
df.index = [cvt(el) for el in df.index]
# convert the index into a Datetime index
df.index = DatetimeIndex(df.index)
# instantiate the plot
ax = df.plot(legend=False)
# x_compat is required to have a nice x axis labelling in all cases
ax = df.plot(legend=False, x_compat=True)
do_labels(ax, "", T(TITLE_Y))
do_tick(ax)
......@@ -210,14 +209,15 @@ def do_stackedchart(publications, selector, graph):
if selector.cumulative:
df = df.cumsum()
# polish the label for the time axis (YYYY-MM)
cvt = get_time_converter(selector.year_start, selector.year_end)
df.index = [cvt(el) for el in df.index]
# convert the index into a Datetime index
df.index = DatetimeIndex(df.index)
# instantiate the plot
# x_compat is required to have a nice x axis labelling in all cases
ax = df.plot(colormap="Pastel1",
kind="area",
stacked=True)
stacked=True,
x_compat=True)
do_labels(ax, "", T(TITLE_Y))
do_tick(ax)
......@@ -266,25 +266,6 @@ def do_title(ax, db, selector):
ax.set_title(title.decode("utf-8"))
def get_time_converter(year_start, year_end):
"""Return the function to compute the time value.
Args:
year_start (str): year defining the begining of the period.
year_end (str): year defining the end of the period.
Returns:
reference to a function: the argument of the function is the
submitted date.
"""
if year_start and not year_end:
return lambda s: datetime.strptime(s[:7], "%Y-%m").strftime("%b")
else:
return lambda s: datetime.strptime(s[:7], "%Y-%m").strftime("%b %y")
def mathplotlib_backend_server():
"""Setup the backend for mathplotlib when running on a server.
......
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