Files
playbook/docs/tsl/codegen/dotnet/runtime/array.md
T

1279 lines
43 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 运行时 / 数组
## 数组 / 基础函数
## `callInArray(func, args)`
以参数数组调用指定函数(含函数名或函数变量)。
| 参数 | 类型 | 说明 |
| ------ | ------ | ---------------------- |
| `func` | string | 函数名字符串或函数指针 |
| `args` | array | 参数数组 |
返回:any
## `deleteField(arr, index, merge)`
数组相关函数。
| 参数 | 类型 | 说明 |
| ------- | ----- | ---- |
| `arr` | array | |
| `index` | any | |
| `merge` | bool | |
返回:bool
## `deleteIndex(arr, index, merge)`
数组相关函数。
| 参数 | 类型 | 说明 |
| ------- | ----- | ---- |
| `arr` | array | |
| `index` | any | |
| `merge` | bool | |
返回:bool
## `execSql(flags, _params, data_base_name, sql, data_keep_null)`
执行SQL语句,该函数总共有8个参数,其中,Flags、Params、UserName;Password、DataKeepNull为可选参数,在调用时,注意参数顺序按定义中的顺序来传入,不需要的参数可以跳过不给。 比如只给Params这个可选参数,则调用代码为: param:=array("TestParamName":("Value":"ParamNameValue","Direction":3)); execsql(param,"test","myStoredProctest",result); 此外,在以上基础上,如果执行的是存贮过程,需要将参数带入,则插入一个参数在最前面,类型为数组,具体结构见参数说明。 如果数据库别名配置在本地,对本地的数据进行操作,则在调用execsql之前,需要加入rdo2关键字(见范例);如果数据库别名配置在服务器,则不需要rdo2关键字。 ExecSQL允许当别名为WideString的时候,默认使用WideString。
| 参数 | 类型 | 说明 |
| ---------------- | ------ | --------------------------------------------------------------------------------------------------------------- |
| `flags` | int | 功能标识符,可选参数,设置值如下 |
| `_params` | array | 数组类型,可选参数,以存贮过程的参数名为下标的一个数组描述存贮过程的参数,其每个存贮参数下标指向的值的结构如下: |
| `data_base_name` | string | 字符串类型,数据库别名,用于指定数据库名称;例如\[SQLAlias\],配置方法详见数据库配置。 |
| `sql` | array | 字符串类型,需要执行的SQL语句。 |
| `data_keep_null` | string | object |
返回:Interger
## `exportJsonStringUtf8(data, n, return_value)`
将天软数组转换为UTF8编码的Json串,解决与第三方交互时的转码问题。
| 参数 | 类型 | 说明 |
| -------------- | ------- | ----------------------------------------------------------------------------- |
| `data` | anytype | 天软数据,任意数据类型。 |
| `n` | int | 可选参数,要保留的小数位数。为0时保留1位小数,大于16或小于0时保留全部小数位数 |
| `return_value` | string | 字符串,UTF8编码的Json字符串。 |
返回:string
## `getMatrixFields(matrix)`
获取 Matrix 的字段(列名)列表。
| 参数 | 类型 | 说明 |
| -------- | ------ | ----------- |
| `matrix` | matrix | Matrix 数据 |
返回:array
## `invokeinarray(obj, member_name, member_value, _params)`
调用类的成员方法或对类的成员变量进行赋值操作。支持对重载方法的调用。基本功能与invoke一样,区别在于设置成员变量的值与调用成员方法的参数值通过数组进行传递。另外,支持命名参数的调用。
| 参数 | 类型 | 说明 |
| -------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `obj` | TSLObject | 实例对象 |
| `member_name` | string | 字符串(小写),成员(方法或属性)的名称 |
| `member_value` | bool | object |
| `_params` | array | 数组,若是成员属性则数组传递的是设置的成员属性值,若是成员方法则表示成员方法的参数,成员方法没有参数时须初始化为空数组。命名参数调用时,下标字符串作为参数名。 |
返回:any
## `magicGetArray(arr, n1, n2, nn)`
获取数组指定下标的值,支持多维数组。中间的参数可以是直接列出的数组各维下标,也可以以数组的形式表现,数组内的数据就是下标。
| 参数 | 类型 | 说明 |
| ----- | ------ | -------- |
| `arr` | array | 数组 |
| `n1` | string | string\\ |
| `n2` | string | string |
| `nn` | string | string |
返回:any
## 数组 / 排序函数
## `magicSetArray(arr, n1, n2, nn, a)`
对数组进行操作,对数组指定下标的数据进行赋值,支持多维数组。中间的参数可以是直接列出的数组各维下标,也可以以数组的形式表现,数组内的数据就是下标。
| 参数 | 类型 | 说明 |
| ----- | ------ | -------------------------------- |
| `arr` | array | 数组 |
| `n1` | string | string\\ |
| `n2` | string | string |
| `nn` | any | string |
| `a` | string | 最后一个参数,任意值,被赋的值。 |
返回:array
## `matrixToArray(mat)`
转换一个Matrix类型为Array。主要可用于Matlab 与TS交互时,从MatLab中得到的矩阵,在TS中不能进行矩阵操作,将Matrix转为天软的矩阵类型之后,即可进行矩阵计算等操作。 如果要反向转换(把Array转化成Matrix),可以采用mselect语法。 支持fmarray转换成Array数组,比如MatrixToArray(fmarray\[1,2,3\])返回array(1,2,3)。
| 参数 | 类型 | 说明 |
| ----- | ------ | --------------------------------- |
| `mat` | matrix | Martrix类型,要转换的MARTIX数据。 |
返回:array
## `reIndex(data, index_info1, index_info2, index_info_n)`
修改数组下标
| 参数 | 类型 | 说明 |
| -------------- | ----- | -------------- |
| `data` | array | 需要重构的数组 |
| `index_info1` | any | Array |
| `index_info2` | any | Array |
| `index_info_n` | any | Array |
返回:array
## `reshape(a, count1, count_n)`
将原数组A的元素重构为一个新的指定行列大小的数组,支持行列重命名。要求重构后的数组的元素个数与原数组的元素个数保持一致。 当只有一个参数时,将原数组A重构为一个一维数组,当有多个参数时,重构为指定结构的N维数组。
| 参数 | 类型 | 说明 |
| --------- | ----- | ---------------------------------------------------------------------------------------------------- |
| `a` | array | 数组类型,需要重构的数组。 |
| `count1` | array | 整数或数组类型,重构的第一维的长度或下标,可缺省,其值可以为第一维度的长度,也可以是维度的下标数组。 |
| `count_n` | array | 整数或数组类型,重构的第N维的长度或下标,可缺省,其值可以为第N维度的长度,也可以是维度的下标数组。 |
返回:array
## 数据表与数组扩展函数
## `istable(t)`
判断是否为数组。如果t为数据表,返回True;否则,返回False
| 参数 | 类型 | 说明 |
| ---- | ----- | ------ |
| `t` | array | 数据表 |
返回:bool
### 示例
```tsl
t1 := array(('a': 1, 'b': 4), ('a': 7, 'b': 8), ('a': 2, 'b': 3));
return istable(t1);
// 结果:1
```
## `noRecordTable()`
返回一个空数组
返回:array,tablearray
### 示例
```tsl
return noRecordTable();
// 结果:Array()
```
## `getSubTable(table, field_arr)`
将一个表类型数组只保留指定的字段并返回
| 参数 | 类型 | 说明 |
| ----------- | ----- | ---------------- |
| `table` | array | 二维数组 |
| `field_arr` | array | 列标名,一维数组 |
返回:array
### 示例
```tsl
a := array((1, 2, 4), (11, 12, 14));
b := array(0, 2);
return getSubTable(a, b);
// 输出:
// Execute script error at Line:3
// function:__main__:line 3:instruction:usercall: function:getSubTable compile error or not found
// function:__main__:line 3:instruction:usercall: function execute error
```
## `fieldCount(t)`
数据表字段个数。如果t不是一个数据表,则返回0
| 参数 | 类型 | 说明 |
| ---- | ----- | ------ |
| `t` | array | 数据表 |
返回:integer
### 示例
```tsl
t1 := array(('a': 1, 'b': 4), ('a': 7, 'b': 8), ('a': 2, 'b': 3));
return fieldCount(t1);
// 结果:2
```
## `fieldExist(t, f_name)`
指定字段是否存在。如果存在,则返回索引号;(索引号从0开始),不存在,返回-1
| 参数 | 类型 | 说明 |
| -------- | ------ | ---------------- |
| `t` | array | 数据表 |
| `f_name` | string | 指定字段,字符串 |
返回:integer
### 示例
```tsl
t1 := array(('a': 1, 'b': 4), ('a': 7, 'b': 8), ('a': 2, 'b': 3));
return fieldExist(t1, 'b');
// 结果:1
```
## `fieldNames(t)`
返回数据表所有字段名称
| 参数 | 类型 | 说明 |
| ---- | ----- | ------ |
| `t` | array | 数据表 |
返回:array
### 示例
```tsl
t1 := array(('a': 1, 'b': 4), ('a': 7, 'b': 8), ('a': 2, 'b': 3));return fieldNames(t1);
// 输出:
// 示例未提供可直接输出的返回表达式。
```
## `fieldName(t, field_index)`
返回数据表指定列索引号(索引号从0开始)的字段名称
| 参数 | 类型 | 说明 |
| ------------- | ------- | ------------ |
| `t` | array | 数据表 |
| `field_index` | integer | 指定列,整数 |
返回:string
### 示例
```tsl
t1 := array(('a': 1, 'b': 4), ('a': 7, 'b': 8), ('a': 2, 'b': 3));
return fieldName(t1, 0);
// 结果:’a
```
## `recordExist(t, v)`
数值是否在数组中存在(一维数组),如果存在,则返回索引号;(索引号从0开始)不存在,返回-1
| 参数 | 类型 | 说明 |
| ---- | ------ | ------------------------------- |
| `t` | array | 指定一维数组 |
| `v` | string | 要查询的数值,与t单元值类型一致 |
返回:integer
### 示例
```tsl
t := array(1, 2, 12, 3, 14);
return recordExist(t, 12);
// 结果:2
```
## `recordExist2(t, f_name, v)`
记录数据表(二维数组)中是否存在列名为fName,值为V的记录;如果存在,则返回行标索引号(索引号从0开始),不存在,返回-1
| 参数 | 类型 | 说明 |
| -------- | ------ | ------------------------- |
| `t` | array | 指定数组,二维数组 |
| `f_name` | string | 指定列名,字符串 |
| `v` | string | 指定值,与t单元值类型一致 |
返回:integer
### 示例
```tsl
t1 := array(('a': 1, 'b': 4), ('a': 7, 'b': 8), ('a': 2, 'b': 3));
return recordExist2(t1, 'b', 3);
// 结果:2
```
## `recordExist3(v, x)`
记录指定值是否存在一维数组中,如果存在,返回1,不存在,返回0
| 参数 | 类型 | 说明 |
| ---- | ------- | ------------------------- |
| `v` | string | 指定数组,一维数组 |
| `x` | integer | 指定值,与v单元值类型一致 |
返回:bool
### 示例
```tsl
t := array(1, 2, 12, 3, 14);
return recordExist3(t, 3);
// 结果:1
```
## `passwordGen(len, n, head, start)`
密码生成器
| 参数 | 类型 | 说明 |
| ------- | ------- | ------------------------------------ |
| `len` | integer | 整数,密码长度 |
| `n` | integer | 整数,生成的密码组合数 |
| `head` | string | 字符串,用户名的前缀 |
| `start` | integer | 整数,用户名的后缀序列数字的起始数字 |
返回:array
### 示例
```tsl
return rdo2 passwordGen(8, 5, 'ts', 3);
// 返回:
```
## `appendArray(arr, con)`
数组新增元素,给数组arr添加一项con
| 参数 | 类型 | 说明 |
| ----- | ------- | ------------------------ |
| `arr` | array | 一维数组 |
| `con` | integer | 整数或字符串,需增加的值 |
返回:array
### 示例
```tsl
a := array(1, 2, 3);
appendArray(a, 4);
return a;
// 返回:
```
## `in1(v, x)`
判断数值x是否在数组v中,返回布尔类型
| 参数 | 类型 | 说明 |
| ---- | ----- | -------- |
| `v` | array | 一维数组 |
| `x` | real | 实数 |
返回:bool
### 示例
```tsl
a := array(1, 2, 3, 4);
return in1(a, 3);
// 结果:1
```
## `deleteColumnByField(t, fields)`
删除指定列,可以一次性删除多列,删除的列字段之间使用;分割
| 参数 | 类型 | 说明 |
| -------- | ------ | ------------------------------------------------------------------------ |
| `t` | array | 指定数组,数据表列名为字符串类型,程序执行完后会变更为删除指定列后的数组 |
| `fields` | string | 指定列,字符串 |
返回:array
### 示例
```tsl
t1 := array(('a': 1, 'b': 4, 'c': 9), ('a': 7, 'b': 8, 'c': 5));
return deleteColumnByField(t1, 'a;b');
// 输出:
// Execute script error at Line:2
// function:__main__:line 2:instruction:usercall: function:deleteColumnByField compile error or not found
// function:__main__:line 2:instruction:usercall: function execute error
```
## `getValuesByFieldValue(t, f_name, field_value)`
返回指定字段值等于指定值的所有记录
| 参数 | 类型 | 说明 |
| ------------- | ------ | ------------------- |
| `t` | array | 二维数组 |
| `f_name` | string | 字符串,指定字段 |
| `field_value` | string | 整数/字符串,指定值 |
返回:array
### 示例
```tsl
t := array(('a': 1, 'b': 4), ('a': 7, 'b': 8), ('a': 2, 'b': 4));
return getValuesByFieldValue(t, 'b', 4); // 返’b’列值为4的所有记录
// 输出:
// 示例包含说明文字,未作为可执行片段运行。
```
## `seekPosInArray(r, arr)`
数字定位,采用二分法寻找数字R在一位正序数字数组arr中的下标。
| 参数 | 类型 | 说明 |
| ----- | ----- | ------------ |
| `r` | real | 实数 |
| `arr` | array | 一维数字数组 |
返回:integer
### 示例
```tsl
return seekPosInArray(4, array(1, 2, 3, 4, 5));
// 返回:3
```
## `outPutTableToCanBeUnderstood(t)`
判断一个数据表是否是空值,如果是则返回'返回结果为空',否则返回该数组。
| 参数 | 类型 | 说明 |
| ---- | ----- | -------------- |
| `t` | array | 数组,数据表。 |
返回:string|array
### 示例
```tsl
return outPutTableToCanBeUnderstood(array(1, 2, 3));
// 返回:
```
## `filterOneDimEx2(t, v1)`
小于等于指定值的最后一条记录(一维数组)。
| 参数 | 类型 | 说明 |
| ---- | ----- | ------------ |
| `t` | array | 一维数字数组 |
| `v1` | real | 实数,指定值 |
返回:real
### 示例
```tsl
s := array(1, 2, 3, 4, 5, 6);
return filterOneDimEx2(s, 4);
// 返回:4
```
## `groupByFieldValue(t, group_field, lowvalue, high_value, sep_value)`
按字段大小进行汇总。小于最小值Lowvalue为一组,从最小值Lowvalue到最大值HighValue中间每步长SepValue为一组,大于最大值High为一组。
| 参数 | 类型 | 说明 |
| ------------- | ------ | -------------- |
| `t` | array | 数据表类型 |
| `group_field` | string | 字符串,列名 |
| `lowvalue` | real | 实数,最小数值 |
| `high_value` | real | 实数,最大数值 |
| `sep_value` | real | 实数,统计间距 |
返回:any
### 示例
```tsl
data := select * from tradetable datekey 20180903t to 20180904T of 'sz000001' end;
return groupByFieldValue(data, 'close', 1, 20, 0.1);
// 返回:
```
## `columnValue(t, fname)`
取得指定列的所有值(按列名)。该函数的功能与直接用读取子矩阵的方式一样,但是用子矩阵的方式更简单快速。功能相当于t[:,fname]
| 参数 | 类型 | 说明 |
| ------- | ------ | ------------------ |
| `t` | array | 数据表类型,数据表 |
| `fname` | string | 字符串,列字段名称 |
返回:any
### 示例
```tsl
s := select ['StockID'] as '代码',
["StockName"] as "名称",
['price'] as '收盘'
from markettable datekey 20190101T to 20190201T of 'SZ000001' end;
return columnValue(s, '收盘');
// 返回:
```
## `filterTableEx(t, fname, method, v1, v2)`
范围取值,从一个表中按照某个字段的取值范围返回对应的记录
| 参数 | 类型 | 说明 |
| -------- | ------ | ---------------------------------------------- |
| `t` | array | 数据表 |
| `fname` | string | 指定字段名,字符串 |
| `method` | string | >’,’<’,’<>’,’<=’,’>=’,’IN’,’IN2’,’IN3 |
| `v1` | real | 实数 |
| `v2` | real | 实数 |
返回:array
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33));
return filterTableEx(t2, 'c', 'IN', 13, 30); // 取13<=[ 'c']<=30
// 输出:
// 示例包含说明文字,未作为可执行片段运行。
```
## `getBottomN(t, n)`
取数组后N行,一般先用SortByField排序,然后使用此函数
| 参数 | 类型 | 说明 |
| ---- | ------- | ------ |
| `t` | array | 数据表 |
| `n` | integer | 整数 |
返回:array
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 33));
return getBottomN(t2, 2);
// 输出:
// Execute script error at Line:2
// function:__main__:line 2:instruction:usercall: function:getBottomN compile error or not found
// function:__main__:line 2:instruction:usercall: function execute error
```
## `getMiddleN(t, from_no, to_no)`
取数组指定行区间记录,一般先用SortByField排序,然后使用此函数
| 参数 | 类型 | 说明 |
| --------- | ------- | ---------------------- |
| `t` | array | 数据表 |
| `from_no` | integer | 起始行数:整数,从1开始 |
| `to_no` | integer | 截止行数:整数,从1开始 |
返回:array
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 4, 'c': 33), ('a': 5, 'c': 33));
return getMiddleN(t2, 2, 3);
// 输出:
// Execute script error at Line:2
// function:__main__:line 2:instruction:usercall: function:getMiddleN compile error or not found
// function:__main__:line 2:instruction:usercall: function execute error
```
## `getTopN(t, n)`
取数组前N行记录,一般先用SortByField排序,然后使用此函数
| 参数 | 类型 | 说明 |
| ---- | ------- | ------ |
| `t` | array | 数据表 |
| `n` | integer | 整数 |
返回:array
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 33));
return getTopN(t2, 2);
// 输出:
// Execute script error at Line:2
// function:__main__:line 2:instruction:usercall: function:getTopN compile error or not found
// function:__main__:line 2:instruction:usercall: function execute error
```
## `filterOneDimEx(t, method, v1, v2)`
范围取值(一维数组)从一个一维数组中按照取值范围返回对应的记录。
| 参数 | 类型 | 说明 |
| -------- | ------ | ---------------------------------------------- |
| `t` | array | 数据表 |
| `method` | string | >’,’<’,’<>’,’<=’,’>=’,’IN’,’IN2’,’IN3 |
| `v1` | real | 实数 |
| `v2` | real | 实数 |
返回:array
### 示例
```tsl
t := array(1, 2, 12, 3.7, 14);
return filterOneDimEx(t, 'IN', 2, 7);
// 输出:
// Execute script error at Line:2
// function:__main__:line 2:instruction:usercall: function:filterOneDimEx compile error or not found
// function:__main__:line 2:instruction:usercall: function execute error
```
## `getDistinctValue(t, f_name)`
得到指定列唯一值,返回值为一维数组
| 参数 | 类型 | 说明 |
| -------- | ------ | -------- |
| `t` | array | 数据表 |
| `f_name` | string | 指定列名 |
返回:array
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 43), ('a': 5, 'c': 53));
return getDistinctValue(t2, 'a');
// 输出:
// Execute script error at Line:2
// function:__main__:line 2:instruction:usercall: function:getDistinctValue compile error or not found
// function:__main__:line 2:instruction:usercall: function execute error
```
## `columnValue2(t, column_name)`
取得多个指定列的所有记录
| 参数 | 类型 | 说明 |
| ------------- | ------ | ------------------------ |
| `t` | array | 数据表,二维数组 |
| `column_name` | string | 指定多个字段,以分号分割 |
返回:array
### 示例
```tsl
t2 := array(('a': 2, 'b': 2, 'c': 13), ('a': 3, 'c': 33, 'b': 3), ('a': 3, 'b': 6, 'c': 43), ('a': 5, 'c': 53, 'b': 5));
return columnValue2(t2, 'a;c');
// 输出:
// Execute script error at Line:2
// function:__main__:line 2:instruction:usercall: function:columnValue2 compile error or not found
// function:__main__:line 2:instruction:usercall: function execute error
```
## `filterTable(t, v)`
从指标表中取以下列的值为v的数据:
| 参数 | 类型 | 说明 |
| ---- | ------- | ------------------ |
| `t` | array | 数组类型,数据 |
| `v` | integer | 报告期类型,报告期 |
返回:array
### 示例
```tsl
// 'SZ002664'在20211231时的分红送股数据
setSysParam(pn_stock(), 'SZ002664');
return filterTable(infoArray(18), 20211231);
// 输出:
// Execute script error at Line:3
// function:__main__:line 3:instruction:usercall: function:infoArray compile error or not found
// function:__main__:line 3:instruction:usercall: function execute error
```
## `getSubField(t, field)`
取表中某一字段的全部列值
| 参数 | 类型 | 说明 |
| ------- | ------ | ------------------- |
| `t` | array | 二维数组 |
| `field` | string | 列标名,字符串/整数 |
返回:array
### 示例
```tsl
a := array(('a': 8, 'b': 7), ('a': 6, 'b': 9));
return getSubField(a, 'a'); // 从a表中取第’a列’
// 输出:
// 示例包含说明文字,未作为可执行片段运行。
```
## `mergeArray(v1, v2, ...)`
多个数组进行合并
| 参数 | 类型 | 说明 |
| ----- | ----- | ---- |
| `v1` | array | |
| `v2` | array | |
| `...` | | |
返回:array
### 示例
```tsl
t1 := array(('b': 12, 'a': 1, 'c': 13, 'd': 'd'));
t2 := array(('a': 2, 'b': 22, 'c': 23, 'e': 'ee'));
t3 := array(('a': 2, 'b': 22, 'd': 23, 'e': 'ee'));
return mergeArray(t1, t2, t3); // 将数组t1,t2,t3合并
// 输出:
// 示例包含说明文字,未作为可执行片段运行。
```
## `intersectionPart(v, w)`
求交集
| 参数 | 类型 | 说明 |
| ---- | ----- | ---- |
| `v` | array | 数组 |
| `w` | array | 数组 |
返回:array
### 示例
```tsl
t1 := array(1.00, 3.00, 2.00, 9.00, 8.00);
t2 := array(3.00, 0.00, 7.00, 8.00, 1.00, 5.00);
return intersectionPart(t1, t2);
// 输出:
// Execute script error at Line:3
// function:__main__:line 3:instruction:usercall: function:intersectionPart compile error or not found
// function:__main__:line 3:instruction:usercall: function execute error
```
## `quickIntersectionPart(v, w)`
快速求交集
| 参数 | 类型 | 说明 |
| ---- | ----- | ---- |
| `v` | array | 数组 |
| `w` | array | 数组 |
返回:array
### 示例
```tsl
t1 := array(1.00, 3.00, 2.00, 9.00, 8.00);
t2 := array(3.00, 0.00, 7.00, 8.00, 1.00, 5.00);
return intersectionPart(t1, t2);
// 输出:
// Execute script error at Line:3
// function:__main__:line 3:instruction:usercall: function:intersectionPart compile error or not found
// function:__main__:line 3:instruction:usercall: function execute error
```
## `distinctStr(t)`
去掉序列中的重复元素
| 参数 | 类型 | 说明 |
| ---- | ----- | ------------------- |
| `t` | array | 一维字符串/数字数组 |
返回:array
### 示例
```tsl
a := array('w', 'd', 'f', 'd', 'e');
return distinctStr(a); // 保留不相同的,相同的只保留一个
// 输出:
// 示例包含说明文字,未作为可执行片段运行。
```
## `sumValueByColumn(t, f_name)`
指定列中所有实数的和
| 参数 | 类型 | 说明 |
| -------- | ------ | -------- |
| `t` | array | 数据表 |
| `f_name` | string | 指定字段 |
返回:real
### 示例
```tsl
t1 := array(('a': 1, 'b': 4, 'c': 9), ('a': 7, 'b': 8, 'c': 5));
return sumValueByColumn(t1, 'b');
// 结果:12
```
## `sumValueByColumn2(tb, column_name, from_row, to_row)`
求指定列中指定多行的和
| 参数 | 类型 | 说明 |
| ------------- | ------- | ------------------------------- |
| `tb` | array | 数据表 |
| `column_name` | string | 指定字段 |
| `from_row` | integer | 指定计算起始行索引号(从0开始) |
| `to_row` | integer | 指定计算结束行索引号(从0开始) |
返回:real
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 43), ('a': 5, 'c': 53));
return sumValueByColumn2(t2, 'c', 1, 2);
// 结果:76
```
## `sumValueByRow(tb, row_index)`
求指定行的和
| 参数 | 类型 | 说明 |
| ----------- | ------- | --------------------------- |
| `tb` | array | 数据表 |
| `row_index` | integer | 指定计算行索引号(从0开始) |
返回:real
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 43), ('a': 5, 'c': 53));
return sumValueByRow(t2, 2);
// 结果:46
```
## `sumValueByRow2(tb, row_index, from_col, to_col)`
求指定行中指定多列的和
| 参数 | 类型 | 说明 |
| ----------- | ------- | ------------------------------- |
| `tb` | array | 数据表 |
| `row_index` | integer | 指定计算行索引号(从0开始) |
| `from_col` | integer | 指定计算起始列索引号(从0开始) |
| `to_col` | integer | 指定计算起始列索引号(从0开始) |
返回:real
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 43), ('a': 5, 'c': 53));
return sumValueByRow2(t2, 1, 0, 1);
// 结果:36
```
## `maxValueByColumn(t, f_name)`
求指定列中的最大值
| 参数 | 类型 | 说明 |
| -------- | ------ | -------- |
| `t` | array | 数据表 |
| `f_name` | string | 指定列名 |
返回:real
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 43), ('a': 5, 'c': 53));
return maxValueByColumn(t2, 'c');
// 结果:53
```
## `minValueByColumn(t, f_name)`
求指定中的最小值
| 参数 | 类型 | 说明 |
| -------- | ------ | -------- |
| `t` | array | 数据表 |
| `f_name` | string | 指定列名 |
返回:real
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 43), ('a': 5, 'c': 53));
return minValueByColumn(t2, 'c');
// 结果:13
```
## `averageValueByColumn(t, f_name, from_row, to_row)`
求在指定多行中指定列的平均值
| 参数 | 类型 | 说明 |
| ---------- | ------- | --------------------------- |
| `t` | array | 数据表 |
| `f_name` | string | 指定列名 |
| `from_row` | integer | 计算起始行索引号(从0开始) |
| `to_row` | integer | 计算结束行索引号(从0开始) |
返回:real
### 示例
```tsl
t2 := array(('a': 2, 'c': 13), ('a': 3, 'c': 33), ('a': 3, 'c': 43), ('a': 5, 'c': 53));
return averageValueByColumn(t2, 'c', 1, 3);
// 结果:43
```
## `renameField(t, old_field, new_field)`
修改指定字段的名称
| 参数 | 类型 | 说明 |
| ----------- | ------ | -------------------- |
| `t` | array | 指定数组,数据表 |
| `old_field` | string | 原来指定列名,字符串 |
| `new_field` | string | 新列名,字符串 |
返回:bool
### 示例
```tsl
t1 := array(('a': 1, 'b': 4, 'c': 9), ('a': 7, 'b': 8, 'c': 5));
return renameField(t1, 'a', 'aaa'); // 将t1中的字段’a’改为’aaa’
// 结果:1
```
## `normalTabletoStrSubscript(t, key_field)`
索引下标数组-->字符串下标数组。将keyfield列的值变为行标。
| 参数 | 类型 | 说明 |
| ----------- | ------ | ------------ |
| `t` | array | 数据表类型 |
| `key_field` | string | 字符串,列名 |
返回:any
### 示例
```tsl
s := nDay(10, 'time', dateToStr(sp_time()), 'close', close());
return normalTabletoStrSubscript(s, 'time');
// 把 time列的数据变为行标
---变为--》
```
## `show3DTable(t, key_field, obsolete_fields, ntype)`
特殊函数,平台功能性函数,一般用户不使用。用于三维表格显示格式转换,其中t为原数据,KeyField为需要转置的字段,ObsoleteFields为需要隐藏的字段,NType决定显示格式。
| 参数 | 类型 | 说明 |
| ----------------- | ------- | ---------------------------- |
| `t` | array | 数据表类型,原数据 |
| `key_field` | string | 字符串,要显示倒置的关键字段 |
| `obsolete_fields` | string | 字符串,不显示的字段(;分割) |
| `ntype` | integer | 用户自定义,三维表格显示格式 |
返回:array
### 示例
```tsl
// 生成数据表t
t := array(("代码": "SH600006", "名称": "东风汽车", "2004.10-12@主营业务收入": 151953.06, "2004.10-12@主营业务利润": 30559.66, "2004.10-12@营业费用": 10112.75, "2004.10-12@管理费用": 10666.36, "2004.10-12@财务费用": -894.46, "2004.10-12@营业利润": 10693.23, "2004.10-12@投资收益": -151.01, "2004.10-12@利润总额": 9904.7, "2004.10-12@所得税": 2413.81, "2004.10-12@净利润": 7873.08, "2004.10-12@货币资金": -11664.28, "2004.10-12@短期投资": -5370.7, "2004.7-9@主营业务收入": 167855.56, "2004.7-9@主营业务利润": 31127.95, "2004.7-9@营业费用": 4452.79, "2004.7-9@管理费用": 10541.15, "2004.7-9@财务费用": -1013.26, "2004.7-9@营业利润": 17162.48, "2004.7-9@投资收益": 150.81, "2004.7-9@利润总额": 17246.26, "2004.7-9@所得税": 2629.5, "2004.7-9@净利润": 14574.03, "2004.7-9@货币资金": 532.5, "2004.7-9@短期投资": 4962.47), ("代码": "SH600007", "名称": "中国国贸", "2004.10-12@主营业务收入": 19715.3, "2004.10-12@主营业务利润": 10383.2, "2004.10-12@营业费用": 238.4, "2004.10-12@管理费用": 1422.7, "2004.10-12@财务费用": 1304.4, "2004.10-12@营业利润": 7417.7, "2004.10-12@投资收益": 81.1, "2004.10-12@利润总额": 6404.6, "2004.10-12@所得税": 2433.4, "2004.10-12@净利润": 3971.2, "2004.10-12@货币资金": 2964.5, "2004.10-12@短期投资": 0.00, "2004.7-9@主营业务收入": 17727.7, "2004.7-9@主营业务利润": 9989.1, "2004.7-9@营业费用": 165.5, "2004.7-9@管理费用": 1151.3, "2004.7-9@财务费用": -18.2, "2004.7-9@营业利润": 8690.5, "2004.7-9@投资收益": 186.2, "2004.7-9@利润总额": 9208.6, "2004.7-9@所得税": 2977.1, "2004.7-9@净利润": 6231.5, "2004.7-9@货币资金": -8101.2, "2004.7-9@短期投资": 0.00), ("代码": "SH600004", "名称": "白云机场", "2004.7-9@主营业务收入": 37934.65, "2004.7-9@主营业务利润": 15725.54, "2004.7-9@营业费用": 2623.82, "2004.7-9@管理费用": 4662.1, "2004.7-9@财务费用": 1789.5, "2004.7-9@营业利润": 6650.11, "2004.7-9@投资收益": -15.38, "2004.7-9@利润总额": 6685.16, "2004.7-9@所得税": 2350.15, "2004.7-9@净利润": 4000.51, "2004.7-9@货币资金": -5054.06, "2004.7-9@短期投资": 101.00));
return show3DTable(t, '名称', '代码', 3);
// 返回:
```
## `show2DTable(t, key_field, obsolete_fields, ntype)`
特殊函数,平台功能性函数,一般用户不使用。二位表格显示格式转换,其中t为原数据,KeyField为需要转置的字段,ObsoleteFields为需要隐藏的字段,NType决定显示格式。
| 参数 | 类型 | 说明 |
| ----------------- | ------- | ---------------------------- |
| `t` | array | 数据表类型,原数据 |
| `key_field` | string | 字符串,要显示倒置的关键字段 |
| `obsolete_fields` | string | 字符串,不显示的字段(;分割) |
| `ntype` | integer | 用户自定义,二维表格显示格式 |
返回:array
### 示例
```tsl
// 生成数据表t
t := array(("代码": "SH600006", "名称": "东风汽车", "主营业务收入": 151953.06, "主营业务利润": 30559.66, "营业费用": 10112.75, "管理费用": 10666.36, "财务费用": -894.46, "营业利润": 10693.23, "投资收益": -151.01, "利润总额": 9904.7, "所得税": 2413.81, "净利润": 7873.08, "货币资金": -11664.28, "短期投资": -5370.7, "主营业务收入": 167855.56, "主营业务利润": 31127.95, "营业费用": 4452.79, "管理费用": 10541.15, "财务费用": -1013.26, "营业利润": 17162.48, "投资收益": 150.81, "利润总额": 17246.26, "所得税": 2629.5, "净利润": 14574.03, "货币资金": 532.5, "短期投资": 4962.47), ("代码": "SH600007", "名称": "中国国贸", "主营业务收入": 19715.3, "主营业务利润": 10383.2, "营业费用": 238.4, "管理费用": 1422.7, "财务费用": 1304.4, "营业利润": 7417.7, "投资收益": 81.1, "利润总额": 6404.6, "所得税": 2433.4, "净利润": 3971.2, "货币资金": 2964.5, "短期投资": 0.00, "主营业务收入": 17727.7, "主营业务利润": 9989.1, "营业费用": 165.5, "管理费用": 1151.3, "财务费用": -18.2, "营业利润": 8690.5, "投资收益": 186.2, "利润总额": 9208.6, "所得税": 2977.1, "净利润": 6231.5, "货币资金": -8101.2, "短期投资": 0.00));
return show2DTable(t, '名称', '代码', 2);
// 返回:
```
## `showTableByField(t, field_arr)`
显示数据表t的部分字段数据,字段在FieldArr的数组里。
| 参数 | 类型 | 说明 |
| ----------- | ----- | ---------------------- |
| `t` | array | 数据表类型,数据 |
| `field_arr` | array | 一维数组,要显示的字段 |
返回:array
### 示例
```tsl
arr := array((1, 2, 3, 4, 5), (2, 3, 4, 5, 6), (3, 4, 5, 6, 7), (4, 5, 6, 7, 8));
return showTableByField(arr, array(1, 2, 3));
// 返回:
```
## `showTableByInverse(t, key_field, field_arr, show_number)`
数据表t转置,其中KeyField为列名,该列的数据转置后作为列标名,FieldARR为需要显示的字段,ShowNumber表示显示原数据keyfield行(转置后列)的数量。
| 参数 | 类型 | 说明 |
| ------------- | ------- | ------------------------------------------------ |
| `t` | array | 数据表类型,数据 |
| `key_field` | string | 字符串,转置后用作列标的值的列名 |
| `field_arr` | array | 数组,要显示的字段列表,给非数组则显示所有字段。 |
| `show_number` | integer | 整数,显示个数 |
返回:array
### 示例
```tsl
// 生成数据表t
t := array(("代码": "SH600006", "名称": "东风汽车", "主营业务收入": 151953.06, "主营业务利润": 30559.66, "营业费用": 10112.75, "管理费用": 10666.36, "财务费用": -894.46, "营业利润": 10693.23, "投资收益": -151.01, "利润总额": 9904.7, "所得税": 2413.81, "净利润": 7873.08, "货币资金": -11664.28, "短期投资": -5370.7, "主营业务收入": 167855.56, "主营业务利润": 31127.95, "营业费用": 4452.79, "管理费用": 10541.15, "财务费用": -1013.26, "营业利润": 17162.48, "投资收益": 150.81, "利润总额": 17246.26, "所得税": 2629.5, "净利润": 14574.03, "货币资金": 532.5, "短期投资": 4962.47), ("代码": "SH600007", "名称": "中国国贸", "主营业务收入": 19715.3, "主营业务利润": 10383.2, "营业费用": 238.4, "管理费用": 1422.7, "财务费用": 1304.4, "营业利润": 7417.7, "投资收益": 81.1, "利润总额": 6404.6, "所得税": 2433.4, "净利润": 3971.2, "货币资金": 2964.5, "短期投资": 0.00, "主营业务收入": 17727.7, "主营业务利润": 9989.1, "营业费用": 165.5, "管理费用": 1151.3, "财务费用": -18.2, "营业利润": 8690.5, "投资收益": 186.2, "利润总额": 9208.6, "所得税": 2977.1, "净利润": 6231.5, "货币资金": -8101.2, "短期投资": 0.00));
return showTableByInverse(t, '代码', '', 2);
// 返回:
```
## `quickRecordExist(v, x)`
记录是否存在(原数组若为纯字符串数组则必须为有序列),返回记录所在行的序号,序号是从0开始原数组必须为有序表
| 参数 | 类型 | 说明 |
| ---- | ------ | ----------- |
| `v` | array | 一维数组 |
| `x` | string | 字符串/数字 |
返回:integer
### 示例
```tsl
t := array('a', 'c', 'd');
return quickRecordExist(t, 'd');
// 结果:2
```
## `rotateTable(data)`
旋转表
| 参数 | 类型 | 说明 |
| ------ | ----- | ---------------- |
| `data` | array | 数据表,二维数组 |
返回:array
### 示例
```tsl
t := array(('a': 1, 'b': 4), ('a': 7, 'b': 8), ('a': 2, 'b': 4));
return rotateTable(t);
// 输出:
// Execute script error at Line:2
// function:__main__:line 2:instruction:usercall: function:rotateTable compile error or not found
// function:__main__:line 2:instruction:usercall: function execute error
```
## `footerValue(t, from_col, tocol, average_col_field, _type)`
数组t从Fromcol列到ToCol列对每列求算术平均或者累计求和。
| 参数 | 类型 | 说明 |
| ------------------- | ------- | ------------------ |
| `t` | array | 数据表类型,数据表 |
| `from_col` | integer | :整数,起始序号 |
| `tocol` | integer | 整数,截止序号 |
| `average_col_field` | string | 字符串,列名 |
| `_type` | any | 用户自定义 |
返回:array
### 示例
```tsl
s := array(array(1, 2, 3, 4, 5),
array(2, 3, 4, 5, 6),
array(3, 4, 5, 6, 7));
return footerValue(s, 1, 3, '', 1);
// 返回:
```
## `footerAverage(t, from_col, tocol, average_col_field)`
调用FooterValue对数组指定列求算术平均。
| 参数 | 类型 | 说明 |
| ------------------- | ------- | -------------------------- |
| `t` | array | 数据表类型,数据表 |
| `from_col` | integer | :整数,起始序号 |
| `tocol` | integer | 整数,截止序号 |
| `average_col_field` | string | 字符串,显示“平均”的列字段 |
返回:array
### 示例
```tsl
s := array(array(1, 2, 3, 4, 5),
array(2, 3, 4, 5, 6),
array(3, 4, 5, 6, 7));
return footerAverage(s, 1, 3, '');
// 返回:
```
## `footerSum(t, from_col, tocol, average_col_field)`
调用FooterValue对数组指定列求算术和。
| 参数 | 类型 | 说明 |
| ------------------- | ------- | -------------------------- |
| `t` | array | 数据表类型,数据表 |
| `from_col` | integer | :整数,起始序号 |
| `tocol` | integer | 整数,截止序号 |
| `average_col_field` | string | 字符串,显示“平均”的列字段 |
返回:array
### 示例
```tsl
s := array(array(1, 2, 3, 4, 5),
array(2, 3, 4, 5, 6),
array(3, 4, 5, 6, 7));
return footerAverage(s, 1, 3, '');
// 返回:
```
## `setRowDefaultValue(t, n, value)`
将数组t的第N行由所有值变更为Value。
| 参数 | 类型 | 说明 |
| ------- | ------- | ------------------ |
| `t` | array | 数据表类型,数据表 |
| `n` | integer | 整数,行号 |
| `value` | string | 字符串,要设置的值 |
返回:array
### 示例
```tsl
s := array(array(1, 2, 3, 4, 5),
array(2, 3, 4, 5, 6),
array(3, 4, 5, 6));
setRowDefaultValue(s, 2, 'wo');
return s;
// 返回:
```
## `inverseTable(t)`
将数组t去掉第一列转置,转置后原数组t的第一列作为行标。
| 参数 | 类型 | 说明 |
| ---- | ----- | ---------- |
| `t` | array | 数据表类型 |
返回:array
### 示例
```tsl
s := array(array('A': 'a', 'B': 'b', 'C': 'c', 'D': 'd', 'e': 'e'),
array('A': 2, 'B': 3, 'C': 4, 'D': 5, 'e': 6),
array('A': 3, 'B': 4, 'C': 5, 'D': 6, 'e': 7),);
return inverseTable(s);
// 返回:
```
## `tableSelect(table, condition, reps)`
表格查询。从t中查询满足Condition的子表
| 参数 | 类型 | 说明 |
| ----------- | ------ | ------ |
| `table` | any | 数据表 |
| `condition` | string | 字符串 |
| `reps` | string | 字符串 |
返回:array
### 示例
```tsl
t := `array('a': (1, 2, 3, 4), 'b': (2, 3, 4, 5), 'c': (3, 4, 5, 6), 'd': (4, 5, 6, 7), 'e': (5, 6, 7, 8), 'f': (7, 8, 9, 10));
return tableSelect(t, "~['b']=2", '~'); // 返回t中字段’b=2的子表
// 返回:
```
## `getSubTableFreeParam()`
取子表,系统第二个到最个一个参数为字段序列,取第一个参数中字段与字段序列匹配的列数据。
返回:array
### 示例
```tsl
return getSubTableFreeParam(); // 之前在系统参数中已经设置好第一个参数s=array(array('s':1,'w':2,'sl':3), array('s':2,'w':3,'sl':4), array('s':3,'w':4,'sl':5)),第二三个参数’s,w’。
// 返回:
```