Collect 是离线数据服务,提供接口采集数据、并将数据推送给 Mapping 拼接马赛克。Collect 离线数据采集前,要先创建采集数据类型;在 Block 模式下,建立一个项目就是创建一个离线数据类型。
离线数据脚本
离线数据脚本是采集数据的变量配置脚本。创建一个离线数据项目,采集的数据可以是单值或者多值,一行脚本则指定一个值。
[
{
"key": "length",
"label_en": "Label_En",
"label_loc": "长度",
"type": "int",
"unit": "米",
"source": "API",
"args": {}
}
]
- key 是数据的键,自定义填写,一般是英文与数字标识;
- label_en 是英文标签;
- label_loc 是中文标签;
- type 是离线数据类型,比如Float(小数)、Integer(整数)、String(字符)等;
- unit 是数据的单位,比如℃、m、kpa等;
- source 是数据的来源,目前有 API(手工API录入), STT(统计计算), INDASS(Indass结果);
- args 是数据来源需要配置的一些参数,当 source 是 API 时不需要填,其他来源需要配置一些特定的参数;
source 与 args 字段说明
当 source 不是 API 手工录入时,需要配置特定来源的参数
当 source 为 STT 时,args 需要 4 个字段:
- type 定义获取统计值的方式,可选
cycle
或event
,cycle
为定时获取对应统计值并录入,event
为监听对应事件,事件触发时将相应统计值录入。 - cycle 当 type 为 cycle 时必填,为定时获取的周期,格式为形如
12h12m12s
的字符串,表示12小时12分钟12秒。 - object_id 统计项目对应的对象 id
- statistics_type 统计计算类型,可以选择
statistics
或者calculate
- statistics_id 统计项目id
例子:
{
"type": "cycle",
"cycle": "5m",
"object_id": "OBJ1",
"statistics_type": "statistics", // statistics:统计 calculate:计算
"statistics_id": "STATISTICS1"
}
当 source 为 INDASS 时,args 需要 4 个字段:
- type 同上
- cycle 同上
- block_id indass 的 block_id,例如 index, map 等等
- object_id 对象id
- project_id indass 项目id
- data_key indass 结果是一组键值对,此项决定获取这组结果中的哪一个值录入
例子:
{
"type": "cycle",
"cycle": "5m",
"block_id": "index",
"object_id": "OBJ1",
"porject_id": "index1",
"data_key": "index_change_rate"
}
脚本示例
[
{
"key": "length",
"label_en": "Label_En",
"label_loc": "长度",
"type": "int",
"unit": "米",
"source": "API",
"args": {}
},
{
"key": "how_many",
"label_en":"Label_En",
"label_loc":"几个",
"type":"int",
"unit":"个",
"source":"API",
"args":{}
},
{
"key":"indass_index_value",
"label_en":"Label_En",
"label_loc":"indass计算值",
"type":"float",
"unit":"s",
"source":"INDASS",
"args": {
"object_id": "OBJ1243475500003",
"block_id": "index",
"project_id": "test",
"data_key": "index_change_rate",
"type": "cycle",
"cycle": "5s"
}
}
]
通过 API 进行数据采集
首先需要配置 Collect 的项目,创建一个新的离线项目,按脚本格式配置好,并启动对应项目。
数据采集接口会校验 collect_id 是否正确,对应项目是否启动。
value 为一组数据值,value 中的 key 需要与对应项目脚本中的 key 一一对应,脚本中不存在的数据会被丢弃。
数据采集接口参数示例如下:
{
"action": "add_collect_value",
"actionid": "",
"name": "多数据采集",
"description": "",
"collect_id": "COL1332295612308",
"object_id": "OBJ1001",
"value": {
"temp": 88.5,
"pressure": 202
},
"file": "",
"collect_at": "2021-03-03 10:88:10",
"collector": "mixuser",
"reference": ""
}
Collect 接口
获取离线项目列表
获取离线项目列表
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | get_project_list | 方法名 |
actionid | 否 | String | 活动标识 | |
page_index | 否 | int | 页数,不传则获取所有记录 | |
page_size | 否 | int | 页大小,不传则获取所有记录 | |
where_and | 否 | String | and 条件 | |
where_or | 否 | String | or 条件 | |
where_in | 否 | String | in 条件 |
示例
{
"action":"get_project_list",
"page_index": 1,
"page_size": 20,
"where_and": "",
"where_or": "",
"where_in": "",
}
响应
{
"resp": "get_project_list",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"page_index": 1,
"page_size": 20,
"total_pages": 0,
"total_records": 0,
"data": [
{
"id": 1969,
"uid": "COL1472557300005",
"name": "042701",
"description": "",
"block_id": "",
"class_id": "",
"is_active": 0,
"option": null,
"script": [
{
"args": [],
"key": "1#Temp",
"label_en": "",
"label_loc": "1机组温度",
"source": "API",
"type": "Float",
"unit": ""
},
{
"args": [],
"key": "2#Temp",
"label_en": "",
"label_loc": "2机组温度",
"source": "API",
"type": "Float",
"unit": ""
}
],
"created": "2021-04-27T15:28:25+08:00",
"last_modified": "",
"last_modified_by": 0,
"is_available": 1
}
]
}
}
获取离线项目
获取离线项目
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | get_project_item | 方法名 |
actionid | 否 | String | 活动标识 | |
uid | 是 | String | 项目uid |
示例
{
"action":"get_project_item",
"uid": "COL1"
}
响应
{
"resp": "get_project_item",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"id": 1969,
"uid": "COL1472557300005",
"name": "042701",
"description": "",
"block_id": "",
"class_id": "",
"is_active": 0,
"option": null,
"script": [
{
"args": [],
"key": "1#Temp",
"label_en": "",
"label_loc": "1机组温度",
"source": "API",
"type": "Float",
"unit": ""
},
{
"args": [],
"key": "2#Temp",
"label_en": "",
"label_loc": "2机组温度",
"source": "API",
"type": "Float",
"unit": ""
}
],
"created": "2021-04-27T15:28:25+08:00",
"last_modified": "",
"last_modified_by": 0,
"is_available": 1
}
}
创建离线项目
创建离线项目
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | create_project | 方法名 |
actionid | 否 | String | 活动标识 | |
name | 是 | String | 项目名称 | |
description | 否 | String | 项目描述 | |
script | 是 | List | 项目脚本 |
示例
{
"action": "create_project",
"name": "离线采集1",
"description": "离线采集1",
"script": [
{
"key": "length", // 离线key
"label_en": "Label_En", // 英文标签
"label_loc": "长度", // 中文标签
"type": "Integer", // 类型,可选值有 Integer Float String Bool
"unit": "米", // 单位
"source": "API", // 数据源
"args": {} // 数据源具体参数
}
]
}
响应
{
"resp": "create_project",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"uid": "COL1472557300005"
}
}
更新离线项目
更新离线项目
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | update_project | 方法名 |
actionid | 否 | String | 活动标识 | |
uid | 是 | String | 项目uid | |
name | 否 | String | 项目名称 | |
description | 否 | String | 项目描述 | |
script | 否 | List | 项目脚本 |
示例
{
"action": "update_project",
"uid": "COL1",
"name": "edit",
"description": "edit",
"script": [
{
"key": "length",
"label_en": "Label_En",
"label_loc": "修改标签",
"type": "int",
"unit": "米",
"source": "API",
"args": {}
}
]
}
响应
{
"resp": "update_project",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"uid": "COL1472557300005"
}
}
删除离线项目
删除离线项目
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | delete_project | 方法名 |
actionid | 否 | String | 活动标识 | |
uid | 是 | String | 项目uid |
示例
{
"action": "delete_project",
"uid": "COL1472557300005"
}
响应
{
"resp": "delete_project",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"uid": "COL1472557300005"
}
}
启动离线项目
启动离线项目
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | start_project | 方法名 |
actionid | 否 | String | 活动标识 | |
uid | 是 | String | 项目uid |
示例
{
"action": "start_project",
"uid": "COL1472557300005"
}
响应
{
"resp": "start_project",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"uid": "COL1472557300005"
}
}
停止离线项目
停止离线项目
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | stop_project | 方法名 |
actionid | 否 | String | 活动标识 | |
uid | 是 | String | 项目uid |
示例
{
"action": "stop_project",
"uid": "COL1"
}
响应
{
"resp": "stop_project",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"uid": "COL1472557300005"
}
}
添加离线数据
添加上报一条离线数据,离线ID对应的项目需要启动并且上报的 value 中的 key 与对应项目配置的脚本匹配
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | add_collect_value | 方法名 |
actionid | 否 | String | 活动标识 | |
name | 是 | String | 名称 | |
description | 否 | String | 描述 | |
collect_id | 是 | String | 离线项目id | |
object_id | 是 | String | 对象id | |
value | 是 | Object | 数据kv对 | |
file | 否 | String | 文件url | |
collector | 否 | String | 上传人 | |
reference | 否 | String | 描述 |
示例
{
"action": "add_collect_value",
"actionid": "",
"name": "数据采集1",
"description": "",
"collect_id": "COL1310231900002",
"object_id": "OBJ1243475500001",
"value": {
"temp": 88.5,
"pressure": 202
},
"file": "",
"collector": "mixuser",
"reference": ""
}
响应
{
"resp": "add_collect_value",
"code": 200,
"msg": "成功",
"result": {
"collect_id": "COL1310231900002",
"name": "数据采集1",
"object_id": "OBJ1243475500001",
"value": {
"temp": 88.5,
"pressure": 202,
"object_id": "OBJ1243475500001"
}
}
}
获取最新离线数据
根据离线ID和对象ID获取最新一条API类型手工上报的离线数据
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | get_last_collect_value | 方法名 |
actionid | 否 | String | 活动标识 | |
collect_id | 是 | String | 离线项目id | |
object_id | 是 | String | 对象id |
示例
{
"action": "get_last_collect_value",
"collect_id": "COL1405447400006",
"object_id": "OBJ1403630800003"
}
响应
{
"resp": "get_last_collect_value",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"id": 95,
"uid": "COLVAL1432906700001",
"name": "a",
"description": "",
"collect_id": "COL1405447400006",
"object_id": "OBJ1403630800003",
"value": {
"aa": true,
"aa2": 12313
},
"file": "",
"collector": "admin",
"collect_at": "2021-04-23 15:56:29",
"reference": "",
"created": "2021-04-23 15:56:29",
"is_available": 1
}
}
获取离线值历史列表
获取历史的离线值
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | get_collect_value_list | 方法名 |
actionid | 否 | String | 活动标识 | |
page_index | 否 | int | 页数,不传则获取所有记录 | |
page_size | 否 | int | 页大小,不传则获取所有记录 | |
where_and | 否 | String | and 条件 | |
where_or | 否 | String | or 条件 | |
where_in | 否 | String | in 条件 |
示例
{
"action": "get_collect_value_list",
"page_index": 1,
"page_size": 20,
"where_and": "",
"where_or": "",
"where_in": "",
"order_by": "",
}
响应
{
"resp": "get_collect_value_list",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"page_index": 1,
"page_size": 20,
"total_pages": 0,
"total_records": 1,
"data": [
{
"id": 95,
"uid": "COLVAL1432906700001",
"name": "a",
"description": "",
"collect_id": "COL1405447400006",
"object_id": "OBJ1403630800003",
"value": {
"aa": true,
"aa2": 12313
},
"file": "",
"collector": "admin",
"collect_at": "2021-04-23 15:56:29",
"reference": "",
"created": "2021-04-23 15:56:29",
"is_available": 1
}
]
}
}
UID获取指定离线值
根据离线值ID获取单条离线值记录
参数
参数名称 | 是否必选 | 数据类型 | 数据约束 | 描述 |
---|---|---|---|---|
action | 是 | String | get_collect_value | 方法名 |
actionid | 否 | String | 活动标识 | |
uid | 是 | String | 离线值uid |
示例
{
"action": "get_collect_value",
"uid": "COLVAL1432906700001"
}
响应
{
"resp": "get_collect_value",
"actionid": "",
"code": 200,
"msg": "成功",
"result": {
"id": 95,
"uid": "COLVAL1432906700001",
"name": "a",
"description": "",
"collect_id": "COL1405447400006",
"object_id": "OBJ1403630800003",
"value": {
"aa": true,
"aa2": 12313
},
"file": "",
"collector": "admin",
"collect_at": "2021-04-23 15:56:29",
"reference": "",
"created": "2021-04-23 15:56:29",
"is_available": 1
}
}
Collect event 说明
离线值更新事件
{
"event": {
"event": "collect_add_value_event",
"block": "collect",
"uniqueid": "COLEVT1",
"datetime": "2006-01-02 15:04:05",
"collect_id": " COLVAL1303892400001",
"object_id": "OBJ1243475500001",
"name": "test",
"value": {"Tem":32,"num2":64},
}
}
文档更新时间: 2024-07-12 16:12 作者:Mixiot