Commit 606fe04a authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the cumulative flag to the dashboad and stacked chart reports.

parent ff472a85
......@@ -15,13 +15,15 @@ INLINE_ALERT = "<script>Ext.Msg.alert('%s', '%s');</script>"
def dashboard():
"""show the cumulative distribution of the number of publications
as a function of the months. It can be build for the institure,
as a function of the months. It can be build for the institute,
for a team or for a project.
"""
# get the user constraint.
selector = Selector(virtdb.dashboard_selector,
exclude_fields=('year_start', 'year_end'))
exclude_fields=('cumulative',
'year_start',
'year_end'))
# query directive to count publications including
# foreign key constraints and user requirements
......@@ -36,7 +38,6 @@ def dashboard():
q_end = db.publications.submitted[0:4] <= selector.year_end
query = (query) & ((q_start) & (q_end))
# count the number of publications
# they are grouped per year and and per month
group_by = [db.publications.submitted[:4], db.publications.submitted[5:7]]
......@@ -64,12 +65,13 @@ def dashboard():
cfg.data.append([month_year, row[count]])
# cumulative distribution
sum = 0
for i in range(len(cfg.data)):
sum += cfg.data[i][1]
cfg.data[i][1] = sum
if selector.cumulative:
sum = 0
for i in range(len(cfg.data)):
sum += cfg.data[i][1]
cfg.data[i][1] = sum
# move to the view
# delegate rendering to the view
return dict(cfg_store=json.dumps(cfg),
team_project=repr_team_project(db, selector),
selector=selector)
......@@ -85,7 +87,8 @@ def stackedchart():
# get the user constraint.
# exclude the fields related to year and series from the query
selector = Selector(virtdb.stackedchart_selector,
exclude_fields=('year_start',
exclude_fields=('cumulative',
'year_start',
'year_end',
'serie_axis',
'serie_granularity'))
......@@ -107,14 +110,16 @@ def stackedchart():
q_end = db.publications.submitted[0:4] <= selector.year_end
query = (query) & ((q_start) & (q_end))
# the serie field and reference dictionary
# the serie field
# publications will be count as a function of the serie field values
serie_field = db[selector.serie_axis][selector.serie_granularity]
# the value for the series legend (only active items)
series = {}
for row in db(query).select(serie_field, distinct=True):
series[row[selector.serie_granularity]] = 0
# dictionary properly initialise, to count publications for each serie
series_keys, series_dict = [], {}
for row in db(query).select(serie_field, distinct=True, orderby=serie_field):
series_keys.append(row[selector.serie_granularity])
series_dict[row[selector.serie_granularity]] = 0
# group per year, per month and per serie
group_by = [db.publications.submitted[:4],
......@@ -128,12 +133,12 @@ def stackedchart():
groupby=group_by,
orderby=group_by)
# configure the Ext.data.JsonStore
# build the Ext.data.JsonStore
cfg = Storage(fields=[], data=[])
cfg.fields.append({'name': 'submitted', 'type': 'string'})
for key in series.iterkeys():
for key in series_keys:
cfg.fields.append({'name': key, 'type': 'int'})
current = None
......@@ -144,25 +149,28 @@ def stackedchart():
if len(submitted) == 4:
continue
# initialise the new row for the store
if submitted[:7] != current:
current = submitted[:7]
di = dict(**series)
di = dict(**series_dict)
di['submitted'] = datetime.strptime(submitted[:7], "%Y-%m").strftime("%b %y")
cfg.data.append(di)
# fill the current row
serie = row[selector.serie_axis][selector.serie_granularity]
cfg.data[-1][serie] = row[count]
# cumulative distribution
for serie in series.iterkeys():
sum = 0
for i in range(len(cfg.data)):
sum += cfg.data[i][serie]
cfg.data[i][serie] = sum
if selector.cumulative:
for serie in series_keys:
sum = 0
for i in range(len(cfg.data)):
sum += cfg.data[i][serie]
cfg.data[i][serie] = sum
# delegate rendering to the view
return dict(cfg_store=json.dumps(cfg),
team_project=repr_team_project(db, selector),
selector=selector,
series=series.keys())
series_keys=series_keys)
......@@ -151,6 +151,7 @@
'CPPM': 'CPPM',
'Created By': 'Created By',
'Created On': 'Created On',
'Cumulative': 'Cumulé',
'dashboard': 'tableau de bord',
'Data base scheme': 'Schéma base de donnée',
'Data institute': 'Les données du laboratoire',
......
......@@ -11,7 +11,8 @@ virtdb.define_table('dashboard_selector',
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
Field('id_teams', 'reference teams', label='Team'),
Field('id_projects', 'reference projects', label='Project'))
Field('id_projects', 'reference projects', label='Project'),
Field('cumulative', 'boolean'))
virtdb.dashboard_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.dashboard_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
......@@ -22,6 +23,7 @@ virtdb.dashboard_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('dashboard_selector')
fieldsModifier.configure_field('cumulative', checked=True)
fieldsModifier.configure_field('year_start', flex=1)
fieldsModifier.configure_field('year_end', flex=1)
fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Year'))
......
......@@ -13,7 +13,8 @@ virtdb.define_table('stackedchart_selector',
Field('id_teams', 'reference teams', label='Team'),
Field('id_projects', 'reference projects', label='Project'),
Field('serie_axis', 'string'),
Field('serie_granularity', 'string'))
Field('serie_granularity', 'string'),
Field('cumulative', 'boolean', default=True))
virtdb.stackedchart_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.stackedchart_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
......@@ -24,6 +25,7 @@ virtdb.stackedchart_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('stackedchart_selector')
fieldsModifier.configure_field('cumulative', checked=True)
fieldsModifier.configure_field('year_start', flex=1)
fieldsModifier.configure_field('year_end', flex=1)
fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Year'))
......
......@@ -20,7 +20,11 @@
#
# The title and the DIV block for the Ext.grid.Panel
#
title = "%s %s" % (T("Sum of publications"), team_project)
if selector.cumulative:
title = "%s %s" % (T("Sum of publications"), team_project)
else:
title = "%s %s" % (T("Publications"), team_project)
pass
response.write(H2(title, _class="dbui-h2 dbui-small-cap"))
response.write(DIV(_id=divchart, _style="padding-left: 12px;"))
......
......@@ -5,7 +5,7 @@
# - cfg_store, the configuration of the Ext.data.Array
# - team_project string
# - selector object
# - series
# - series_keys
#
# prepare the data
# - build unique DIV identifier
......@@ -22,16 +22,15 @@
#
# The title and the DIV block for the Ext.grid.Panel
#
title = "%s %s" % (T("Sum of publications"), team_project)
if selector.cumulative:
title = "%s %s" % (T("Sum of publications"), team_project)
else:
title = "%s %s" % (T("Publications"), team_project)
pass
response.write(H2(title, _class="dbui-h2 dbui-small-cap"))
response.write(DIV(_id=divchart, _style="padding-left: 12px;"))
#
# time axis boundaries
#
year_min = selector.year_start
year_max = (selector.year_end if selector.year_end else selector.year_start)
#
# Export python variables to the javascript
#
......@@ -40,9 +39,7 @@
"chart",
"divchart = '%s'" % divchart,
"series",
"seriesFields = %s" % json.dumps(series),
"yearMin = %s" % year_min,
"yearMax = %s" % year_max]
"seriesKeys = %s" % json.dumps(series_keys)]
jsvars = " var %s;" % ',\n'.join(jsvars)
response.write(SCRIPT(jsvars), escape=False)
......@@ -53,7 +50,7 @@
// the axes publications versus month
axes = [{
type: 'Numeric',
fields: seriesFields,
fields: seriesKeys,
grid: true,
minimum: 0,
minorTickSteps: 1,
......@@ -77,7 +74,7 @@
opacity: 0.8
},
xField: 'submitted',
yField: seriesFields
yField: seriesKeys
}];
// instantiate the chart
......
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