Commit 37ed2840 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Refactor graphs. They are handled as metrics (new table graphs, controller graphs/index, ...)

parent 11fc9ab3
......@@ -30,6 +30,41 @@ def dashboard():
redirect(URL('graphs', 'linechart', vars=selector))
def index():
"""Render the selected graph.
"""
vars = Storage()
selector = Selector(virtdb.graph_selector)
# get the graph data
graph = db.graphs[selector.id_graphs]
# stacked chart
if graph.stack_axis:
vars.Stackedchart_selectorCumulative = selector.cumulative
vars.Stackedchart_selectorId = ''
vars.Stackedchart_selectorId_projects = selector.id_projects
vars.Stackedchart_selectorId_teams = selector.id_teams
vars.Stackedchart_selectorYear_start = selector.year_start
vars.Stackedchart_selectorYear_end = selector.year_end
vars.Stackedchart_selectorStack_axis = graph.stack_axis
vars.Stackedchart_selectorStack_granularity = graph.stack_granularity
redirect(URL('graphs', 'stackedchart', vars=vars))
# line char
else:
vars.Linechart_selectorCumulative = selector.cumulative
vars.Linechart_selectorId = ''
vars.Linechart_selectorId_projects = selector.id_projects
vars.Linechart_selectorId_teams = selector.id_teams
vars.Linechart_selectorYear_start = selector.year_start
vars.Linechart_selectorYear_end = selector.year_end
redirect(URL('graphs', 'linechart', vars=vars))
def linechart():
"""show the cumulative distribution of the number of publications
as a function of the months. It can be build for the institute,
......@@ -95,24 +130,23 @@ def linechart():
def stackedchart():
"""show the cumulative distribution of publications as a function
"""show the distribution of publications as a function
of the month. It is displayed as a stacked chart showing for example
what happen per team or scientific domains.
"""
# get the user constraint.
# exclude the fields related to year and series from the query
# exclude the fields related to year and to the stack
selector = Selector(virtdb.stackedchart_selector,
exclude_fields=('cumulative',
'year_start',
'year_end',
'serie_axis',
'serie_granularity'))
'stack_axis',
'stack_granularity'))
# protection -- a serie has to be selected
if not selector.serie_axis:
return INLINE_ALERT % (T("Error"), T("Please select a serie..."))
# protection -- a stack has to be selected
if not selector.stack_axis:
return INLINE_ALERT % (T("Error"), T("Please select a stack..."))
# query directive to count publications including
# foreign key constraints and user requirements
......@@ -127,25 +161,25 @@ def stackedchart():
q_end = db.publications.submitted[0:4] <= selector.year_end
query = (query) & ((q_start) & (q_end))
# 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 stack field
# publications will be count as a function of the stack values
stack_field = db[selector.stack_axis][selector.stack_granularity]
# the value for the series legend (only active items)
# 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
# the value for the legend (only active items)
# dictionary, properly initialise, to count publications per stack value
stack_keys, stack_dict = [], {}
for row in db(query).select(stack_field, distinct=True, orderby=stack_field):
stack_keys.append(row[selector.stack_granularity])
stack_dict[row[selector.stack_granularity]] = 0
# group per year, per month and per serie
# group per year, per month and per stack value
group_by = [db.publications.submitted[:4],
db.publications.submitted[5:7],
serie_field]
stack_field]
count = db.publications.id.count()
rows = db(query).select(db.publications.submitted,
serie_field,
stack_field,
count,
groupby=group_by,
orderby=group_by)
......@@ -155,7 +189,7 @@ def stackedchart():
cfg.fields.append({'name': 'submitted', 'type': 'string'})
for key in series_keys:
for key in stack_keys:
cfg.fields.append({'name': key, 'type': 'int'})
current = None
......@@ -170,24 +204,24 @@ def stackedchart():
if submitted[:7] != current:
current = submitted[:7]
di = dict(**series_dict)
di = dict(**stack_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]
stack = row[selector.stack_axis][selector.stack_granularity]
cfg.data[-1][stack] = row[count]
# cumulative distribution
if selector.cumulative:
for serie in series_keys:
for stack in stack_keys:
sum = 0
for i in range(len(cfg.data)):
sum += cfg.data[i][serie]
cfg.data[i][serie] = sum
sum += cfg.data[i][stack]
cfg.data[i][stack] = sum
# delegate rendering to the view
return dict(cfg_store=json.dumps(cfg),
team_project=repr_team_project(db, selector),
selector=selector,
series_keys=series_keys)
stack_keys=stack_keys)
......@@ -131,9 +131,9 @@
'Conference town is not defined': "La ville de la conférence n'est pas défine",
'Conference_Url': 'URL de la Conférence',
'Configuration': 'Configuration',
'Configure graphs and metrics': 'Configurer les graphes et les métriques',
'Configure harvesters': 'Configurer les moissonneurs',
'Configure lists': 'Configurer les listes',
'Configure metrics': 'Configurer les métriques',
'Configure rapports': 'Configurer les rapports',
'Configure the application': "Configurer l'application",
'contains': 'contiens',
......@@ -226,6 +226,7 @@
'Filter collaborations': 'Filtrer les collaborations',
'Filter countries': 'Filtrer les pays',
'Filter diplomas': 'Filtrer les diplomes',
'Filter graphs': 'Filter les graphes',
'Filter harvesters': 'Filtrer les moissonneurs',
'Filter lists': 'Filtrer les listes',
'Filter metrics': 'Filtrer les métriques',
......@@ -257,7 +258,8 @@
'Granularity Level 4': 'Granularity Level 4',
'Granularity Row': 'Granularity Row',
'Granularity Vertical': 'Granularity Vertical',
'graphs': 'graphs',
'Graph': 'Graphe',
'graphs': 'graphes',
'Grids': 'Tables',
'Group': 'Groupe',
'Group %(group_id)s created': 'Group %(group_id)s created',
......@@ -411,7 +413,7 @@
'please input your password again': 'please input your password again',
'Please select a list....': 'Sélectionner une liste....',
'Please select a metric....': 'Sélectionnez une métrique....',
'Please select a serie...': 'sélectionnez une série...',
'Please select a stack...': 'Sélectionnez un empilement...',
'Please, define sections for the list "%s"': 'définissez des sections pour la liste "%s"',
'plugin not install': 'plugin not install',
'Position': 'Position',
......@@ -558,7 +560,12 @@
'Sort Field': 'Trier par',
'Sort the publications list associated to the section according to the database field. The field has to belong to the table publications. The publications of this section will be sort according to this field': 'Ordonne les publications de la sections en fonction de ce champ. Il doit appartenir à la table "publications".',
'Speaker': 'Orateur',
'Stack': 'Empilement',
'Stack Axis': 'Stack Axis',
'Stack Granularity': 'Stack Granularity',
'Stacked Axis': 'Stacked Axis',
'stacked chart': 'stacked chart',
'Stacked Granularity': 'Stacked Granularity',
'state': 'state',
'Statistics': 'Statistique',
'Status': 'Status',
......@@ -590,6 +597,7 @@
'Temps': 'Temps',
'The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.': 'The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.',
'The field "%s" is missing ...': 'Le champ "%s" est manquant ...',
'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. ',
'The identifier of the record in the invenio store': 'The identifier of the record in the invenio store',
'The institute authors contains the team name?': "Le champ, autheurs du laboratoire, contiens le nom de l'équipe ?",
'The name of the first author: J. Doe': 'Nom du premier auteur : J. Doe',
......
......@@ -97,6 +97,7 @@ tables = ['application',
'controllers',
'countries',
'harvesters',
'graphs',
'lists',
'metrics',
'my_authors',
......
# -*- coding: utf-8 -*-
""" graphs
"""
tp_stacked = \
T("The graph can be rendered as line or stacked chart. "
"The latter is used when the stacked fields are defined. ")
db.define_table("graphs",
Field("graph", "string", length=255, notnull=True),
Field("definition", "text", default=""),
Field('stack_axis', 'string', length=255, comment=tp_stacked),
Field('stack_granularity', 'string', length=255),
migrate="graphs.table")
db.graphs.graph.filter_in = dbui.CLEAN_SPACES
# -*- coding: utf-8 -*-
""" graphs
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('graphs')
fieldsModifier.configure_field('definition', height=100)
fieldsModifier.configure_field('stack_axis', flex=1)
fieldsModifier.configure_field('stack_granularity', flex=1)
fieldsModifier.merge_fields('stack_axis', 'stack_granularity', fieldLabel=T('Stack'))
fieldsModifier.configure_field('stack_axis',
itemId='stack_axis',
displayField='AxesTr_axis',
valueField='AxesAxis',
refStore=dbui.get_store_id('axes'),
emptyText=T('Select axis...'),
userReset=True,
xtype='xcomboboxmaster')
fieldsModifier.configure_field('stack_granularity',
masterItemId='stack_axis',
masterValueField='AxesAxis',
displayField='AxesTr_granularity',
valueField='AxesGranularity',
refStore=dbui.get_store_id('axes'),
emptyText=T('Select granularity...'),
xtype='xcomboboxslave')
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
gridModifier = dbui.GridModifier('graphs')
gridModifier.configure_column('graph', width=90)
gridModifier.configure_column('definition', width=250)
gridModifier.hide_columns('stack_axis',
'stack_granularity')
gridModifier.append_filter(('graph', 'contains', T('contains')))
gridModifier.configure_filters(plugins=['pFormToolTip'], width=300)
gridModifier.configure_gridWithFilter(selectorTitle= T('Filter'))
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
storeModifier = dbui.StoreModifier('graphs')
storeModifier.orderby(db.graphs.graph)
# -*- coding: utf-8 -*-
""" graph_selector (virtual table)
"""
#-------------------------------------------------------------------------------
#
# DEFINITION
#
#-------------------------------------------------------------------------------
virtdb.define_table('graph_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_graphs', 'reference graphs', label='Graph'),
Field('cumulative', 'boolean', default=True))
virtdb.graph_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.graph_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
virtdb.graph_selector.id_graphs.requires = IS_IN_DB(db, 'graphs.graph')
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('graph_selector')
fieldsModifier.configure_field('year_start', flex=1)
fieldsModifier.configure_field('year_end', flex=1)
fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Year'))
fieldsModifier.configure_field('id_graphs', selectFirst=True)
fieldsModifier.configure_field('id_projects', emptyText=T('select...'), xtype='xcomboboxuserreset')
fieldsModifier.configure_field('id_teams', emptyText=T('select...'), xtype='xcomboboxuserreset')
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
......@@ -12,8 +12,8 @@ virtdb.define_table('stackedchart_selector',
Field('year_end', 'integer'),
Field('id_teams', 'reference teams', label='Team'),
Field('id_projects', 'reference projects', label='Project'),
Field('serie_axis', 'string'),
Field('serie_granularity', 'string'),
Field('stack_axis', 'string'),
Field('stack_granularity', 'string'),
Field('cumulative', 'boolean', default=True))
virtdb.stackedchart_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
......@@ -30,15 +30,15 @@ fieldsModifier.configure_field('year_start', flex=1)
fieldsModifier.configure_field('year_end', flex=1)
fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Year'))
fieldsModifier.configure_field('serie_axis', flex=1)
fieldsModifier.configure_field('serie_granularity', flex=1)
fieldsModifier.merge_fields('serie_axis', 'serie_granularity', fieldLabel=T('Serie'))
fieldsModifier.configure_field('stack_axis', flex=1)
fieldsModifier.configure_field('stack_granularity', flex=1)
fieldsModifier.merge_fields('stack_axis', 'stack_granularity', fieldLabel=T('Stack'))
fieldsModifier.configure_field('id_projects', emptyText=T('select...'), xtype='xcomboboxuserreset')
fieldsModifier.configure_field('id_teams', emptyText=T('select...'), xtype='xcomboboxuserreset')
fieldsModifier.configure_field('serie_axis',
itemId='serie_axis',
fieldsModifier.configure_field('stack_axis',
itemId='stack_axis',
displayField='AxesTr_axis',
valueField='AxesAxis',
refStore=dbui.get_store_id('axes'),
......@@ -46,8 +46,8 @@ fieldsModifier.configure_field('serie_axis',
userReset=True,
xtype='xcomboboxmaster')
fieldsModifier.configure_field('serie_granularity',
masterItemId='serie_axis',
fieldsModifier.configure_field('stack_granularity',
masterItemId='stack_axis',
masterValueField='AxesAxis',
displayField='AxesTr_granularity',
valueField='AxesGranularity',
......
......@@ -73,7 +73,8 @@ if session.role == ADMIN:
confMetricNode = None
if session.role == ADMIN:
confMetricNode = Node(T('Configure metrics'))
confMetricNode = Node(T('Configure graphs and metrics'))
confMetricNode.add_child(T('graphs'), to_grid('graphs'))
confMetricNode.add_child(T('metrics'), to_grid('metrics'))
#-------------------------------------------------------------------------------
......@@ -156,28 +157,23 @@ dashBoardLeaf = Panel(loader=loader,
plugins=['pPanelLoaderException'],
autoScroll=True)
graphLeaf = PanelWithUrlSelector(virtdb.graph_selector,
baseUrl=URL('graphs', 'index'))
listLeaf = PanelWithUrlSelector(virtdb.list_selector,
baseUrl=URL('lists', 'index'),
extField='format',
plugins=['pMathJax'])
lineChartLeaf = PanelWithUrlSelector(virtdb.linechart_selector,
baseUrl=URL('graphs', 'linechart'))
metricLeaf = PanelWithUrlSelector(virtdb.metric_selector,
baseUrl=URL('metrics', 'index'),
extField='format')
stackedChartLeaf = PanelWithUrlSelector(virtdb.stackedchart_selector,
baseUrl=URL('graphs', 'stackedchart'))
reportNode = Node(T('Reports'))
reportNode.add_child(T('dashboard'), dashBoardLeaf)
reportNode.add_child(T('lists'), listLeaf)
reportNode.add_child(T('metrics'), metricLeaf)
reportNode.add_child(T('line chart'), lineChartLeaf)
reportNode.add_child(T('stacked chart'), stackedChartLeaf)
reportNode.add_child(T('graphs'), graphLeaf)
#-------------------------------------------------------------------------------
#
......
......@@ -5,7 +5,7 @@
# - cfg_store, the configuration of the Ext.data.Array
# - team_project string
# - selector object
# - series_keys
# - stack_keys
#
# prepare the data
# - build unique DIV identifier
......@@ -39,7 +39,7 @@
"chart",
"divchart = '%s'" % divchart,
"series",
"seriesKeys = %s" % json.dumps(series_keys)]
"seriesKeys = %s" % json.dumps(stack_keys)]
jsvars = " var %s;" % ',\n'.join(jsvars)
response.write(SCRIPT(jsvars), escape=False)
......
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