报表多维数据结构
如果structure在report中,那么该structure就表示整张report的数据库数据结构,可以作为每张card的标准。一张report可以同时存在多个数据库,所以也包含多个structure。
report中structure具体的属性如下:
measures
度量字段的相关属性:
"key":度量字段的唯一标识码。
"title":度量字段的标签。
"sort":度量值排序的方式。可选项有:"NXSortOperationNone"(无序),"NXSortOperationAsc"(增序),"NXSortOperationDesc"(降序)
"aggregator":图表有可能出现图形粒度需要分组的情况,这时就需要将度量值根据该属性值进行分组。可选项有:"SUM", "AVG", "MIN", "MAX", "COUNT","RANK". 默认为SUM。
"isCreated":度量值不仅可以直接从数据库中读取,还可以根据formula计算得出。
"formula":计算得出度量值的公式。具体属性见formula
aggregatorGranKey:用来算聚合的粒度基于哪个粒度,比如一个班内有多少个学生分数少于60分,这个字段描述了「一个班」中班的粒度key,如果不设,则此值是aggregatorSubGranKey所在当前维度的最低可见层级的粒度key
aggregatorSubGranKey:用来算聚合的粒度基于哪个子粒度,比如一个班内有多少个学生分数 此字段描述学生粒度值为其key,如果不设,则此值是aggregatorGranKey所在当前维度的最低可见层级的粒度key,要看用户钻取到中一层
aggregatorGroupByLastGran:是否按最后一个图形粒度分组
aggregatorMeasureKey:聚合计算的度量,比如一个班中学习成绩的最高分,这个字段应配置学习成绩这个度量的key。
- rankSort:当"aggregator":"RANK"时是对该度量的值进行排名,设成NXSortOperationDesc是将其从大往小排,NXSortOperationAsc是从小往大排.
formula
可以对度量间进行公式运算,支持+,-,*,/ 以及以下三角函数:
| 描述 | 函数 | |
|---|---|---|
| Sine | sin(x) | |
| Cosine | cos(x) | |
| Tangent | tan(x) | |
| Arc Sine2 | asin(x) | |
| Arc Cosine2 | acos(x) | |
| Arc Tangent | atan(x) | |
| Arc Tan with 2 parameters | atan2(y, x) | |
| Secant | sec(x) | |
| Cosecant | cosec(x) | |
| Co-tangent | cot(x) | |
| Hyperbolic Sine | sinh(x) | |
| Hyperbolic Cosine | cosh(x) | |
| Hyperbolic Tangent | tanh(x) | |
| Inverse Hyperbolic Sine | asinh(x) | |
| Inverse Hyperbolic Cosine1 | acosh(x) | |
| Inverse Hyperbolic Tangent1 | atanh(x) |
指数与LOG函数: |描述 |函数 | | -- | -- | |Natural Logarithm1 |ln(x)| |Logarithm base 101 |log(x) | |Logarithm base 21 |lg(x) | |Exponential (e^x) |exp(x) | |Power1 pow(x)|
统计函数: |描述 |函数 | | -- | -- | |Average |avg(x1,x2,x3,...) | |Minimum| min(x1,x2,x3,...) | |Maximum| max(x1,x2,x3,...) | |Vector |Sum vsum(x1,x2,x3,...) |
| 描述 | 函数 |
|---|---|
| If | if(cond, trueval, falseval) |
| Str (convert number to string) | str(x) |
| Absolute Value / Magnitude | abs(x) |
| Random number (between 0 and 1) | rand() |
| Modulus | mod(x,y) = x % y |
| Square Root1 sqrt(x) | |
| Sum | sum(x,y,...) |
| Binomial coefficients | binom(n, i) |
| Signum (-1,0,1 depending on sign of argument) | signum(x) |
| 描述 | 函数 |
|---|---|
| Real Component re(c) | |
| Imaginary Component im(c) | Imaginary |
| Complex Modulus (Absolute Value) | cmod(c) |
| Argument (Angle of complex value, in radians) | arg(c) |
| Complex conjugate | conj(c) |
| Complex, constructs a complex number from real and imaginary parts | complex(x, y) |
| Polar, constructs a complex number from modulus and argument | polar(r, theta) |
例子 假设COL_1,COL_2,COL_3分别是某3个试题的key. 现在需要构造一个新的度量是COL_1与COL_2相对再除以COL_3的绝对值,则公式如下: "formula":"(COL_1+COL_2)/abs(COL_3)"
example 设COL_0_0=科目,COL_0_1=年,COL_0_2=学期,COL_0_3=月,COL_0_4=日,COL_0_5=年级,COL_0_6=班级,COL_0_7=学生,COL_0_8=每日作业分数总和,则
我们要算出「每日每个同学的作业平均分」 首先要知道基于现在时间维度的层级(有可能钻取到年,有可能是学期,有可能是月,假设是学期)一共有多少天,该试题应配置为:
{
"aggregator": "count",
"aggregatorSubGranKey": "COL_0_4",
"isCreated": true,
"key": "COL_0_12",
"title": "days counts"
}
因为当前时间层级是动态的,所以aggregatorGranKey不作设定,如果需要定死算一个月有几天,不希望跟着当前时间的层级变化,则应配置为:
{
"aggregator": "count",
"aggregatorGranKey": "COL_0_3",
"aggregatorSubGranKey": "COL_0_4",
"isCreated": true,
"key": "COL_0_12",
"title": "days counts inMonth"
}
另外我们再要算一共有几个科目
{
"aggregator": "count",
"aggregatorGranKey": "COL_0_0",
"isCreated": true,
"key": "COL_0_13",
"title": "subject counts"
}
学生数目:
{
"aggregator": "count",
"aggregatorSubGranKey": "COL_0_7",
"isCreated": true,
"key": "COL_0_14",
"title": "student's counts"
}
最后「每日每个同学的作业平均分」=作业所有成绩数据总和/天数/学生数/科目数:
{
"formula": "COL_0_8/COL_0_14/COL_0_12/COL_0_13/",
"isCreated": true,
"key": "COL_0_15",
"title": "student's average kpi"
}
可以直接见学校教育例子
dimensions
维度字段的相关属性:
- "key":维度字段的唯一标识码。
- "title":维度字段的标签。
- "granularities":粒度字段的相关属性类似于dimension的。
- "selectionValue":默认选中的粒度值
- "static"是否可以更换成除默认粒度值外的其它值,默认为false.
- "linkMatchKey":与其它数据源联动时应设定成相同的任意字符串。
- "index":默认为0,所有粒度会按index从小到大进行排序,最后一个粒度则为图形粒度。相同的情况下按json数组里的先后次序。
- "regularExpression":正则表达式用来提取粒度值中的关键词与sortLanguage配合进行排序。
- "sortLanguage":可选值有『NXSortPinyin』按中文译成拼音排序、「NXSortRegularExpressNum」按正则表达式提取的词将文中的中文的 一,二,三,四,壹,贰,甲,乙,丙等 变成 1,2,3按数字大小排
- "sort":排序时是正序(NXSortOperationAsc)还是逆序(NXSortOperationDesc)。
- dateFormat:日期格式输出输出,与series里的数据源的输入输出一致
db
该structure代表的数据库在文件路径中的文件名。
encrypt
若该属性为空或未填写或为null,则表示数据库文件不加密。不然设置该数据库文件的加密密码。
dataSetId
该属性作为structure与数据库映射的标识码。相同dataSetId值的structure表示同一个数据库。