与 Seeq 的集成

Seeq 是制造业和工业互联网(IIOT)高级分析软件。Seeq 支持在工艺制造组织中使用机器学习创新的新功能。这些功能使组织能够将自己或第三方机器学习算法部署到前线流程工程师和主题专家使用的高级分析应用程序,从而使单个数据科学家的努力扩展到许多前线员工。

通过 TDengine Java connector, Seeq 可以轻松支持查询 TDengine 提供的时序数据,并提供数据展现、分析、预测等功能。

Seeq 安装方法

从 Seeq 官网下载相关软件,例如 Seeq Server 和 Seeq Data Lab 等。Seeq Data Lab 需要安装在和 Seeq Server 不同的服务器上,并通过配置和 Seeq Server 互联。详细安装配置指令参见Seeq 知识库。

TDengine 本地实例安装方法

请参考官网文档。

TDengine Cloud 访问方法

如果使用 Seeq 连接 TDengine Cloud,请在 <https://cloud.taosdata.com> 申请帐号并登录查看如何访问 TDengine Cloud。

配置 Seeq 访问 TDengine

  1. 查看 data 存储位置
1. sudo seeq config get Folders/Data
  1. 从 maven.org 下载 TDengine Java connector 包,目前最新版本为3.2.5,并拷贝至 data 存储位置的 plugins\lib 中。
  2. 重新启动 seeq server
1. sudo seeq restart
  1. 输入 License

使用浏览器访问 ip:34216 并按照说明输入 license。

使用 Seeq 分析 TDengine 时序数据

本章节演示如何使用 Seeq 软件配合 TDengine 进行时序数据分析。

场景介绍

示例场景为一个电力系统,用户每天从电站仪表收集用电量数据,并将其存储在 TDengine 集群中。现在用户想要预测电力消耗将会如何发展,并购买更多设备来支持它。用户电力消耗随着每月订单变化而不同,另外考虑到季节变化,电力消耗量会有所不同。这个城市位于北半球,所以在夏天会使用更多的电力。我们模拟数据来反映这些假定。

数据 Schema

1. CREATE STABLE meters (ts TIMESTAMP, num INT, temperature FLOAT, goods INT) TAGS (device NCHAR(20));
2. CREATE TABLE goods (ts1 TIMESTAMP, ts2 TIMESTAMP, goods FLOAT);

Seeq demo schema

构造数据方法

1. python mockdata.py
2. taos -s "insert into power.goods select _wstart, _wstart + 10d, avg(goods) from power.meters interval(10d);"

源代码托管在GitHub 仓库。

使用 Seeq 进行数据分析

配置数据源(Data Source)

使用 Seeq 管理员角色的帐号登录,并新建数据源。

  • Power
1. {
2. "QueryDefinitions": [
3. {
4. "Name": "PowerNum",
5. "Type": "SIGNAL",
6. "Sql": "SELECT  ts, num FROM meters",
7. "Enabled": true,
8. "TestMode": false,
9. "TestQueriesDuringSync": true,
10. "InProgressCapsulesEnabled": false,
11. "Variables": null,
12. "Properties": [
13. {
14. "Name": "Name",
15. "Value": "Num",
16. "Sql": null,
17. "Uom": "string"
18. },
19. {
20. "Name": "Interpolation Method",
21. "Value": "linear",
22. "Sql": null,
23. "Uom": "string"
24. },
25. {
26. "Name": "Maximum Interpolation",
27. "Value": "2day",
28. "Sql": null,
29. "Uom": "string"
30. }
31. ],
32. "CapsuleProperties": null
33. }
34. ],
35. "Type": "GENERIC",
36. "Hostname": null,
37. "Port": 0,
38. "DatabaseName": null,
39. "Username": "root",
40. "Password": "taosdata",
41. "InitialSql": null,
42. "TimeZone": null,
43. "PrintRows": false,
44. "UseWindowsAuth": false,
45. "SqlFetchBatchSize": 100000,
46. "UseSSL": false,
47. "JdbcProperties": null,
48. "GenericDatabaseConfig": {
49. "DatabaseJdbcUrl": "jdbc:TAOS-RS://127.0.0.1:6041/power?user=root&password=taosdata",
50. "SqlDriverClassName": "com.taosdata.jdbc.rs.RestfulDriver",
51. "ResolutionInNanoseconds": 1000,
52. "ZonedColumnTypes": []
53. }
54. }
  • Goods
1. {
2. "QueryDefinitions": [
3. {
4. "Name": "PowerGoods",
5. "Type": "CONDITION",
6. "Sql": "SELECT ts1, ts2, goods FROM power.goods",
7. "Enabled": true,
8. "TestMode": false,
9. "TestQueriesDuringSync": true,
10. "InProgressCapsulesEnabled": false,
11. "Variables": null,
12. "Properties": [
13. {
14. "Name": "Name",
15. "Value": "Goods",
16. "Sql": null,
17. "Uom": "string"
18. },
19. {
20. "Name": "Maximum Duration",
21. "Value": "10days",
22. "Sql": null,
23. "Uom": "string"
24. }
25. ],
26. "CapsuleProperties": [
27. {
28. "Name": "goods",
29. "Value": "${columnResult}",
30. "Column": "goods",
31. "Uom": "string"
32. }
33. ]
34. }
35. ],
36. "Type": "GENERIC",
37. "Hostname": null,
38. "Port": 0,
39. "DatabaseName": null,
40. "Username": "root",
41. "Password": "taosdata",
42. "InitialSql": null,
43. "TimeZone": null,
44. "PrintRows": false,
45. "UseWindowsAuth": false,
46. "SqlFetchBatchSize": 100000,
47. "UseSSL": false,
48. "JdbcProperties": null,
49. "GenericDatabaseConfig": {
50. "DatabaseJdbcUrl": "jdbc:TAOS-RS://127.0.0.1:6041/power?user=root&password=taosdata",
51. "SqlDriverClassName": "com.taosdata.jdbc.rs.RestfulDriver",
52. "ResolutionInNanoseconds": 1000,
53. "ZonedColumnTypes": []
54. }
55. }
  • Temperature
1. {
2. "QueryDefinitions": [
3. {
4. "Name": "PowerNum",
5. "Type": "SIGNAL",
6. "Sql": "SELECT  ts, temperature FROM meters",
7. "Enabled": true,
8. "TestMode": false,
9. "TestQueriesDuringSync": true,
10. "InProgressCapsulesEnabled": false,
11. "Variables": null,
12. "Properties": [
13. {
14. "Name": "Name",
15. "Value": "Temperature",
16. "Sql": null,
17. "Uom": "string"
18. },
19. {
20. "Name": "Interpolation Method",
21. "Value": "linear",
22. "Sql": null,
23. "Uom": "string"
24. },
25. {
26. "Name": "Maximum Interpolation",
27. "Value": "2day",
28. "Sql": null,
29. "Uom": "string"
30. }
31. ],
32. "CapsuleProperties": null
33. }
34. ],
35. "Type": "GENERIC",
36. "Hostname": null,
37. "Port": 0,
38. "DatabaseName": null,
39. "Username": "root",
40. "Password": "taosdata",
41. "InitialSql": null,
42. "TimeZone": null,
43. "PrintRows": false,
44. "UseWindowsAuth": false,
45. "SqlFetchBatchSize": 100000,
46. "UseSSL": false,
47. "JdbcProperties": null,
48. "GenericDatabaseConfig": {
49. "DatabaseJdbcUrl": "jdbc:TAOS-RS://127.0.0.1:6041/power?user=root&password=taosdata",
50. "SqlDriverClassName": "com.taosdata.jdbc.rs.RestfulDriver",
51. "ResolutionInNanoseconds": 1000,
52. "ZonedColumnTypes": []
53. }
54. }

使用 Seeq Workbench

登录 Seeq 服务页面并新建 Seeq Workbench,通过选择数据源搜索结果和根据需要选择不同的工具,可以进行数据展现或预测,详细使用方法参见官方知识库。

Seeq Workbench

用 Seeq Data Lab Server 进行进一步的数据分析

登录 Seeq 服务页面并新建 Seeq Data Lab,可以进一步使用 Python 编程或其他机器学习工具进行更复杂的数据挖掘功能。

1. from seeq import spy
2. spy.options.compatibility = 189
3. import pandas as pd
4. import matplotlib
5. import matplotlib.pyplot as plt
6. import mlforecast
7. import lightgbm as lgb
8. from mlforecast.target_transforms import Differences
9. from sklearn.linear_model import LinearRegression

11. ds = spy.search({'ID': "8C91A9C7-B6C2-4E18-AAAF-XXXXXXXXX"})
12. print(ds)

14. sig = ds.loc[ds['Name'].isin(['Num'])]
15. print(sig)

17. data = spy.pull(sig, start='2015-01-01', end='2022-12-31', grid=None)
18. print("data.info()")
19. data.info()
20. print(data)
21. #data.plot()

23. print("data[Num].info()")
24. data['Num'].info()
25. da = data['Num'].index.tolist()
26. #print(da)

28. li = data['Num'].tolist()
29. #print(li)

31. data2 = pd.DataFrame()
32. data2['ds'] = da
33. print('1st data2 ds info()')
34. data2['ds'].info()

36. #data2['ds'] = pd.to_datetime(data2['ds']).to_timestamp()
37. data2['ds'] = pd.to_datetime(data2['ds']).astype('int64')
38. data2['y'] = li
39. print('2nd data2 ds info()')
40. data2['ds'].info()
41. print(data2)

43. data2.insert(0, column = "unique_id", value="unique_id")

45. print("Forecasting ...")

47. forecast = mlforecast.MLForecast(
48. models = lgb.LGBMRegressor(),
49. freq = 1,
50. lags=[365],
51. target_transforms=[Differences([365])],
52. )

54. forecast.fit(data2)
55. predicts = forecast.predict(365)

57. pd.concat([data2, predicts]).set_index("ds").plot(title = "current data with forecast")
58. plt.show()

运行程序输出结果:

Seeq forecast result

配置 Seeq 数据源连接 TDengine Cloud

配置 Seeq 数据源连接 TDengine Cloud 和连接 TDengine 本地安装实例没有本质的不同,只要登录 TDengine Cloud 后选择“编程 - Java”并拷贝带 token 字符串的 JDBC 填写为 Seeq Data Source 的 DatabaseJdbcUrl 值。 注意使用 TDengine Cloud 时 SQL 命令中需要指定数据库名称。

用 TDengine Cloud 作为数据源的配置内容示例:

1. {
2. "QueryDefinitions": [
3. {
4. "Name": "CloudVoltage",
5. "Type": "SIGNAL",
6. "Sql": "SELECT  ts, voltage FROM test.meters",
7. "Enabled": true,
8. "TestMode": false,
9. "TestQueriesDuringSync": true,
10. "InProgressCapsulesEnabled": false,
11. "Variables": null,
12. "Properties": [
13. {
14. "Name": "Name",
15. "Value": "Voltage",
16. "Sql": null,
17. "Uom": "string"
18. },
19. {
20. "Name": "Interpolation Method",
21. "Value": "linear",
22. "Sql": null,
23. "Uom": "string"
24. },
25. {
26. "Name": "Maximum Interpolation",
27. "Value": "2day",
28. "Sql": null,
29. "Uom": "string"
30. }
31. ],
32. "CapsuleProperties": null
33. }
34. ],
35. "Type": "GENERIC",
36. "Hostname": null,
37. "Port": 0,
38. "DatabaseName": null,
39. "Username": "root",
40. "Password": "taosdata",
41. "InitialSql": null,
42. "TimeZone": null,
43. "PrintRows": false,
44. "UseWindowsAuth": false,
45. "SqlFetchBatchSize": 100000,
46. "UseSSL": false,
47. "JdbcProperties": null,
48. "GenericDatabaseConfig": {
49. "DatabaseJdbcUrl": "jdbc:TAOS-RS://gw.cloud.taosdata.com?useSSL=true&token=41ac9d61d641b6b334e8b76f45f5a8XXXXXXXXXX",
50. "SqlDriverClassName": "com.taosdata.jdbc.rs.RestfulDriver",
51. "ResolutionInNanoseconds": 1000,
52. "ZonedColumnTypes": []
53. }
54. }

TDengine Cloud 作为数据源的 Seeq Workbench 界面示例

Seeq workbench with TDengine cloud

方案总结

通过集成Seeq和TDengine,可以充分利用TDengine高效的存储和查询性能,同时也可以受益于Seeq提供给用户的强大数据可视化和分析功能。

这种集成使用户能够充分利用TDengine的高性能时序数据存储和检索,确保高效处理大量数据。同时,Seeq提供高级分析功能,如数据可视化、异常检测、相关性分析和预测建模,使用户能够获得有价值的洞察并基于数据进行决策。

综合来看,Seeq和TDengine共同为制造业、工业物联网和电力系统等各行各业的时序数据分析提供了综合解决方案。高效数据存储和先进的分析相结合,赋予用户充分发挥时序数据潜力的能力,推动运营改进,并支持预测和规划分析应用。