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

Modify the metrics2d2 table to generalize summaries and to add the graph configuration.

parent 51707a47
docs/db_schema/database.png

209 KB | W: | H:

docs/db_schema/database.png

203 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
......@@ -425,24 +425,15 @@
<row name="aggregate_func_z" null="0" autoincrement="0">
<datatype>string</datatype>
</row>
<row name="summary_x" null="1" autoincrement="0">
<datatype>boolean</datatype>
<default>NULL</default></row>
<row name="summary_func_x" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="summary_label_x" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="summary_y" null="1" autoincrement="0">
<datatype>boolean</datatype>
<default>NULL</default></row>
<row name="summary_func_y" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="summary_label_y" null="1" autoincrement="0">
<datatype>string</datatype>
<default>NULL</default></row>
<row name="summary_x" null="0" autoincrement="0">
<datatype>blob</datatype>
</row>
<row name="summary_y" null="0" autoincrement="0">
<datatype>blob</datatype>
</row>
<row name="graph" null="0" autoincrement="0">
<datatype>blob</datatype>
</row>
<key type="PRIMARY" name="">
<part>id</part>
</key>
......
......@@ -392,48 +392,53 @@ class Report(object):
length=255,
notnull=True),
Field("summary_x", "boolean", default=False, label="Per row"),
Field("summary_func_x",
"string",
comment=T(TP_SUMMARY_X),
default="sum",
label="aggregate",
length=255),
Field("summary_label_x",
"string",
default=T("Sum"),
label="label",
length=255),
Field("summary_y", "boolean", default=False, label="Per columns"),
Field("summary_func_y",
"string",
comment=T(TP_SUMMARY_Y),
default="sum",
label="aggregate",
length=255),
Field("summary_label_y",
"string",
label="label",
length=255),
Field("summary_x",
"json",
default={"compute": False,
"function(s)": '["sum"]',
"label(s)": '["Sum"]'},
label="Per row"),
Field("summary_y",
"json",
default={"compute": False,
"function(s)": '["sum"]',
"label(s)": '["Sum"]'},
label="Per column"),
Field("graph",
"json",
default={"kind": "bar",
"stacked": True,
"colormap": "Pastel1",
"bar width": 1.0,
"line width": 0,
"xlabel": "",
"ylabel": "",
"grid": True,
"legend": True,
"rot": 0,
"logx": False,
"logy": False,
"loglog": False,
"ylim (min, max)": ""}),
migrate="metrics2d2.table")
sources = PluginManager("event").event.sources.keys()
sources.sort()
db.metrics2d2.source.requires = IS_IN_SET(sources)
table.source.requires = IS_IN_SET(sources)
funcs = AGGREGATE_FUNCS.keys()
funcs.sort()
db.metrics2d2.aggregate_func_z.requires = IS_IN_SET(funcs)
db.metrics2d2.summary_func_x.requires = IS_IN_SET(funcs)
db.metrics2d2.summary_func_y.requires = IS_IN_SET(funcs)
table.aggregate_func_z.requires = IS_IN_SET(funcs)
# NOTE: we have to remove the json validator to work !!
table.graph.requires = None
table.summary_x.requires = None
table.summary_y.requires = None
return table
......
......@@ -325,27 +325,43 @@ class Metric2D2(BaseReport):
if isinstance(df.index, pd.MultiIndex):
df.index = df.index.get_level_values(1)
# prepare summary
# Copy the existing DataFrame to avoid pollution computing summaries
summary_x = config.summary_x
summary_y = config.summary_y
if summary_x[u"compute"] or summary_y[u"compute"]:
df0 = df.copy()
# summary per row
if config.summary_x:
if summary_x[u"compute"]:
func = AGGREGATE_FUNCS[config.summary_func_x]
label = config.summary_label_x
funcs = json.loads(summary_x[u"function(s)"])
labels = json.loads(summary_x[u"label(s)"])
df[label] = df.apply(func, axis="columns")
for i, func in enumerate(funcs):
func = AGGREGATE_FUNCS[func]
label = labels[i]
df[label] = df0.apply(func, axis="columns")
# summary per column
# note: the concatenation does not work when using a CategoricalIndex
# on one side and a standard index on the other side.
if config.summary_y:
if summary_y[u"compute"]:
if isinstance(df.index, pd.CategoricalIndex):
df.index = df.index.astype(unicode)
func = AGGREGATE_FUNCS[config.summary_func_y]
label = config.summary_label_y
funcs = json.loads(summary_y[u"function(s)"])
labels = json.loads(summary_y[u"label(s)"])
for i, func in enumerate(funcs):
func = AGGREGATE_FUNCS[func]
label = labels[i]
sum = pd.DataFrame(df.apply(func, axis="rows"), columns=[label])
df = pd.concat((df, sum.T))
sum = pd.DataFrame(df0.apply(func, axis="rows"), columns=[label])
df = pd.concat((df, sum.T))
# move the index to column in order to ease the data extraction
df = df.reset_index()
......
......@@ -457,6 +457,7 @@ class ReportUi(object):
height=120,
hideLabel=False)
mdf.configure_field("graph", hideLabel=True)
mdf.configure_field("id_events", emptyText=" ")
mdf.configure_field("query",
......@@ -466,11 +467,8 @@ class ReportUi(object):
height=120,
hideLabel=False)
mdf.configure_field("summary_func_x", labelAlign="right")
mdf.configure_field("summary_label_x", labelAlign="right")
mdf.configure_field("summary_func_y", labelAlign="right")
mdf.configure_field("summary_label_y", labelAlign="right")
mdf.configure_field("summary_x", labelAlign="top")
mdf.configure_field("summary_y", labelAlign="top")
#.....................................................................
#
......@@ -496,13 +494,12 @@ class ReportUi(object):
title=T("Aggregate"))
mdf.merge_fields("summary_x",
"summary_func_x",
"summary_label_x",
"summary_y",
"summary_func_y",
"summary_label_y",
title=T("Summary"))
mdf.merge_fields("graph",
title=T("Graph"))
mdf.set_mapper(dbui.map_tabpanel)
mdf.configure(width=450)
......@@ -514,19 +511,16 @@ class ReportUi(object):
mdf.configure_column("name", width=30)
mdf.hide_columns("aggregate_func_z",
"eval",
"graph",
"group_field_x",
"group_field_y",
"id_events",
"metric_field_z",
"query",
"source",
"title",
"summary_x",
"summary_func_x",
"summary_label_x",
"summary_y",
"summary_func_y",
"summary_label_y")
"title")
#.....................................................................
#
......
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