@cpzxrobot/sdk 1.0.73 → 1.0.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/device_filter.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { Cpzxrobot, DataQueryArgs } from ".";
2
2
  import type { AxiosResponse } from "axios";
3
3
 
4
-
5
-
6
4
  export abstract class DeviceFilter<T extends { id: number }> {
7
5
  context: Cpzxrobot;
8
6
  protected devices: T[] = [];
@@ -115,7 +113,7 @@ export abstract class DeviceFilter<T extends { id: number }> {
115
113
  type: "diffPerDay", // diffPerDay, sumPerDay, latest
116
114
  }
117
115
  ) {
118
- if(!args.period || args.period.endsWith("d")) {
116
+ if (!args.period || args.period.endsWith("d")) {
119
117
  if (!args.stop) {
120
118
  args.stop = this.formateDateToYYYYMMDD(new Date());
121
119
  }
@@ -124,7 +122,7 @@ export abstract class DeviceFilter<T extends { id: number }> {
124
122
  sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
125
123
  args.start = this.formateDateToYYYYMMDD(sevenDaysAgo);
126
124
  }
127
- }else if(args.period.endsWith("h")) {
125
+ } else if (args.period.endsWith("h")) {
128
126
  if (!args.stop) {
129
127
  args.stop = new Date().toISOString();
130
128
  }
@@ -135,7 +133,7 @@ export abstract class DeviceFilter<T extends { id: number }> {
135
133
  }
136
134
  }
137
135
 
138
- if(!args.type) {
136
+ if (!args.type) {
139
137
  args.type = "last";
140
138
  }
141
139
 
@@ -147,8 +145,58 @@ export abstract class DeviceFilter<T extends { id: number }> {
147
145
  params: args,
148
146
  }
149
147
  );
150
-
151
- return this.wrapData(id, args, p1);
148
+ if (args.type == "raw") {
149
+ return p1.then((res: AxiosResponse) => {
150
+ var string = res.data.data as string;
151
+ string = string.replace(/\r/g, "");
152
+ var arr = string.split("\n");
153
+ var inAnnotation = false;
154
+ var dataGroups = new SensorDatas();
155
+ var field: FieldDatas | null = null;
156
+ for (var i = 0; i < arr.length; i++) {
157
+ var values = arr[i].split(",");
158
+ if (arr[i].startsWith("#")) {
159
+ if (!inAnnotation) {
160
+ inAnnotation = true;
161
+ if (field) {
162
+ dataGroups.push(field);
163
+ }
164
+ field = new FieldDatas();
165
+ }
166
+ switch (values[0]) {
167
+ case "#datatype":
168
+ field!.datatypes = values.slice(1);
169
+ break;
170
+ case "#group":
171
+ field!.groups = values
172
+ .slice(1)
173
+ .map((item) => item == "true");
174
+ break;
175
+ case "#default":
176
+ field!.defaults = values.slice(1);
177
+ break;
178
+ default:
179
+ break;
180
+ }
181
+ } else if (arr[i] != "") {
182
+ if (inAnnotation) {
183
+ inAnnotation = false;
184
+ for (var j = 0; j < values.length; j++) {
185
+ field!.columns.set(values[j], j);
186
+ }
187
+ } else {
188
+ field!.values.push(values);
189
+ }
190
+ }
191
+ }
192
+ if (field) {
193
+ dataGroups!.push(field);
194
+ }
195
+ return dataGroups;
196
+ });
197
+ } else {
198
+ return this.wrapData(id, args, p1);
199
+ }
152
200
  })
153
201
  .then((res: AxiosResponse) => {
154
202
  if (res.data.Error) {
@@ -122,7 +122,61 @@ class DeviceFilter {
122
122
  const p1 = this.context.axios.get(`/api/v1/device/${id}/data/${args.type}`, {
123
123
  params: args,
124
124
  });
125
- return this.wrapData(id, args, p1);
125
+ if (args.type == "raw") {
126
+ return p1.then((res) => {
127
+ var string = res.data.data;
128
+ string = string.replace(/\r/g, "");
129
+ var arr = string.split("\n");
130
+ var inAnnotation = false;
131
+ var dataGroups = new SensorDatas();
132
+ var field = null;
133
+ for (var i = 0; i < arr.length; i++) {
134
+ var values = arr[i].split(",");
135
+ if (arr[i].startsWith("#")) {
136
+ if (!inAnnotation) {
137
+ inAnnotation = true;
138
+ if (field) {
139
+ dataGroups.push(field);
140
+ }
141
+ field = new FieldDatas();
142
+ }
143
+ switch (values[0]) {
144
+ case "#datatype":
145
+ field.datatypes = values.slice(1);
146
+ break;
147
+ case "#group":
148
+ field.groups = values
149
+ .slice(1)
150
+ .map((item) => item == "true");
151
+ break;
152
+ case "#default":
153
+ field.defaults = values.slice(1);
154
+ break;
155
+ default:
156
+ break;
157
+ }
158
+ }
159
+ else if (arr[i] != "") {
160
+ if (inAnnotation) {
161
+ inAnnotation = false;
162
+ for (var j = 0; j < values.length; j++) {
163
+ field.columns.set(values[j], j);
164
+ }
165
+ }
166
+ else {
167
+ field.values.push(values);
168
+ }
169
+ }
170
+ }
171
+ if (field) {
172
+ dataGroups.push(field);
173
+ }
174
+ return dataGroups;
175
+ });
176
+ }
177
+ else {
178
+ return this.wrapData(id, args, p1);
179
+ }
126
180
  })
127
181
  .then((res) => {
128
182
  if (res.data.Error) {
package/dist/index.js CHANGED
@@ -93,11 +93,13 @@ class Cpzxrobot {
93
93
  // @ts-ignore
94
94
  this._jumpToMiniApp = window.miniapp.open;
95
95
  // @ts-ignore
96
- this._scanQrcode = window.miniapp.scanQrcode;
96
+ this.scanQrcode = window.miniapp.scanQrcode;
97
97
  // @ts-ignore
98
98
  this.setTitle = window.miniapp.setTitle;
99
99
  // @ts-ignore
100
100
  this.saveBase64 = window.miniapp.saveBase64;
101
+ // @ts-ignore
102
+ this.vibrate = window.miniapp.vibrate;
101
103
  this.saveBlob = this._saveBlobAsBase64;
102
104
  }
103
105
  else if (domain == "appassets.androidplatform.net" ||
@@ -115,7 +117,7 @@ class Cpzxrobot {
115
117
  this._jumpToMiniApp = function (url) {
116
118
  return platform.callHandler("app.openMiniapp", url);
117
119
  };
118
- this._scanQrcode = function () {
120
+ this.scanQrcode = function () {
119
121
  return platform.callHandler("app.scanQrcode");
120
122
  };
121
123
  this.setTitle = function (title) {
@@ -125,6 +127,9 @@ class Cpzxrobot {
125
127
  this.saveBase64 = function (base64, filename) {
126
128
  return platform.callHandler("app.saveBase64", base64, filename);
127
129
  };
130
+ this.vibrate = function (time) {
131
+ return platform.callHandler("app.vibrate", time);
132
+ };
128
133
  this.axios = {
129
134
  get: function (url, data) {
130
135
  console.log(url, data);
@@ -210,9 +215,6 @@ class Cpzxrobot {
210
215
  dict(dictName) {
211
216
  return this.axios.get(`/api/v1/dict/${dictName}`);
212
217
  }
213
- scanQrcode() {
214
- return this._scanQrcode();
215
- }
216
218
  //打开其他小程序
217
219
  openMiniApp(url) {
218
220
  this._jumpToMiniApp(url);
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ class FieldDatas {
3
+ constructor() {
4
+ this.datatypes = [];
5
+ this.groups = [];
6
+ this.defaults = [];
7
+ this.values = [];
8
+ this.columns = new Map();
9
+ }
10
+ get length() {
11
+ return this.values.length;
12
+ }
13
+ valuesAt(at) {
14
+ var values = new Map();
15
+ for (var i = 0; i < this.values.length; i++) {
16
+ if (this.values[i][this.columns.get("_time")] == at) {
17
+ var field = this.values[i][this.columns.get("_field")];
18
+ var value = this.values[i][this.columns.get("_value")];
19
+ values.set(field, value);
20
+ break;
21
+ }
22
+ }
23
+ return values;
24
+ }
25
+ get fields() {
26
+ var fields = ["time"];
27
+ for (var i = 0; i < this.values.length; i++) {
28
+ var field = this.values[i][this.columns.get("_field")];
29
+ if (fields.indexOf(field) == -1) {
30
+ fields.push(field);
31
+ }
32
+ }
33
+ return fields;
34
+ }
35
+ }
36
+ class SensorDatas {
37
+ constructor() {
38
+ this.data_fields = [];
39
+ }
40
+ push(datas) {
41
+ this.data_fields.push(datas);
42
+ }
43
+ get datas() {
44
+ var datas = [];
45
+ for (var i = 0; i < this.data_fields[0].values.length; i++) {
46
+ var data = {
47
+ time: this.data_fields[0].values[i][this.data_fields[0].columns.get("_time")],
48
+ };
49
+ for (var j = 0; j < this.data_fields.length; j++) {
50
+ var field = this.data_fields[j];
51
+ var values = field.valuesAt(data.time);
52
+ for (let [key, value] of values.entries()) {
53
+ data[key] = value;
54
+ }
55
+ }
56
+ datas.push(data);
57
+ }
58
+ return datas;
59
+ }
60
+ get fields() {
61
+ var fields = [];
62
+ for (var i = 0; i < this.data_fields.length; i++) {
63
+ var subfields = this.data_fields[i].fields;
64
+ for (var j = 0; j < subfields.length; j++) {
65
+ if (fields.indexOf(subfields[j]) == -1) {
66
+ fields.push(subfields[j]);
67
+ }
68
+ }
69
+ }
70
+ return fields;
71
+ }
72
+ }
package/index.ts CHANGED
@@ -32,10 +32,11 @@ export class Cpzxrobot {
32
32
  _getSelectedFarmFromMiniApp!: () => any;
33
33
  _getSelectedUnitFromMiniApp!: () => any;
34
34
  _jumpToMiniApp!: (url: string) => any;
35
- _scanQrcode!:() => Promise<string>;
36
35
  setTitle!: (title: string) => void;
37
36
  saveBase64!: (base64: string, filename: string) => void;
38
37
  saveBlob!: (blob: Blob, filename: string) => void;
38
+ scanQrcode!:() => Promise<string>;
39
+ vibrate!: (time?: number) => void;
39
40
  assistant: AssistantGateway;
40
41
  energy: EnergyGateway;
41
42
  camera: CameraGateway;
@@ -121,11 +122,13 @@ export class Cpzxrobot {
121
122
  // @ts-ignore
122
123
  this._jumpToMiniApp = window.miniapp.open;
123
124
  // @ts-ignore
124
- this._scanQrcode = window.miniapp.scanQrcode;
125
+ this.scanQrcode = window.miniapp.scanQrcode;
125
126
  // @ts-ignore
126
127
  this.setTitle = window.miniapp.setTitle;
127
128
  // @ts-ignore
128
129
  this.saveBase64 = window.miniapp.saveBase64;
130
+ // @ts-ignore
131
+ this.vibrate = window.miniapp.vibrate;
129
132
  this.saveBlob = this._saveBlobAsBase64;
130
133
  } else if (
131
134
  domain == "appassets.androidplatform.net" ||
@@ -146,7 +149,7 @@ export class Cpzxrobot {
146
149
  this._jumpToMiniApp = function (url: string) {
147
150
  return platform.callHandler("app.openMiniapp", url);
148
151
  };
149
- this._scanQrcode = function(){
152
+ this.scanQrcode = function(){
150
153
  return platform.callHandler("app.scanQrcode");
151
154
  }
152
155
  this.setTitle = function (title: string) {
@@ -156,6 +159,9 @@ export class Cpzxrobot {
156
159
  this.saveBase64 = function (base64: string, filename: string) {
157
160
  return platform.callHandler("app.saveBase64", base64, filename);
158
161
  };
162
+ this.vibrate = function (time?: number) {
163
+ return platform.callHandler("app.vibrate", time);
164
+ };
159
165
  this.axios = {
160
166
  get: function (url, data) {
161
167
  console.log(url, data);
@@ -247,10 +253,6 @@ export class Cpzxrobot {
247
253
  return this.axios.get(`/api/v1/dict/${dictName}`);
248
254
  }
249
255
 
250
- scanQrcode(){
251
- return this._scanQrcode();
252
- }
253
-
254
256
  //打开其他小程序
255
257
  openMiniApp(url: string) {
256
258
  this._jumpToMiniApp(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.0.73",
3
+ "version": "1.0.75",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -104,6 +104,7 @@ baseURL: "/"
104
104
  | cpzxrobot().pigfarm.heatlamp.iotFields | 获取保温灯用于获取iot的字段列表 |
105
105
  | cpzxrobot().pigfarm.threshold | 获取单元中特定类型的阈值信息 |
106
106
  | cpzxrobot().scanQrcode | 调用扫码功能,获得扫码文字 |
107
+ | cpzxrobot().vibrate | 调用震动功能 |
107
108
  | cpzxrobot().unit.v2.list | 获得单元列表,v2版本 |
108
109
  | cpzxrobot().unit.v2.add | 添加单元,v2版本 |
109
110
  | cpzxrobot().unit.v2.update | 更新单元,v2版本 |
@@ -0,0 +1,83 @@
1
+
2
+ class FieldDatas {
3
+ datatypes: string[] = [];
4
+ groups: boolean[] = [];
5
+ defaults: string[] = [];
6
+ values: string[][] = [];
7
+ columns: Map<String, number> = new Map();
8
+
9
+ get length() {
10
+ return this.values.length;
11
+ }
12
+
13
+
14
+ valuesAt(at: string) {
15
+ var values: Map<string, any> = new Map();
16
+ for (var i = 0; i < this.values.length; i++) {
17
+ if (this.values[i][this.columns.get("_time")!] == at) {
18
+ var field = this.values[i][this.columns.get("_field")!];
19
+ var value = this.values[i][this.columns.get("_value")!];
20
+ values.set(field, value);
21
+ break;
22
+ }
23
+ }
24
+ return values;
25
+ }
26
+
27
+ get fields() {
28
+ var fields: string[] = ["time"];
29
+ for (var i = 0; i < this.values.length; i++) {
30
+ var field = this.values[i][this.columns.get("_field")!];
31
+ if (fields.indexOf(field) == -1) {
32
+ fields.push(field);
33
+ }
34
+ }
35
+ return fields;
36
+ }
37
+ }
38
+
39
+ class SensorDatas {
40
+ push(datas: FieldDatas) {
41
+ this.data_fields.push(datas);
42
+ }
43
+ data_fields: FieldDatas[] = [];
44
+
45
+ get datas() {
46
+ var datas: {
47
+ time: string;
48
+ [key: string]: any;
49
+ }[] = [];
50
+ for (var i = 0; i < this.data_fields[0].values.length; i++) {
51
+ var data: {
52
+ time: string;
53
+ [key: string]: any;
54
+ } = {
55
+ time: this.data_fields[0].values[i][
56
+ this.data_fields[0].columns.get("_time")!
57
+ ],
58
+ };
59
+ for (var j = 0; j < this.data_fields.length; j++) {
60
+ var field = this.data_fields[j];
61
+ var values = field.valuesAt(data.time);
62
+ for (let [key, value] of values.entries()) {
63
+ data[key] = value;
64
+ }
65
+ }
66
+ datas.push(data);
67
+ }
68
+ return datas;
69
+ }
70
+
71
+ get fields() {
72
+ var fields: string[] = [];
73
+ for (var i = 0; i < this.data_fields.length; i++) {
74
+ var subfields = this.data_fields[i].fields;
75
+ for (var j = 0; j < subfields.length; j++) {
76
+ if (fields.indexOf(subfields[j]) == -1) {
77
+ fields.push(subfields[j]);
78
+ }
79
+ }
80
+ }
81
+ return fields;
82
+ }
83
+ }
package/types.d.ts CHANGED
@@ -264,6 +264,7 @@ export interface DataQueryArgs {
264
264
  | "latest"
265
265
  | "latestInRangePerDay"
266
266
  | "last"
267
+ | "raw"
267
268
  | "difference";
268
269
  period?: "1mo" | "1d" | null;
269
270
  offset?: string; // 可以设置统计偏移量,比如设置18h, 则统计从当天晚上6点开始
@@ -289,6 +290,8 @@ export class Cpzxrobot {
289
290
  setTitle: (title: string) => void;
290
291
  saveBase64: (base64: string, filename: string) => void;
291
292
  saveBlob: (blob: Blob, filename: string) => void;
293
+ scanQrcode:() => Promise<string>;
294
+ vibrate: (time?: number) => void;
292
295
  }
293
296
 
294
297
  declare global {