Commit 397bdb0e authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '72-author-in-metrics-graphs' into 'master'

72 author in metrics graphs

* Add the `author` criteria in `metrics` and `graphs` selector.
* Close #72 

See merge request !70
parents 3a9980e7 7f6095e6
......@@ -77,7 +77,7 @@ def index():
either as a linechart or as a stacked histograms.
"""
fields = ('cumulative','id_graphs', 'time', 'year_start','year_end')
fields = ('author', 'cumulative','id_graphs', 'time', 'year_start','year_end')
selector = Selector(virtdb.graph_selector, exclude_fields=fields)
# graph configuration
......
......@@ -15,13 +15,13 @@ def index():
"""Main Controller handling metrics.
"""
publications = db.publications
# get the user constraint.
# the selector fields year_start, year_end, id_lists are excluded
# from the selector query.
selector = Selector(virtdb.metric_selector,
exclude_fields=('year_start',
'year_end',
'id_metrics'))
tpl = ('author', 'year_start', 'year_end', 'id_metrics')
selector = Selector(virtdb.metric_selector, exclude_fields=tpl)
# protection
if not selector.id_metrics:
......@@ -46,19 +46,23 @@ def index():
# query directive to count publications including
# foreign key constraints and user requirements
# related to team, project and year
query = selector.query(db.publications)
query = selector.query(publications)
if metric.conditions:
q_conditions = smart_query(db.publications, metric.conditions)
query = (query) & (q_conditions)
q_conditions = smart_query(publications, metric.conditions)
query &= q_conditions
if selector.year_start and not selector.year_end:
query = (query) & (db.publications.year == selector.year_start)
query &= (publications.year == selector.year_start)
elif selector.year_start and selector.year_end:
q_start = db.publications.year >= selector.year_start
q_end = db.publications.year <= selector.year_end
query = (query) & ((q_start) & (q_end))
q_start = publications.year >= selector.year_start
q_end = publications.year <= selector.year_end
query &= ((q_start) & (q_end))
if selector.author:
q_author = publications.authors_institute.contains(selector.author)
query &= q_author
# get the label along the x and y axis
labels = {}
......@@ -89,7 +93,7 @@ def index():
# fill the data block of the Ext.data.Array.Store
# transform (x, y count) data point into a row of values
# sum the content of the row
count = db.publications.id.count()
count = publications.id.count()
rows = db(query).select(fields['vertical'],
fields['horizontal'],
count,
......
......@@ -13,6 +13,7 @@ virtdb.define_table('graph_selector',
Field('id_teams', 'reference teams', label='Team'),
Field('id_projects', 'reference projects', label='Project'),
Field('id_categories', 'reference categories', label='Category'),
Field('author', 'string'),
Field('id_authors_roles', 'reference authors_roles', label='Role'),
Field('id_graphs', 'reference graphs', label='Graph'),
Field('cumulative', 'boolean', default=True),
......
......@@ -13,6 +13,7 @@ virtdb.define_table('metric_selector',
Field('id_teams', 'reference teams', label='Team'),
Field('id_projects', 'reference projects', label='Project'),
Field('id_categories', 'reference categories', label='Category'),
Field('author', 'string'),
Field('id_authors_roles', 'reference authors_roles', label='Role'),
Field('id_metrics', 'reference metrics', label='Metric'))
......
......@@ -230,6 +230,10 @@ def do_query(publications, selector):
elif year_end and not year_start:
query &= publications.submitted[0:4] <= year_end
if selector.author:
q_author = publications.authors_institute.contains(selector.author)
query &= q_author
return query
......
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