Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

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

Graph as a function of submission date or publication date.

parent 6c8c1ef2
......@@ -13,6 +13,7 @@ from graph_tools import (FROM_TO,
linechart,
savefig,
stackchart)
from model_selector import YEAR_SUBMIT
def dashboard():
......@@ -42,7 +43,7 @@ def dashboard():
max_year = str(current_year - 1)
selector.Graph_selectorCumulative = "false"
selector.Graph_selectorTime = T("year")
selector.Graph_selectorTime = T(YEAR_SUBMIT)
selector.Graph_selectorYear_start = min_year
selector.Graph_selectorYear_end = max_year
......@@ -59,7 +60,7 @@ def dashboard():
# the cumulative sum of publications for the current year on a month
year = str(current_year)
selector.Graph_selectorCumulative = "true"
selector.Graph_selectorTime = T("month")
selector.Graph_selectorTime = T(YEAR_SUBMIT)
selector.Graph_selectorYear_start = year
selector.Graph_selectorYear_end = ""
......
......@@ -330,6 +330,7 @@
'Invalid email': 'Invalid email',
'invalid expression': 'expression non conforme',
'Invalid expression': 'Expression non conforme',
'Invalid host': 'Invalid host',
'Invalid keyword argument': 'Invalid keyword argument',
'Invalid list of record identifiers': "La liste des identifiants n'est pas valide",
'Invalid login': 'Invalid login',
......@@ -396,6 +397,7 @@
'Modified On': 'Modified On',
'Modify': 'Modifier',
'month': 'mois',
'month of submission': 'mois de soumission',
'More than one affiliation for the selected author!': "Plus d'une affiliation pour l'auteur sélectionné !",
'my_authors': 'autheurs du laboratoire',
'mémoire': 'mémoire',
......@@ -500,6 +502,7 @@
'présentation orale': 'présentation orale',
'Publication': 'Publication',
'Publication category associated to the found records.': 'Catégorie associée aux enregistrements.',
'Publication date': 'Date de publication',
'Publication not found!': "La publication n'a pas été trouvé !",
'publications': 'publications',
'Publications': 'Publications',
......@@ -677,6 +680,7 @@
'The <i>record id</i> is not well formed.': 'Le <i>record id</i> est mal formé.',
'The category is used twice !': 'La catégorie est utilisée deux fois !',
'The field "%s" is missing ...': 'Le champ "%s" est manquant ...',
"The field '%s' is missing ...": "The field '%s' is missing ...",
'The generation of the ODT file failed:<br><br>': 'La génération du fichier ODT a échoué :<br><br>',
'The generation of the PDF file failed.<br>Please, check the LaTeX file.': 'La génération du fichier PDF a échoué.<br>Vérifier le fichier LaTeX...',
'The graph can be rendered as line or stacked chart. The latter is used when the stacked fields are defined. ': 'The graph can be rendered as line or stacked chart. The latter is used when the stacked fields are defined. ',
......@@ -768,6 +772,8 @@
'year': 'année',
'Year': 'Année',
'Year End': 'Année de fin',
'year of publication': 'année de publication',
'year of submission': 'année de soumission',
'Year of the publication': 'Année de la publication',
'Year Start': 'Année de début',
'You can not delete the row containing the undefined value.': 'Vous ne pouvez pas détruire la ligne contenant la valeur "indéfini".',
......
......@@ -7,6 +7,7 @@ import pandas as pd
from gluon import current
from model_selector import MONTH_SUBMIT, YEAR_SUBMIT, YEAR_PUBLISH
from pandas import DataFrame, DatetimeIndex, to_datetime
from StringIO import StringIO
......@@ -169,14 +170,18 @@ def linechart(db, selector, target=None, title=None, xlabel=None, ylabel=None):
# variables depending on the time axis
#
time_axis = selector.Graph_selectorTime
is_month = time_axis == T("month")
to_time = (submitted2YM if is_month else submitted2Y)
is_submit_month = time_axis == T(MONTH_SUBMIT)
is_publish_year = time_axis == T(YEAR_PUBLISH)
to_time = (submitted2YM if is_submit_month else submitted2Y)
to_time = (published2Y if is_publish_year else to_time)
# ........................................................................
#
# instantiate the DataFrame
#
query = query_publications(db, **selector)
query = query_publications(db, is_publish_year, **selector)
fields = [
publications.year,
......@@ -208,7 +213,7 @@ def linechart(db, selector, target=None, title=None, xlabel=None, ylabel=None):
#
mpl.rcParams['legend.fontsize'] = 10
if is_month:
if is_submit_month:
df.index = DatetimeIndex(df.index)
if df.size == 1:
......@@ -231,18 +236,19 @@ def linechart(db, selector, target=None, title=None, xlabel=None, ylabel=None):
# x label
if xlabel is None:
xlabel = T(DATE_SUB).decode("utf-8")
xlabel = T(DATE_PUB if is_publish_year else DATE_SUB).decode("utf-8")
ax.set_xlabel(xlabel, x=1, horizontalalignment="right")
# y label
if ylabel is None:
if is_cumsum and is_month:
if is_cumsum and is_submit_month:
ylabel = LABELY_CUM_MONTH
elif is_cumsum:
ylabel = LABELY_CUM_YEAR
elif is_month:
elif is_submit_month:
ylabel = LABELY_MONTH
else:
ylabel = LABELY_YEAR
......@@ -260,7 +266,7 @@ def linechart(db, selector, target=None, title=None, xlabel=None, ylabel=None):
return ax
def query_publications(db, **kwargs):
def query_publications(db, is_publish, **kwargs):
"""Construct the query to select publications according to user criteria,
team, project, year, etc. The operator AND is applied between conditions.
......@@ -268,6 +274,7 @@ def query_publications(db, **kwargs):
Args:
db (gluon.dal.DAL): database connection.
is_publish (bool): select using either published year or submitted one.
Keyword Args:
Graph_selectorAuthor (str):
......@@ -293,16 +300,29 @@ def query_publications(db, **kwargs):
year_end = di["Graph_selectorYear_end"]
year_start = di["Graph_selectorYear_start"]
if year_start and not year_end:
query = publications.submitted[0:4] == year_start
if is_publish:
if year_start and not year_end:
query = publications.year == int(year_start)
elif year_start and year_end:
q_start = publications.submitted[0:4] >= year_start
q_end = publications.submitted[0:4] <= year_end
query = ((q_start) & (q_end))
elif year_start and year_end:
q_start = publications.year >= int(year_start)
q_end = publications.year <= int(year_end)
query = ((q_start) & (q_end))
elif year_end and not year_start:
query = publications.submitted[0:4] <= year_end
elif year_end and not year_start:
query = publications.year <= int(year_end)
else:
if year_start and not year_end:
query = publications.submitted[0:4] == year_start
elif year_start and year_end:
q_start = publications.submitted[0:4] >= year_start
q_end = publications.submitted[0:4] <= year_end
query = ((q_start) & (q_end))
elif year_end and not year_start:
query = publications.submitted[0:4] <= year_end
for k, v in di.iteritems():
......@@ -426,14 +446,18 @@ def stackchart(db, selector, target=None):
# variables depending on the time axis
#
time_axis = selector.Graph_selectorTime
is_month = time_axis == T("month")
to_time = (submitted2YM if is_month else submitted2Y)
is_submit_month = time_axis == T(MONTH_SUBMIT)
is_publish_year = time_axis == T(YEAR_PUBLISH)
to_time = (submitted2YM if is_submit_month else submitted2Y)
to_time = (published2Y if is_publish_year else to_time)
# ........................................................................
#
# instantiate the DataFrame
#
query = query_publications(db, **selector)
query = query_publications(db, is_publish_year, **selector)
# link to the axis table
axis = graph.stack_axis
......@@ -474,12 +498,13 @@ def stackchart(db, selector, target=None):
mpl.rcParams['legend.fontsize'] = 10
kwargs = {}
if is_month:
if is_submit_month:
df.index = DatetimeIndex(df.index)
kwargs = dict(kind="area", x_compat=True)
else:
kwargs = dict(kind="bar", linewidth=0, rot=15, width=1.)
rot = (0 if df.index.size == 1 else 15)
kwargs = dict(kind="bar", linewidth=0, rot=rot, width=1.)
ax = df.plot(colormap="Pastel1",
grid=True,
......@@ -494,17 +519,17 @@ def stackchart(db, selector, target=None):
ax.tick_params(which="minor", length=4)
# x and y labels
xlabel = T(DATE_SUB).decode("utf-8")
xlabel = T(DATE_PUB if is_publish_year else DATE_SUB).decode("utf-8")
ax.set_xlabel(xlabel, x=1, horizontalalignment="right")
# y label
if is_cumsum and is_month:
if is_cumsum and is_submit_month:
ylabel = LABELY_CUM_MONTH
elif is_cumsum:
ylabel = LABELY_CUM_YEAR
elif is_month:
elif is_submit_month:
ylabel = LABELY_MONTH
else:
ylabel = LABELY_YEAR
......@@ -546,3 +571,15 @@ def submitted2Y(df):
"""
return df.submitted.str[0:4]
def published2Y(df):
"""
Args:
df (pandas.DataFrame): contains the column ``published``.
Returns:
str: YYYY
"""
return df.published.astype(str)
......@@ -19,6 +19,10 @@ FORMATS = ["bib", "html", "odt", "pdf", "tex"]
MODE_CHANGE_STATUS = "change status"
MODE_LOAD_IN_DB = "load in the database"
MONTH_SUBMIT = "month of submission"
YEAR_PUBLISH = "year of publication"
YEAR_SUBMIT = "year of submission"
class Selector(object):
"""Create virtual tables used to generate selector interfaces.
......@@ -220,6 +224,7 @@ class Selector(object):
"""
year = current.request.now.year
month_submit = T(MONTH_SUBMIT)
table = virtdb.define_table(
"graph_selector",
......@@ -232,7 +237,7 @@ class Selector(object):
Field("id_authors_roles", "reference authors_roles", label="Role"),
Field("id_graphs", "reference graphs", label="Graph"),
Field("cumulative", "boolean", default=True),
Field("time", "string", default=T("month")),
Field("time", "string", default=month_submit),
Field("format", "string", default="html", label="Format"))
table.id_authors_roles.requires = IS_IN_DB(db, "authors_roles.role")
......@@ -242,7 +247,9 @@ class Selector(object):
table.id_teams.requires = IS_IN_DB(db, "teams.team")
table.format.requires = IS_IN_SET(["html", "pdf", "png"])
table.time.requires = IS_IN_SET([T("month"), T("year")])
table.time.requires = \
IS_IN_SET([month_submit, T(YEAR_SUBMIT), T(YEAR_PUBLISH)])
return table
......
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