Commit e3f8e373 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the metric table and modify the reporting tools accordingly.

parent 4f543ee5
......@@ -15,7 +15,7 @@ from reporting_tools import Report, repr_duration, to_dataFields
def list():
"""List organises in a Ext.grid.Panel.
"""List renders by an Ext.grid.Panel.
The controller extracts the configuration of the view
and builds the configuration for the Ext.data.Array.
......@@ -87,6 +87,195 @@ def list():
return dict(cfg_store=cfg, view=view)
def metric1D():
"""One dimension metric renders by an Ext.grid.Panel.
The controller extracts the configuration of the metric
and builds the configuration for the Ext.data.Array.
The latter is the core component embedded in the grid.
The metric identifier is defined in the viewport
and send using the baseParams techniques.
"""
metric = db.metrics[request.vars.id_metrics]
report = Report(virtdb.metric_selector, exclude_fields=('category',
'metric',
'period_end',
'period_start',
'year'))
# apply filter condition from the metric
if metric.conditions:
q_conditions = smart_query(db.history, metric.conditions)
report.append_query(q_conditions)
# group condition for the vertical axis
groupfield = metric.field_vertical
label = groupfield.split('.')[-1]
# configure the Ext.data.ArrayStore
cfg = dict()
cfg['data'] = []
cfg['fields'] = [{'name': 'group', 'type': 'string'},
{'name': 'count', 'type': 'float'},
{'name': 'sum_fte', 'type': 'float'},
{'name': 'avg_age', 'type': 'float'}]
cfg['sorters'] = ['group']
# fill the data block
for di in report.get_metric(groupfield):
cfg['data'].append([di['group'], di['count'], di['sum_fte'], di['avg_age']])
# customize the standard view (Ext.grid.Panel)
view = Storage(columns=[], features=[])
view.columns = [{'text': T(label.title()),
'dataIndex': 'group',
'flex': 0.8},
{'text': '∑ person',
'dataIndex': 'count',
'align': 'right',
'flex': 0.5,
'summaryType': 'sum' },
{'text': '∑ fte',
'dataIndex': 'sum_fte',
'align': 'right',
'flex': 0.5,
'format': '0.00',
'summaryType': 'sum',
'xtype': 'numbercolumn'},
{'text': '<age>',
'dataIndex': 'avg_age',
'align': 'right',
'flex': 0.5,
'format': '0.00',
'xtype': 'numbercolumn'}]
view.features = [{'ftype': 'summary'}]
# JSON encoding
view.columns = json.dumps(view.columns)
view.features = json.dumps(view.features)
# delegate to standard view
response.view = 'report/grid.html'
return dict(cfg_store=cfg, view=view)
def metric2D():
"""Two dimensions metric renders by an Ext.grid.Panel.
The controller extracts the configuration of the metric
and builds the configuration for the Ext.data.Array.
The latter is the core component embedded in the grid.
The metric identifier is defined in the viewport
and send using the baseParams techniques.
"""
metric = db.metrics[request.vars.id_metrics]
report = Report(virtdb.metric_selector, exclude_fields=('category',
'metric',
'period_end',
'period_start',
'year'))
# decode filter condition from the metric
if metric.conditions:
q_conditions = smart_query(db.history, metric.conditions)
# vertical axis
groupfield_v = metric.field_vertical
label_v = groupfield_v.split('.')[-1]
# horizontal axis
groupfield_h = metric.field_horizontal
if groupfield_h == 'year':
label_h = 'year'
values_h = range(report.period_start.year, report.period_end.year + 1)
else:
tablename, fieldname = groupfield_h.split('.')
field_h = db[tablename][fieldname]
label_h = fieldname
rows = db().select(field_h, distinct=True)
values_h = [row[fieldname] for row in rows]
# how to count
counter = report.metric
# configure the Ext.data.ArrayStore
# one column for each horizontal value
cfg = dict()
cfg['data'] = []
cfg['fields'] = [{'name': 'group', 'type': 'string'}]
cfg['sorters'] = ['group']
for value in values_h:
cfg['fields'].append({'name': str(value), 'type': 'float'})
# prepare the intermediate dictionary for each vertical group
# the value is a list containing the group name and the metric
# for each horizontal value
data = {}
for value_h in values_h:
report.reset_extra_queries()
report.append_query(q_conditions)
# modify the selector criteria
if groupfield_h == 'year':
report.period_start = date(value_h, 1, 1)
report.period_end = date(value_h, 12, 31)
else:
report.append_query(field_h == value_h)
# for each vertical value build a list.
# it contains the metric for each horizontal value
for di in report.get_metric(groupfield_v):
if di['group'] not in data:
li = [di['group']]
li.extend([""]*len(values_h))
data[di['group']] = li
i = values_h.index(value_h) + 1
data[di['group']][i] = di[counter]
# from the intermediate dictionary
# build the data block of the store
for k in data.iterkeys():
cfg['data'].append(data[k])
# customize the standard view (Ext.grid.Panel)
view = Storage(columns=[], features=[])
view.columns.append({'text': T(label_v.title()),
'dataIndex': 'group',
'flex': 0.8})
for value_h in values_h:
view.columns.append({'text': str(value_h),
'dataIndex': str(value_h),
'align': 'right',
'flex': 0.5,
'format': '0.00',
'summaryType': 'sum',
'xtype': 'numbercolumn'})
view.features.append({'ftype': 'summary'})
# JSON encoding
view.columns = json.dumps(view.columns)
view.features = json.dumps(view.features)
# delegate the rendering to the standard view
response.view = 'report/grid.html'
return dict(cfg_store=cfg, view=view)
def metric():
""" build the table showing all metrics per category, code, ...
The group field category, code, ... is defined in the viewport
......
......@@ -58,6 +58,7 @@ tables = ['auth_group',
'events',
'fundings',
'history',
'metrics',
'people',
'people_categories',
'projects',
......
# -*- coding: utf-8 -*-
""" metrics
"""
tp_conditions = \
T("Can be applied on any field of the history table using the SQL WHERE syntax. "
"Be aware that foreign key are not resolved "
"(more information in the smart_query in the web2py documentation). "
"In addition individual property of the user block are not available, "
"but operator like contains can be applied on the history.data field.")
tp_fields = \
T("Any field of the history table including foreign table. "
"The field is encoded as tablename.fieldname. "
"For properties in the the user data block, use history.data.myproperty.")
db.define_table("metrics",
Field("metric", "string", length=255, notnull=True, unique=True),
Field("title", "string", length=255),
Field("conditions", "text", comment=tp_conditions),
Field("field_vertical", "string", length=255, notnull=True, comment=tp_fields),
Field("field_horizontal", "string", length=255, comment=tp_fields),
Field("sorters_vertical", "list:string", comment=tp_fields),
Field("sorters_horizontal", "list:string", comment=tp_fields),
Field("definition", "text", comment=tp_conditions),
migrate="metrics.table")
# -*- coding: utf-8 -*-
""" metrics
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('metrics')
fieldsModifier.configure_field('conditions', height=120)
fieldsModifier.configure_field('definition', height=120)
fieldsModifier.configure_field('sorters_horizontal', height=120)
fieldsModifier.configure_field('sorters_vertical', height=120)
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
formModifier = dbui.FormModifier('metrics')
formModifier.merge_fields('metric',
'title',
'definition',
title=T('General'))
formModifier.merge_fields('field_vertical',
'field_horizontal',
'conditions',
title=T('Count by'))
formModifier.merge_fields('sorters_vertical',
'sorters_horizontal',
title=T('sorters'))
formModifier.set_mapper(dbui.map_tabpanel)
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
gridModifier = dbui.GridModifier('metrics')
gridModifier.configure_column('metric', width=30)
gridModifier.hide_columns('title',
'conditions',
'field_vertical',
'field_horizontal',
'sorters_vertical',
'sorters_horizontal')
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
storeModifier = dbui.StoreModifier('metrics')
storeModifier.orderby(db.metrics.metric)
\ No newline at end of file
......@@ -62,6 +62,7 @@ helpNode.sort_children()
#-------------------------------------------------------------------------------
cfgNode = Node(T('Configure'))
cfgNode.add_child(T('Configure lists'), to_grid('views'))
cfgNode.add_child(T('Configure metrics'), to_grid('metrics'))
#-------------------------------------------------------------------------------
#
......@@ -105,7 +106,27 @@ for row in db(db.views.id > 0).select():
# METRIC
#
#-------------------------------------------------------------------------------
metricNode = Node(T('The metrics'))
metricNode2 = Node(T('The metrics'))
for row in db(db.metrics.id > 0).select():
# select the action
action = 'metric1D'
if row.field_horizontal:
action = 'metric2D'
leaf = PanelWithUrlSelector(virtdb.metric_selector,
baseUrl=URL('report', action),
baseParams={'id_metrics': row.id})
metricNode2.add_child(row.metric, leaf)
#-------------------------------------------------------------------------------
#
# METRIC (OLD)
#
#-------------------------------------------------------------------------------
metricNode = Node(T('The metrics (old)'))
leaf1 = PanelWithUrlSelector(virtdb.metric_selector,
baseParams={'group': 'people_categories.category'},
......@@ -147,6 +168,7 @@ nodes = [helpNode,
metaNode,
eventNode,
listNode,
metricNode2,
metricNode,
graphNode]
......
......@@ -386,3 +386,6 @@ class Report(SelectorActiveItems):
return query
def reset_extra_queries(self):
self._extra_queries = []
static/docs/database.png

75.1 KB | W: | H:

static/docs/database.png

91.4 KB | W: | H:

static/docs/database.png
static/docs/database.png
static/docs/database.png
static/docs/database.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -22,4 +22,4 @@
<type label="Upload" length="0" sql="upload" quote="'"/>
<type label="Password" length="0" sql="password" quote="'"/>
</group>
</datatypes><table x="303" y="21" name="people"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="first_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="last_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="initials" null="0" autoincrement="0"><datatype>string</datatype></row><row name="birth_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="302" y="174" name="teams"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="team" null="0" autoincrement="0"><datatype>string</datatype></row><row name="domain" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="303" y="285" name="projects"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="project" null="0" autoincrement="0"><datatype>string</datatype></row><row name="agencies" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="618" y="19" name="people_categories"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="code" null="0" autoincrement="0"><datatype>string</datatype></row><row name="category" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="452" y="71" name="history"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="id_people" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people" row="id" /></row><row name="id_teams" null="0" autoincrement="0"><datatype>integer</datatype><relation table="teams" row="id" /></row><row name="id_projects" null="0" autoincrement="0"><datatype>integer</datatype><relation table="projects" row="id" /></row><row name="id_people_categories" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people_categories" row="id" /></row><row name="id_fundings" null="0" autoincrement="0"><datatype>integer</datatype><relation table="fundings" row="id" /></row><row name="id_events" null="0" autoincrement="0"><datatype>integer</datatype><relation table="events" row="id" /></row><row name="start_date" null="0" autoincrement="0"><datatype>date</datatype></row><row name="end_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="percentage" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="0" autoincrement="0"><datatype>text</datatype></row><row name="data" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="633" y="149" name="fundings"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="agency" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="638" y="266" name="events"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="event" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definitiion" null="1" autoincrement="0"><datatype>text</datatype></row><row name="data" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="819" y="189" name="views"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="view" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="conditions" null="1" autoincrement="0"><datatype>text</datatype></row><row name="group_field" null="1" autoincrement="0"><datatype>string</datatype></row><row name="sorters" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="columns" null="0" autoincrement="0"><datatype>text</datatype></row><row name="features" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table></sql>
\ No newline at end of file
</datatypes><table x="303" y="21" name="people"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="first_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="last_name" null="0" autoincrement="0"><datatype>string</datatype></row><row name="initials" null="0" autoincrement="0"><datatype>string</datatype></row><row name="birth_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="note" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="302" y="174" name="teams"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="team" null="0" autoincrement="0"><datatype>string</datatype></row><row name="domain" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="303" y="285" name="projects"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="project" null="0" autoincrement="0"><datatype>string</datatype></row><row name="agencies" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="618" y="19" name="people_categories"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="code" null="0" autoincrement="0"><datatype>string</datatype></row><row name="category" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="452" y="71" name="history"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="id_people" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people" row="id" /></row><row name="id_teams" null="0" autoincrement="0"><datatype>integer</datatype><relation table="teams" row="id" /></row><row name="id_projects" null="0" autoincrement="0"><datatype>integer</datatype><relation table="projects" row="id" /></row><row name="id_people_categories" null="0" autoincrement="0"><datatype>integer</datatype><relation table="people_categories" row="id" /></row><row name="id_fundings" null="0" autoincrement="0"><datatype>integer</datatype><relation table="fundings" row="id" /></row><row name="id_events" null="0" autoincrement="0"><datatype>integer</datatype><relation table="events" row="id" /></row><row name="start_date" null="0" autoincrement="0"><datatype>date</datatype></row><row name="end_date" null="1" autoincrement="0"><datatype>date</datatype></row><row name="percentage" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="note" null="0" autoincrement="0"><datatype>text</datatype></row><row name="data" null="1" autoincrement="0"><datatype>string</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="633" y="149" name="fundings"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="agency" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="638" y="266" name="events"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="event" null="0" autoincrement="0"><datatype>string</datatype></row><row name="definitiion" null="1" autoincrement="0"><datatype>text</datatype></row><row name="data" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="819" y="193" name="views"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="view" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="conditions" null="1" autoincrement="0"><datatype>text</datatype></row><row name="group_field" null="1" autoincrement="0"><datatype>string</datatype></row><row name="sorters" null="1" autoincrement="0"><datatype>integer</datatype></row><row name="columns" null="0" autoincrement="0"><datatype>text</datatype></row><row name="features" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="920" y="190" name="metrics"><row name="id" null="0" autoincrement="1"><datatype>integer</datatype></row><row name="metric" null="0" autoincrement="0"><datatype>string</datatype></row><row name="title" null="1" autoincrement="0"><datatype>string</datatype></row><row name="conditions" null="1" autoincrement="0"><datatype>text</datatype></row><row name="field_vertical" null="0" autoincrement="0"><datatype>string</datatype></row><row name="field_horizontal" null="1" autoincrement="0"><datatype>string</datatype></row><row name="sorters_vertical" null="1" autoincrement="0"><datatype>string</datatype></row><row name="sorters_horizontal" null="1" autoincrement="0"><datatype>string</datatype></row><row name="definition" null="1" autoincrement="0"><datatype>text</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table></sql>
\ No newline at end of file
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