Commit 03d64890 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the report stacked chart.

parent 91b375cd
......@@ -9,6 +9,9 @@ from plugin_dbui import Selector
from reporting_tools import repr_team_project
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,
......@@ -16,12 +19,8 @@ def dashboard():
"""
# 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'))
exclude_fields=('year_start', 'year_end'))
# query directive to count publications including
# foreign key constraints and user requirements
......@@ -75,18 +74,25 @@ def dashboard():
selector=selector)
def index():
"""the main controller to build graph
def stackedchart():
"""show the cumulative 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
selector = Selector(virtdb.graph_selector,
selector = Selector(virtdb.stackedchart_selector,
exclude_fields=('year_start',
'year_end',
'serie_axis',
'serie_granularity'))
# protection -- a serie has to be selected
if not selector.serie_axis:
return INLINE_ALERT % (T("Error"), T("Please select a serie..."))
# query directive to count publications including
# foreign key constraints and user requirements
# related to team, project and year
......@@ -101,43 +107,34 @@ def index():
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]]
# the serie field and reference dictionary
serie_field = db[selector.serie_axis][selector.serie_granularity]
series = {}
for row in db(db[selector.serie_axis]).select(serie_field, distinct=True):
series[row[selector.serie_granularity]] = 0
# group per year, per month and per serie
group_by = [db.publications.submitted[:4],
db.publications.submitted[5:7],
serie_field]
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,
serie_field,
count,
groupby=group_by,
orderby=group_by)
# configure the Ext.data.ArrayStore
# configure the Ext.data.JsonStore
cfg = Storage(fields=[], data=[])
cfg.fields.append({'name': 'submitted', 'type': 'date', 'dateFormat': 'Y-m-d'})
cfg.fields.append({'name': 'publications', 'type': 'int'})
for key in series.iterkeys():
cfg.fields.append({'name': key, 'type': 'int'})
current, dates = None, []
for row in rows:
# protection -- ignore publication with invalid submitted date
......@@ -145,15 +142,27 @@ def index():
if len(submitted) == 4:
continue
# centre the bin to the middle of the month
cfg.data.append(["%s-15" % submitted[:7], row[count]])
if submitted[:7] != current:
current = submitted[:7]
di = dict(**series)
di['submitted'] = "%s-15" % submitted[:7]
cfg.data.append(di)
dates.append(di['submitted'])
serie = row[selector.serie_axis][selector.serie_granularity]
cfg.data[-1][serie] = row[count]
# cumulative distribution
sum = 0
for i in range(len(cfg.data)):
sum += cfg.data[i][1]
cfg.data[i][1] = sum
for serie in series.iterkeys():
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)
team_project=repr_team_project(db, selector),
selector=selector,
series=series.keys())
......@@ -8,7 +8,7 @@ from gluon.dal import smart_query
from plugin_dbui import Selector
from reporting_tools import get_converter, repr_team_project
INLINE_ALERT = "<script>Ext.Msg.alert('%s', '%s');</script>"
MSG_NO_METRIC = T("Please select a metric....")
MSG_NO_TABLE = T("Invalid database table '%s'")
......@@ -27,7 +27,7 @@ def index():
# protection
if not selector.id_metrics:
return MSG_NO_METRIC
return INLINE_ALERT % (T("Error"), MSG_NO_METRIC)
# retrieve metric data
metric = db.metrics[selector.id_metrics]
......
......@@ -407,7 +407,8 @@
'PhDs': 'PhDs',
'please input your password again': 'please input your password again',
'Please select a list....': 'Sélectionner une liste....',
'Please select a metric....': 'Sélectionner une metrique....',
'Please select a metric....': 'Sélectionnez une métrique....',
'Please select a serie...': 'sélectionnez une série...',
'Please, define sections for the list "%s"': 'définissez des sections pour la liste "%s"',
'plugin not install': 'plugin not install',
'Position': 'Position',
......@@ -553,6 +554,7 @@
'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',
'stacked chart': 'stacked chart',
'state': 'state',
'Statistics': 'Statistique',
'Status': 'Status',
......
# -*- coding: utf-8 -*-
""" graph_selector (virtual table)
""" stackedchart_selector (virtual table)
"""
#-------------------------------------------------------------------------------
......@@ -7,7 +7,7 @@
# DEFINITION
#
#-------------------------------------------------------------------------------
virtdb.define_table('graph_selector',
virtdb.define_table('stackedchart_selector',
Field('year_start', 'integer', default=year),
Field('year_end', 'integer'),
Field('id_teams', 'reference teams', label='Team'),
......@@ -15,15 +15,15 @@ virtdb.define_table('graph_selector',
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')
virtdb.stackedchart_selector.id_projects.requires = IS_IN_DB(db, 'projects.project')
virtdb.stackedchart_selector.id_teams.requires = IS_IN_DB(db, 'teams.team')
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('graph_selector')
fieldsModifier = dbui.FieldsModifier('stackedchart_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'))
......
......@@ -148,7 +148,7 @@ helpNode.sort_children()
#
#-------------------------------------------------------------------------------
dashBoardLeaf = PanelWithUrlSelector(virtdb.dashboard_selector,
baseUrl=URL('graphs', 'dashboard'))
baseUrl=URL('graphs', 'dashboard'))
listLeaf = PanelWithUrlSelector(virtdb.list_selector,
baseUrl=URL('lists', 'index'),
......@@ -159,10 +159,14 @@ 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('lists'), listLeaf)
reportNode.add_child(T('metrics'), metricLeaf)
reportNode.add_child(T('dashboard'), dashBoardLeaf)
reportNode.add_child(T('stacked chart'), stackedChartLeaf)
reportNode.sort_children()
......
......@@ -26,6 +26,8 @@ HEAD
Harvester can not add country anymore.
- Re-enforce rule for fields: collaborations, defense, conference_dates,
submitted and publications_url
- Add the dashbaord reports. It shows the cumulative number of publications
as a function of the months.
0.8.7.2 (Sep 2014)
- Migrate to plugin_dbui 0.6.1.7.
......
{{
#--------------------------------------------------------------------------
#
# The python controller return:
# - cfg_store, the configuration of the Ext.data.Array
# - team_project string
# - selector object
# - series
#
# prepare the data
# - build unique DIV identifier
# - Title and DIV block
#
#--------------------------------------------------------------------------
import json
#
# 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,
"series = %s" % json.dumps(series),
"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: series,
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
}
}
}],
legend: {
labelFont: '8px Helvetica, sans-serif',
position: 'right'
},
series: [{
type: 'area',
style: {
opacity: 0.8
},
xField: 'submitted',
yField: series
}],
store: Ext.create('Ext.data.JsonStore', cfgStore),
width: 600,
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