Commit 04ef8fb1 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Modify the db schema and add the logic for Metrics2d2.

parent df138736
......@@ -7,14 +7,22 @@ import json
from gluon.tools import PluginManager
from plugin_dbui import Selector
from plugin_event import do_title2, List2
from plugin_event import do_title2, List2, ReportException
def grid2():
"""New approach to generate lists.
"""New approach to generate lists and metrics2D.
"""
report = List2(request.vars.id_lists2)
try:
if "id_lists2" in request.vars:
report = List2(request.vars.id_lists2)
elif "id_metrics2d2" in request.vars:
return "Hello"
except (IndexError, ReportException, TypeError, ValueError) as e:
return INLINE_ALERT % ("REPORT Error...", e)
store = report.get_store_configuration()
grid = report.get_grid_configuration()
......
docs/db_schema/database.png

180 KB | W: | H:

docs/db_schema/database.png

199 KB | W: | H:

docs/db_schema/database.png
docs/db_schema/database.png
docs/db_schema/database.png
docs/db_schema/database.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -178,7 +178,7 @@
<part>id</part>
</key>
</table>
<table x="827" y="22" name="lists">
<table x="814" y="331" name="lists">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
......@@ -210,7 +210,7 @@
<part>id</part>
</key>
</table>
<table x="934" y="193" name="metrics2d">
<table x="1060" y="330" name="metrics2d">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
......@@ -268,7 +268,7 @@
<part>id</part>
</key>
</table>
<table x="929" y="19" name="metrics1d">
<table x="928" y="374" name="metrics1d">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
......@@ -342,7 +342,7 @@
<part>id</part>
</key>
</table>
<table x="819" y="246" name="lists2">
<table x="805" y="20" name="lists2">
<row name="id" null="1" autoincrement="1">
<datatype>integer</datatype>
<default>NULL</default></row>
......@@ -387,4 +387,52 @@
<part>id</part>
</key>
</table>
<table x="923" y="21" name="metrics2d2">
<row name="id" null="1" autoincrement="1">
<datatype>integer</datatype>
<default>NULL</default></row>
<row name="name" null="0" autoincrement="0">
<datatype>string</datatype>
<default>'NULL'</default></row>
<row name="title" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="definition" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="source" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="id_events" null="0" autoincrement="0">
<datatype>integer</datatype>
<relation table="events" row="id" />
</row>
<row name="eval" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<row name="query" null="1" autoincrement="0">
<datatype>text</datatype>
<default>NULL</default></row>
<row name="group_field_x" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="group_field_y" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="metric_field_z" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="aggregate_func_z" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="summary_func_x" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="summary_func_y" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
</table>
</sql>
......@@ -92,6 +92,7 @@ if ctrl == "plugin_dbui" and fnct in ("call", "dbui_conf"):
"lists2",
"metrics1d",
"metrics2d",
"metrics2d2",
"object_categories",
"objects",
"people",
......
......@@ -13,6 +13,19 @@ from gluon.tools import PluginManager
from pydal import Field
AGGREGATE_FUNCS = [
"count",
"first",
"last",
"max",
"mean",
"median",
"min",
"sem",
"sum",
"std",
"var"]
DEF_COLUMNS_LISTS = \
"""[{
"xtype": "rownumberer"
......@@ -100,6 +113,7 @@ class Report(object):
Report.lists2(db, T)
Report.metrics1d(db, T)
Report.metrics2d(db, T)
Report.metrics2d2(db, T)
@staticmethod
def graphs(db, T):
......@@ -319,6 +333,87 @@ class Report(object):
return table
@staticmethod
def metrics2d2(db, T):
"""metrics2d2 table
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
Returns:
pyDAL.Table
"""
table = db.define_table(
"metrics2d2",
Field("name", "string", length=255, notnull=True, unique=True),
Field("title", "string", length=255),
Field("definition", "text"),
Field("source", "string", length=255, notnull=True),
Field("id_events",
"reference events",
notnull=True,
label="Event"),
Field("eval", "text"),
Field("query", "text"),
Field("group_field_x",
"string",
length=255,
notnull=True,
comment=T(TP_GROUP_FIELD_METRICS),
label="Group (x)"),
Field("group_field_y",
"string",
length=255,
notnull=True,
comment=T(TP_GROUP_FIELD_METRICS),
label="Group (y)"),
Field("metric_field_z",
"string",
length=255,
notnull=True,
comment=T(TP_GROUP_FIELD_METRICS),
label="Metric (z)"),
Field("aggregate_func_z",
"string",
default="sum",
length=255,
notnull=True,
comment=T(TP_AGG),
label="Aggregate (z)"),
Field("summary_func_x",
"string",
default="",
length=255,
label="Summary (x)"),
Field("summary_func_y",
"string",
default= "",
length=255,
label="Summary (y)"),
migrate="metrics2d2.table")
sources = PluginManager("event").event.sources.keys()
sources.sort()
db.metrics2d2.source.requires = IS_IN_SET(sources)
db.metrics2d2.aggregate_func_z.requires = IS_IN_SET(AGGREGATE_FUNCS)
db.metrics2d2.summary_func_x.requires = IS_IN_SET(AGGREGATE_FUNCS)
db.metrics2d2.summary_func_y.requires = IS_IN_SET(AGGREGATE_FUNCS)
return table
@staticmethod
def tables():
"""Tool returning the list of table names.
......@@ -329,7 +424,9 @@ class Report(object):
"""
lst = ["graphs",
"lists",
"lists2",
"metrics1d",
"metrics2d"]
"metrics2d"
"metrics2d2"]
return lst
......@@ -25,6 +25,7 @@ It is possible to filter the source by applying a query on its fields.
For more details have a look to the method pandas.DataFrame.query.
"""
class ReportUi(object):
@staticmethod
......@@ -42,6 +43,7 @@ class ReportUi(object):
ReportUi.lists2(db, T)
ReportUi.metrics1d(db, T)
ReportUi.metrics2d(db, T)
ReportUi.metrics2d2(db, T)
@staticmethod
def graphs(db, T):
......@@ -430,3 +432,94 @@ class ReportUi(object):
# Store
#
storeModifier("metrics2d").orderby(db.metrics2d.name)
@staticmethod
def metrics2d2(db, T):
"""UI for the metrics2d2 table
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
"""
#.....................................................................
#
# Fields
#
mdf = fieldsModifier("metrics2d2")
mdf.configure_field("definition", height=110)
mdf.configure_field("eval",
emptyText=T(EVAL_GUIDE),
fieldLabel=T("Add columns"),
labelAlign="top",
height=120,
hideLabel=False)
mdf.configure_field("id_events", emptyText=" ")
mdf.configure_field("query",
emptyText=T(QUERY_GUIDE),
fieldLabel=T("Filter source"),
labelAlign="top",
height=120,
hideLabel=False)
mytype = "xcomboboxuserreset"
text = T("select...")
mdf.configure_field("summary_func_x", emptyText=text, xtype=mytype)
mdf.configure_field("summary_func_y", emptyText=text, xtype=mytype)
#.....................................................................
#
# Form
#
mdf = formModifier("metrics2d2")
mdf.merge_fields("name",
"title",
"source",
"id_events",
"definition",
title=T("General"))
mdf.merge_fields("eval",
"query",
title=T("Transform"))
mdf.merge_fields("group_field_x",
"group_field_y",
"metric_field_z",
"aggregate_func_z",
"summary_func_x",
"summary_func_y",
title=T("Aggregate"))
mdf.set_mapper(dbui.map_tabpanel)
mdf.configure(width=450)
#.....................................................................
#
# Grid
#
mdf = gridModifier("metrics2d2")
mdf.configure_column("name", width=30)
mdf.hide_columns("aggregate_func_z",
"eval",
"group_field_x",
"group_field_y",
"id_events",
"metric_field_z",
"query",
"source",
"title",
"summary_func_x",
"summary_func_y")
#.....................................................................
#
# Store
#
storeModifier("metrics2d2").orderby(db.metrics2d2.name)
......@@ -38,6 +38,7 @@ class ViewportUi(object):
ViewportUi.list2_node(db, T, selector_panel),
ViewportUi.metric1d_node(db, T, selector_panel),
ViewportUi.metric2d_node(db, T, selector_panel),
ViewportUi.metric2d2_node(db, T, selector_panel),
ViewportUi.graph_node(db, T, selector_panel)]
modifier = dbui.ViewportModifier()
......@@ -140,6 +141,7 @@ class ViewportUi(object):
add_child(T("the lists #2"), to_grid(db.lists2))
add_child(T("the metrics 1d"), to_grid(db.metrics1d))
add_child(T("the metrics 2d"), to_grid(db.metrics2d))
add_child(T("the metrics 2d2"), to_grid(db.metrics2d2))
add_child(T("the graphs"), to_grid(db.graphs))
return node
......@@ -330,6 +332,34 @@ class ViewportUi(object):
return node
@staticmethod
def metric2d2_node(db, T, selector_panel):
"""To deal with two-dimension metrics.
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
selector_panel (gluon.storage.Storage):
configuration of the selector panel.
Returns:
dbui.Node:
the configuration of a tree node.
"""
node = Node(T("The metrics 2d2"))
add_child = node.add_child
for row in db(db.metrics2d2.id > 0).select(orderby=db.metrics2d2.name):
panel = selector_panel
panel.baseUrl = URL("new_report", "grid2")
panel.baseParams = {"id_metrics2d2": row.id}
node.add_child(row.name, panel)
return node
@staticmethod
def graph_node(db, T, selector_panel):
"""To deal with graphs.
......
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