Commit 91b375cd authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the dashboard report(s).

parent feea3b86
# -*- coding: utf-8 -*-
""" Controllers for building graphs
"""
import json
from gluon.storage import Storage
from plugin_dbui import Selector
from reporting_tools import repr_team_project
def dashboard():
"""show the cumulative distribution of the number of publications
as a function of the months. It can be build for the institure,
for a team or for a project.
"""
# get the user constraint.
# exclude the fields related to year and series from the query
selector = Selector(virtdb.graph_selector,
exclude_fields=('year_start',
'year_end',
'serie_axis',
'serie_granularity'))
# query directive to count publications including
# foreign key constraints and user requirements
# related to team, project and year
query = selector.query(db.publications)
if selector.year_start and not selector.year_end:
query = (query) & (db.publications.submitted[0:4] == selector.year_start)
elif selector.year_start and selector.year_end:
q_start = db.publications.submitted[0:4] >= selector.year_start
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]]
count = db.publications.id.count()
rows = db(query).select(db.publications.submitted,
count,
groupby=group_by,
orderby=group_by)
# build the Ext.data.ArrayStore
cfg = Storage(fields=[], data=[])
cfg.fields.append({'name': 'submitted', 'type': 'date', 'dateFormat': 'Y-m-d'})
cfg.fields.append({'name': 'publications', 'type': 'int'})
for row in rows:
# protection -- ignore publication with invalid submitted date
submitted = row.publications.submitted
if len(submitted) == 4:
continue
# centre the bin to the middle of the month
cfg.data.append(["%s-15" % submitted[:7], row[count]])
# cumulative distribution
sum = 0
for i in range(len(cfg.data)):
sum += cfg.data[i][1]
cfg.data[i][1] = sum
# move to the view
return dict(cfg_store=json.dumps(cfg),
team_project=repr_team_project(db, selector),
selector=selector)
def index():
"""the main controller to build graph
"""
# get the user constraint.
# exclude the fields related to year and series from the query
selector = Selector(virtdb.graph_selector,
exclude_fields=('year_start',
'year_end',
'serie_axis',
'serie_granularity'))
# query directive to count publications including
# foreign key constraints and user requirements
# related to team, project and year
query = selector.query(db.publications)
if selector.year_start and not selector.year_end:
query = (query) & (db.publications.submitted[0:4] == selector.year_start)
elif selector.year_start and selector.year_end:
q_start = db.publications.submitted[0:4] >= selector.year_start
q_end = db.publications.submitted[0:4] <= selector.year_end
query = (query) & ((q_start) & (q_end))
# group by directive per year and month and serie
group_by = [db.publications.submitted[:4], db.publications.submitted[5:7]]
serie = None
if selector.serie_axis:
serie = db[selector.serie_axis][selector.serie_granularity]
group_by.append(serie)
#----
# print selector.serie_axis, "<>", selector.serie_granularity
# foo = (db.publications.submitted[:4],
# db.publications.submitted[5:7],
# db[selector.serie_axis][selector.serie_granularity])
#
# count = db.publications.id.count()
# rows = db(query).select(db.publications.submitted,
# db[selector.serie_axis][selector.serie_granularity],
# count,
# groupby=foo,
# orderby=foo)
#
# for el in rows:
# print el
#----
count = db.publications.id.count()
rows = db(query).select(db.publications.submitted,
count,
groupby=group_by,
orderby=group_by)
# configure the Ext.data.ArrayStore
cfg = Storage(fields=[], data=[])
cfg.fields.append({'name': 'submitted', 'type': 'date', 'dateFormat': 'Y-m-d'})
cfg.fields.append({'name': 'publications', 'type': 'int'})
for row in rows:
# protection -- ignore publication with invalid submitted date
submitted = row.publications.submitted
if len(submitted) == 4:
continue
# centre the bin to the middle of the month
cfg.data.append(["%s-15" % submitted[:7], row[count]])
# cumulative distribution
sum = 0
for i in range(len(cfg.data)):
sum += cfg.data[i][1]
cfg.data[i][1] = sum
return dict(cfg_store=json.dumps(cfg),
team_project=repr_team_project(db, selector),
selector=selector)
......@@ -151,6 +151,7 @@
'CPPM': 'CPPM',
'Created By': 'Created By',
'Created On': 'Created On',
'dashboard': 'tableau de bord',
'Data base scheme': 'Schéma base de donnée',
'Data institute': 'Les données du laboratoire',
'Data publications': 'Les données des publications',
......@@ -255,6 +256,7 @@
'Granularity Level 4': 'Granularity Level 4',
'Granularity Row': 'Granularity Row',
'Granularity Vertical': 'Granularity Vertical',
'graphs': 'graphs',
'Grids': 'Tables',
'Group': 'Groupe',
'Group %(group_id)s created': 'Group %(group_id)s created',
......@@ -324,6 +326,7 @@
'Load in the database': 'Chargé dans la base de données',
'Loading failed': 'Echec du chargement',
'Loading...': 'Chargement en cours...',
'Log In': 'Log In',
'Logged in': 'Logged in',
'Logged out': 'Logged out',
'Login': 'Login',
......@@ -538,8 +541,12 @@
'Select granularity...': 'Sélect. granularité...',
'select...': 'sélectionner...',
'selected': 'sélectionnez',
'Serie': 'Serie',
'Serie Axis': 'Serie Axis',
'Serie Granularity': 'Serie Granularity',
'Service': 'Service',
'Several publications refer to it.': 'Several publications refer to it.',
'Sign Up': 'Sign Up',
'Software versions': 'Version des logiciels',
'Sort by': 'Trier par',
'Sort field': 'Trier par',
......@@ -559,6 +566,7 @@
'Submitted date is not valid': "La date de soumission n'est pas valide",
'Substitute': 'Substitution',
'substitution mechanism: {tablename.fieldname} or {foreigntablename.fieldname}': 'régle de substitution : {tablename.fieldname} or {foreigntablename.fieldname}',
'Sum of publications': 'Somme des publications',
'Summary per collections': 'Résumé par collection',
'Sélectionner une "catégorie" !!!': 'Sélectionner une "catégorie" !!!',
'table': 'table',
......
# -*- coding: utf-8 -*-
""" dashboard_selector (virtual table)
"""
#-------------------------------------------------------------------------------
#
# DEFINITION
#
#-------------------------------------------------------------------------------
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'))
virtdb.dashboard_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.dashboard_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('dashboard_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_projects', emptyText=T('select...'), xtype='xcomboboxuserreset')
fieldsModifier.configure_field('id_teams', emptyText=T('select...'), xtype='xcomboboxuserreset')
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
# -*- 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('serie_axis', 'string'),
Field('serie_granularity', 'string'))
virtdb.graph_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.graph_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
#-------------------------------------------------------------------------------
#
# 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('serie_axis', flex=1)
fieldsModifier.configure_field('serie_granularity', flex=1)
fieldsModifier.merge_fields('serie_axis', 'serie_granularity', fieldLabel=T('Serie'))
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',
displayField='AxesTr_axis',
valueField='AxesAxis',
refStore=dbui.get_store_id('axes'),
emptyText=T('Select axis...'),
userReset=True,
xtype='xcomboboxmaster')
fieldsModifier.configure_field('serie_granularity',
masterItemId='serie_axis',
masterValueField='AxesAxis',
displayField='AxesTr_granularity',
valueField='AxesGranularity',
refStore=dbui.get_store_id('axes'),
emptyText=T('Select granularity...'),
xtype='xcomboboxslave')
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
......@@ -147,6 +147,9 @@ helpNode.sort_children()
# REPORT NODE
#
#-------------------------------------------------------------------------------
dashBoardLeaf = PanelWithUrlSelector(virtdb.dashboard_selector,
baseUrl=URL('graphs', 'dashboard'))
listLeaf = PanelWithUrlSelector(virtdb.list_selector,
baseUrl=URL('lists', 'index'),
extField='format',
......@@ -159,6 +162,7 @@ metricLeaf = PanelWithUrlSelector(virtdb.metric_selector,
reportNode = Node(T('Reports'))
reportNode.add_child(T('lists'), listLeaf)
reportNode.add_child(T('metrics'), metricLeaf)
reportNode.add_child(T('dashboard'), dashBoardLeaf)
reportNode.sort_children()
......
{{
#--------------------------------------------------------------------------
#
# The python controller return:
# - cfg_store, the configuration of the Ext.data.Array
# - team_project string
# - selector object
#
# prepare the data
# - build unique DIV identifier
# - Title and DIV block
#
#--------------------------------------------------------------------------
#
# unique identifier for the DIV block associated to the grid
#
divchart = "chart-%s" % id(cfg_store)
#
# The title and the DIV block for the Ext.grid.Panel
#
title = "%s %s" % (T("Sum of publications"), team_project)
response.write(H2(title, _class="dbui-h2 dbui-small-cap"))
response.write(DIV(_id=divchart))
#
# 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
#
jsvars = ["cfgStore = %s" % cfg_store,
"chart",
"divchart = '%s'" % divchart,
"yearMin = %s" % year_min,
"yearMax = %s" % year_max]
jsvars = " var %s;" % ',\n'.join(jsvars)
response.write(SCRIPT(jsvars), escape=False)
}}
<script>
chart = Ext.create('Ext.chart.Chart', {
axes: [{
type: 'Numeric',
position: 'left',
fields: ['publications'],
grid: true,
minimum: 0,
minorTickSteps: 1
}, {
type: 'Time',
position: 'bottom',
fields: ['submitted'],
grid: true,
dateFormat: 'M y',
constrain: true,
fromDate: new Date(yearMin,01, 01),
toDate: new Date(yearMax, 12, 31),
step: [Ext.Date.MONTH, 1],
label: {
rotate: {
degrees: 290
}
}
}],
series: [{
type: 'line',
shadowAttributes: [],
showMarkers: false,
style: {
stroke: '#0084d1',
'stroke-width': 1.5
},
xField: 'submitted',
yField: 'publications'
}],
store: Ext.create('Ext.data.ArrayStore', cfgStore),
width: 500,
height: 400,
padding: "00 00 00 10",
renderTo: divchart
});
</script>
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