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

Modify the database schema to improve the summary section of metrics2d2.

parent 068763ef
docs/db_schema/database.png

199 KB | W: | H:

docs/db_schema/database.png

209 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="814" y="331" name="lists">
<table x="1064" y="24" name="lists">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
......@@ -210,7 +210,7 @@
<part>id</part>
</key>
</table>
<table x="1060" y="330" name="metrics2d">
<table x="1166" y="219" name="metrics2d">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
......@@ -242,7 +242,7 @@
<part>id</part>
</key>
</table>
<table x="1065" y="22" name="graphs">
<table x="1057" y="250" name="graphs">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
......@@ -268,7 +268,7 @@
<part>id</part>
</key>
</table>
<table x="928" y="374" name="metrics1d">
<table x="1163" y="28" name="metrics1d">
<row name="id" null="0" autoincrement="1">
<datatype>integer</datatype>
</row>
......@@ -425,12 +425,24 @@
<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>
<key type="PRIMARY" name="">
<part>id</part>
</key>
......
......@@ -391,17 +391,33 @@ 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),
length=255,
label="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),
length=255,
label="Summary (y)"),
label="aggregate",
length=255),
Field("summary_label_y",
"string",
label="label",
length=255),
migrate="metrics2d2.table")
......
......@@ -326,7 +326,8 @@ class Metric2D2(BaseReport):
.groupby([field_x, field_y])
.agg({field_z: aggregate_func_z})
.unstack(level=0)
.fillna(0))
.fillna(0)
.sort_index())
if isinstance(df.columns, pd.MultiIndex):
df.columns = df.columns.get_level_values(1)
......@@ -334,16 +335,22 @@ class Metric2D2(BaseReport):
if isinstance(df.index, pd.MultiIndex):
df.index = df.index.get_level_values(1)
func_x = config.summary_func_x
if func_x not in ("", None):
df[func_x.title()] = \
df.apply(AGGREGATE_FUNCS[func_x], axis="columns")
# summary per row
if config.summary_x:
func_y = config.summary_func_y
if func_y not in ("", None):
tot = pd.DataFrame(df.apply(AGGREGATE_FUNCS[func_y], axis="rows"),
columns=[func_y.title()])
df = pd.concat((df, tot.T))
func = AGGREGATE_FUNCS[config.summary_func_x]
label = config.summary_label_x
df[label] = df.apply(func, axis="columns")
# summary per column
if config.summary_y:
func = AGGREGATE_FUNCS[config.summary_func_y]
label = config.summary_label_y
sum = pd.DataFrame(df.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()
......@@ -359,8 +366,6 @@ class Metric2D2(BaseReport):
di["type"] = ("string" if col == field_y else "number")
store.fields.append(di)
store.sorters = [field_y]
if not df.empty:
data = df.to_json(orient="records", date_format="iso")
store.data = json.loads(data)
......
......@@ -466,18 +466,11 @@ class ReportUi(object):
height=120,
hideLabel=False)
mytype = "xcomboboxuserreset"
text = T("select...")
mdf.configure_field("summary_func_x", labelAlign="right")
mdf.configure_field("summary_label_x", labelAlign="right")
mdf.configure_field("summary_func_x",
emptyText=text,
emptyValue=text,
xtype=mytype)
mdf.configure_field("summary_func_y",
emptyText=text,
emptyValue=text,
xtype=mytype)
mdf.configure_field("summary_func_y", labelAlign="right")
mdf.configure_field("summary_label_y", labelAlign="right")
#.....................................................................
#
......@@ -500,9 +493,15 @@ class ReportUi(object):
"group_field_y",
"metric_field_z",
"aggregate_func_z",
title=T("Aggregate"))
mdf.merge_fields("summary_x",
"summary_func_x",
"summary_label_x",
"summary_y",
"summary_func_y",
title=T("Aggregate"))
"summary_label_y",
title=T("Summary"))
mdf.set_mapper(dbui.map_tabpanel)
mdf.configure(width=450)
......@@ -522,8 +521,12 @@ class ReportUi(object):
"query",
"source",
"title",
"summary_x",
"summary_func_x",
"summary_func_y")
"summary_label_x",
"summary_y",
"summary_func_y",
"summary_label_y")
#.....................................................................
#
......
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