iobroker.influxdb 2.1.1 → 2.5.2

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.
Files changed (40) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +106 -57
  3. package/admin/i18n/de/translations.json +8 -2
  4. package/admin/i18n/en/translations.json +7 -1
  5. package/admin/i18n/es/translations.json +7 -1
  6. package/admin/i18n/fr/translations.json +7 -1
  7. package/admin/i18n/it/translations.json +7 -1
  8. package/admin/i18n/nl/translations.json +7 -1
  9. package/admin/i18n/pl/translations.json +7 -1
  10. package/admin/i18n/pt/translations.json +9 -3
  11. package/admin/i18n/ru/translations.json +7 -1
  12. package/admin/i18n/zh-cn/translations.json +7 -1
  13. package/admin/influxdb.png +0 -0
  14. package/admin/jsonConfig.json +36 -5
  15. package/admin/jsonCustom.json +43 -6
  16. package/admin/words.js +17 -11
  17. package/docs/de/img/influxdb_Filtern_loggen.jpg +0 -0
  18. package/docs/de/img/influxdb_ioBroker_Adapter_SQL_objects_Data.jpg +0 -0
  19. package/docs/de/img/influxdb_ioBroker_Adapter_SQL_objects_filter.jpg +0 -0
  20. package/docs/de/img/influxdb_ioBroker_Adapter_SQL_objects_timerange.jpg +0 -0
  21. package/docs/de/img/influxdb_ioBroker_Adapter_SQL_objects_type.jpg +0 -0
  22. package/docs/de/img/influxdb_ioBroker_Adapter_influxDB_Konfig.jpg +0 -0
  23. package/docs/de/img/influxdb_ioBroker_Adapter_influxDB_objects.jpg +0 -0
  24. package/docs/de/img/influxdb_ioBroker_Adapter_rickshaw03.jpg +0 -0
  25. package/docs/de/img/influxdb_ioBroker_adapter_History_devices.jpg +0 -0
  26. package/docs/de/influxdb.md +101 -0
  27. package/io-package.json +220 -364
  28. package/lib/Database.js +6 -5
  29. package/lib/DatabaseInfluxDB1x.js +18 -17
  30. package/lib/DatabaseInfluxDB2x.js +108 -71
  31. package/lib/aggregate.js +141 -37
  32. package/main.js +712 -364
  33. package/package.json +22 -8
  34. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
  35. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  36. package/.github/auto-merge.yml +0 -17
  37. package/.github/dependabot.yml +0 -16
  38. package/.github/stale.yml +0 -78
  39. package/.github/workflows/dependabot-automerge.yml +0 -22
  40. package/.github/workflows/test-and-release.yml +0 -221
package/lib/aggregate.js CHANGED
@@ -22,16 +22,18 @@ function initAggregate(options) {
22
22
  options.overallLength = 0;
23
23
 
24
24
  // pre-fill the result with timestamps (add one before start and one after end)
25
- for (let i = 0; i <= options.maxIndex + 2; i++){
25
+ for (let i = 0; i <= options.maxIndex + 2; i++) {
26
26
  options.result[i] = {
27
- val: {ts: null, val: null},
28
- max: {ts: null, val: null},
29
- min: {ts: null, val: null},
30
- start: {ts: null, val: null},
31
- end: {ts: null, val: null}
27
+ val: {ts: null, val: null},
28
+ max: {ts: null, val: null},
29
+ min: {ts: null, val: null},
30
+ start: {ts: null, val: null},
31
+ end: {ts: null, val: null}
32
32
  };
33
33
 
34
- if (options.aggregate === 'average') options.averageCount[i] = 0;
34
+ if (options.aggregate === 'average') {
35
+ options.averageCount[i] = 0;
36
+ }
35
37
  }
36
38
  return options;
37
39
  }
@@ -40,9 +42,12 @@ function aggregation(options, data) {
40
42
  let index;
41
43
  let preIndex;
42
44
  for (let i = 0; i < data.length; i++) {
43
- if (!data[i]) continue;
44
- if (typeof data[i].ts !== 'number') data[i].ts = parseInt(data[i].ts, 10);
45
- if (data[i].ts < 946681200000) data[i].ts *= 1000;
45
+ if (!data[i]) {
46
+ continue;
47
+ }
48
+ if (typeof data[i].ts !== 'number') {
49
+ data[i].ts = parseInt(data[i].ts, 10);
50
+ }
46
51
 
47
52
  preIndex = Math.floor((data[i].ts - options.start) / options.step);
48
53
 
@@ -62,17 +67,29 @@ function aggregation(options, data) {
62
67
  }
63
68
 
64
69
  if (options.aggregate === 'max') {
65
- if (!options.result[index].val.ts) options.result[index].val.ts = Math.round(options.start + (((index - 1) + 0.5) * options.step));
66
- if (options.result[index].val.val === null || options.result[index].val.val < data[i].val) options.result[index].val.val = data[i].val;
70
+ if (!options.result[index].val.ts) {
71
+ options.result[index].val.ts = Math.round(options.start + (((index - 1) + 0.5) * options.step));
72
+ }
73
+ if (options.result[index].val.val === null || options.result[index].val.val < data[i].val) {
74
+ options.result[index].val.val = data[i].val;
75
+ }
67
76
  } else if (options.aggregate === 'min') {
68
- if (!options.result[index].val.ts) options.result[index].val.ts = Math.round(options.start + (((index - 1) + 0.5) * options.step));
69
- if (options.result[index].val.val === null || options.result[index].val.val > data[i].val) options.result[index].val.val = data[i].val;
77
+ if (!options.result[index].val.ts) {
78
+ options.result[index].val.ts = Math.round(options.start + (((index - 1) + 0.5) * options.step));
79
+ }
80
+ if (options.result[index].val.val === null || options.result[index].val.val > data[i].val) {
81
+ options.result[index].val.val = data[i].val;
82
+ }
70
83
  } else if (options.aggregate === 'average') {
71
- if (!options.result[index].val.ts) options.result[index].val.ts = Math.round(options.start + (((index - 1) + 0.5) * options.step));
84
+ if (!options.result[index].val.ts) {
85
+ options.result[index].val.ts = Math.round(options.start + (((index - 1) + 0.5) * options.step));
86
+ }
72
87
  options.result[index].val.val += parseFloat(data[i].val);
73
88
  options.averageCount[index]++;
74
89
  } else if (options.aggregate === 'total') {
75
- if (!options.result[index].val.ts) options.result[index].val.ts = Math.round(options.start + (((index - 1) + 0.5) * options.step));
90
+ if (!options.result[index].val.ts) {
91
+ options.result[index].val.ts = Math.round(options.start + (((index - 1) + 0.5) * options.step));
92
+ }
76
93
  options.result[index].val.val += parseFloat(data[i].val);
77
94
  } else if (options.aggregate === 'minmax') {
78
95
  if (options.result[index].min.ts === null) {
@@ -195,7 +212,6 @@ function finishAggregation(options) {
195
212
  };
196
213
  } // start, min, max == end
197
214
  else {
198
-
199
215
  options.result.splice(ii + 1, 0, {
200
216
  ts: options.result[ii].min.ts,
201
217
  val: options.result[ii].min.val
@@ -261,8 +277,8 @@ function finishAggregation(options) {
261
277
  for (let k = options.result.length - 1; k >= 0; k--) {
262
278
  if (options.result[k].val.ts) {
263
279
  options.result[k] = {
264
- ts: options.result[k].val.ts,
265
- val: (options.result[k].val.val !== null) ? Math.round(options.result[k].val.val / options.averageCount[k] * 100) / 100 : null
280
+ ts: options.result[k].val.ts,
281
+ val: options.result[k].val.val !== null ? Math.round(options.result[k].val.val / options.averageCount[k] * 100) / 100 : null
266
282
  };
267
283
  } else {
268
284
  // no one value in this interval
@@ -282,16 +298,26 @@ function finishAggregation(options) {
282
298
  }
283
299
  }
284
300
  }
301
+
285
302
  beautify(options);
286
303
  }
287
304
 
288
305
  function beautify(options) {
289
306
  let preFirstValue = null;
290
307
  let postLastValue = null;
291
- if (options.ignoreNull === 'true') options.ignoreNull = true; // include nulls and replace them with last value
292
- if (options.ignoreNull === 'false') options.ignoreNull = false; // include nulls
293
- if (options.ignoreNull === '0') options.ignoreNull = 0; // include nulls and replace them with 0
294
- if (options.ignoreNull !== true && options.ignoreNull !== false && options.ignoreNull !== 0) options.ignoreNull = false;
308
+
309
+ if (options.ignoreNull === 'true') { // include nulls and replace them with last value
310
+ options.ignoreNull = true;
311
+ } else
312
+ if (options.ignoreNull === 'false') { // include nulls
313
+ options.ignoreNull = false;
314
+ } else
315
+ if (options.ignoreNull === '0') { // include nulls and replace them with 0
316
+ options.ignoreNull = 0;
317
+ } else
318
+ if (options.ignoreNull !== true && options.ignoreNull !== false && options.ignoreNull !== 0) {
319
+ options.ignoreNull = false;
320
+ }
295
321
 
296
322
  // process null values, remove points outside the span and find first points after end and before start
297
323
  for (let i = 0; i < options.result.length; i++) {
@@ -348,7 +374,7 @@ function beautify(options) {
348
374
  if (firstY !== null) {
349
375
  // interpolate
350
376
  const y = preFirstValue.val + (firstY - preFirstValue.val) * (options.start - preFirstValue.ts) / (firstTS - preFirstValue.ts);
351
- options.result.unshift({ts: options.start, val: y});
377
+ options.result.unshift({ts: options.start, val: y, i: true});
352
378
  } else {
353
379
  options.result.unshift({ts: options.start, val: null});
354
380
  }
@@ -386,7 +412,7 @@ function beautify(options) {
386
412
  if (lastY !== null) {
387
413
  // make interpolation
388
414
  const _y = lastY + (postLastValue.val - lastY) * (options.end - lastTS) / (postLastValue.ts - lastTS);
389
- options.result.push({ts: options.end, val: _y});
415
+ options.result.push({ts: options.end, val: _y, i: true});
390
416
  } else {
391
417
  options.result.push({ts: options.end, val: null});
392
418
  }
@@ -407,9 +433,8 @@ function beautify(options) {
407
433
  }
408
434
  }
409
435
  }
410
- }
411
- else if (options.aggregate === 'none') {
412
- if ((options.count) && (options.result.length > options.count)) {
436
+ } else if (options.aggregate === 'none') {
437
+ if (options.count && options.result.length > options.count) {
413
438
  options.result = options.result.slice(0, options.count);
414
439
  }
415
440
  }
@@ -443,8 +468,10 @@ function sendResponse(adapter, msg, options, data, startTime) {
443
468
  }
444
469
  }
445
470
  options.result = aggregateData.result;
471
+
446
472
  beautify(options);
447
- if ((options.aggregate === 'none') && (options.count) && (options.result.length > options.count)) {
473
+
474
+ if (options.aggregate === 'none' && options.count && options.result.length > options.count) {
448
475
  options.result = options.result.slice(0, options.count);
449
476
  }
450
477
  aggregateData.result = options.result;
@@ -455,10 +482,11 @@ function sendResponse(adapter, msg, options, data, startTime) {
455
482
  aggregateData.result = options.result;
456
483
  }
457
484
 
458
- adapter.log.debug('Send: ' + aggregateData.result.length + ' of: ' + aggregateData.sourceLength + ' in: ' + (new Date().getTime() - startTime) + 'ms');
485
+ adapter.log.debug(`Send: ${aggregateData.result.length} of: ${aggregateData.sourceLength} in: ${Date.now() - startTime}ms`);
486
+
459
487
  adapter.sendTo(msg.from, msg.command, {
460
- result: aggregateData.result,
461
- step: aggregateData.step,
488
+ result: aggregateData.result,
489
+ step: aggregateData.step,
462
490
  error: null,
463
491
  sessionId: options.sessionId
464
492
  }, msg.callback);
@@ -468,8 +496,84 @@ function sendResponse(adapter, msg, options, data, startTime) {
468
496
  }
469
497
  }
470
498
 
471
- module.exports.sendResponse = sendResponse;
472
- module.exports.initAggregate = initAggregate;
473
- module.exports.aggregation = aggregation;
474
- module.exports.beautify = beautify;
475
- module.exports.finishAggregation = finishAggregation;
499
+ function sendResponseCounter(adapter, msg, options, data, startTime) {
500
+ // data
501
+ // 1586713810000 100
502
+ // 1586713810010 200
503
+ // 1586713810040 500
504
+ // 1586713810050 0
505
+ // 1586713810090 400
506
+ // 1586713810100 0
507
+ // 1586713810110 100
508
+ if (typeof data === 'string') {
509
+ adapter.log.error(data);
510
+ return adapter.sendTo(msg.from, msg.command, {
511
+ result: [],
512
+ error: data,
513
+ sessionId: options.sessionId
514
+ }, msg.callback);
515
+ }
516
+
517
+ if (data[0] && data[1]) {
518
+ // first | start | afterFirst | ...... | last | end | afterLast
519
+ // 5 | | 8 | 9 | 1 | 3 | | 5
520
+ // | 5+(8-5/tsDiff) | | 9 | 1 | | 3+(5-3/tsDiff) |
521
+ // (9 - 6.5) + (4 - 1)
522
+
523
+ if (data[1].ts === options.start) {
524
+ data.splice(0, 1);
525
+ }
526
+
527
+ if (data[0].ts < options.start && data[0].val > data[1].val) {
528
+ data.splice(0, 1);
529
+ }
530
+
531
+ // interpolate from first to start time
532
+ if (data[0].ts < options.start) {
533
+ const val = data[0].val + (data[1].val - data[0].val) * ((options.start - data[0].ts) / (data[1].ts - data[0].ts));
534
+ data.splice(0, 1);
535
+ data.unshift({ts: options.start, val, i: true});
536
+ }
537
+
538
+ if (data[data.length - 2].ts === options.end) {
539
+ data.splice(-1, 1);
540
+ }
541
+
542
+ const veryLast = data[data.length - 1];
543
+ const beforeLast = data[data.length - 2];
544
+
545
+ // interpolate from end time to last
546
+ if (options.end < veryLast.ts) {
547
+ const val = beforeLast.val + (veryLast.val - beforeLast.val) * ((options.end - beforeLast.ts) / (veryLast.ts - beforeLast.ts));
548
+ data.splice(-1, 1);
549
+ data.push({ts: options.end, val, i: true});
550
+ }
551
+
552
+ // at this point we expect [6.5, 9, 1, 4]
553
+ // at this point we expect [150, 200, 500, 0, 400, 0, 50]
554
+ let val = data[data.length - 1].val;
555
+ let sum = 0;
556
+ for (let i = data.length - 2; i >= 0; i--) {
557
+ if (data[i].val < val) {
558
+ sum += val - data[i].val;
559
+ }
560
+ val = data[i].val;
561
+ }
562
+
563
+ adapter.sendTo(msg.from, msg.command, {
564
+ result: sum,
565
+ error: null,
566
+ sessionId: options.sessionId
567
+ }, msg.callback);
568
+ } else {
569
+ adapter.log.info('No Data');
570
+ adapter.sendTo(msg.from, msg.command, {result: 0, step: null, error: null, sessionId: options.sessionId}, msg.callback);
571
+ }
572
+ }
573
+
574
+ module.exports.sendResponseCounter = sendResponseCounter;
575
+ module.exports.sendResponse = sendResponse;
576
+ module.exports.initAggregate = initAggregate;
577
+ module.exports.aggregation = aggregation;
578
+ module.exports.beautify = beautify;
579
+ module.exports.finishAggregation = finishAggregation;