iobroker.sql 1.16.1 → 1.16.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 bluefox <dogafox@gmail.com>, Apollon77
3
+ Copyright (c) 2015-2022 bluefox <dogafox@gmail.com>, Apollon77
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -145,7 +145,7 @@ Structure:
145
145
  | ts | BIGINT / INTEGER | Time in ms till epoch. Can be converted to time with "new Date(ts)" |
146
146
  | val | REAL | Value |
147
147
 
148
- This table stores the values when the counter was exchanged and the value does not increased, but failed to zero or lower value.
148
+ This table stores the values when the counter was exchanged and the value does not increase, but failed to zero or lower value.
149
149
 
150
150
  ### Strings
151
151
  Values for states with type "string".
@@ -267,7 +267,7 @@ sendTo('sql.0', 'deleteAll', [
267
267
  ], result => console.log('deleted'));
268
268
  ```
269
269
 
270
- To delete history data for some data point and for some range execute:
270
+ To delete history data for some data point and for some range, execute:
271
271
 
272
272
  ```
273
273
  sendTo('sql.0', 'deleteRange', [
@@ -292,7 +292,7 @@ sendTo('sql.0', 'update', [
292
292
 
293
293
  `ts` is mandatory. At least one other flags must be included in state object.
294
294
 
295
- Be careful with `counters`. The `counters` in DB will not be reset and you must handle it yourself.
295
+ Be careful with `counters`. The `counters` in DB will not be reset, and you must handle it yourself.
296
296
 
297
297
  ## Get history
298
298
  Additional to custom queries, you can use build in system function **getHistory**:
@@ -420,6 +420,9 @@ sendTo('sql.0', 'getEnabledDPs', {}, function (result) {
420
420
  -->
421
421
 
422
422
  ## Changelog
423
+ ### 1.16.2 (2022-02-16)
424
+ * (bluefox) Marked interpolated data with `i=true`
425
+
423
426
  ### 1.16.1 (2021-12-19)
424
427
  * (Excodibur) Hide settings not relevant when "log changes only" is not used
425
428
  * (Apollon77) Allow all number values for debounce again
@@ -682,7 +685,7 @@ sendTo('sql.0', 'getEnabledDPs', {}, function (result) {
682
685
 
683
686
  The MIT License (MIT)
684
687
 
685
- Copyright (c) 2015-2021 bluefox <dogafox@gmail.com>, Apollon77
688
+ Copyright (c) 2015-2022 bluefox <dogafox@gmail.com>, Apollon77
686
689
 
687
690
  Permission is hereby granted, free of charge, to any person obtaining a copy
688
691
  of this software and associated documentation files (the "Software"), to deal
package/io-package.json CHANGED
@@ -26,8 +26,20 @@
26
26
  "pl": "Rejestrowanie stanów w SQL DB",
27
27
  "zh-cn": "将状态记录到SQL DB"
28
28
  },
29
- "version": "1.16.1",
29
+ "version": "1.16.2",
30
30
  "news": {
31
+ "1.16.2": {
32
+ "en": "Marked interpolated data with `i=true`",
33
+ "de": "Markierte interpolierte Daten mit `i=true`",
34
+ "ru": "Помеченные интерполированные данные с `i=true`",
35
+ "pt": "Dados interpolados marcados com `i=true`",
36
+ "nl": "Gemarkeerde geïnterpoleerde gegevens met `i=true`",
37
+ "fr": "Données interpolées marquées avec `i=true`",
38
+ "it": "Dati interpolati contrassegnati con `i=true`",
39
+ "es": "Datos interpolados marcados con `i=true`",
40
+ "pl": "Oznaczono dane interpolowane za pomocą `i=true`",
41
+ "zh-cn": "用 `i=true` 标记插值数据"
42
+ },
31
43
  "1.16.1": {
32
44
  "en": "Hide settings not relevant when \"log changes only\" is not used\nAllow all number values for debounce again",
33
45
  "de": "Nicht relevante Einstellungen ausblenden, wenn \"Nur Änderungen protokollieren\" nicht verwendet wird\nAlle Zahlenwerte wieder für die Entprellung zulassen",
@@ -99,18 +111,6 @@
99
111
  "es": "Optimizar el manejo de paradas",
100
112
  "pl": "Zoptymalizuj obsługę zatrzymania",
101
113
  "zh-cn": "优化停止处理"
102
- },
103
- "1.15.3": {
104
- "en": "Added the option \"Do not create database\". E.g. if DB was created and it does not required to do that, because the user does not have enough rights.",
105
- "de": "Die Option \"Datenbank nicht erstellen\" wurde hinzugefügt. Z.B. wenn DB erstellt wurde und dies nicht erforderlich ist, da der Benutzer nicht über genügend Rechte verfügt.",
106
- "ru": "Добавлена опция «Не создавать базу данных». Например. если БД была создана, а этого делать не нужно, так как у пользователя недостаточно прав.",
107
- "pt": "Adicionada a opção \"Não criar banco de dados\". Por exemplo. se o DB foi criado e não é obrigatório, porque o usuário não tem direitos suficientes.",
108
- "nl": "De optie \"Geen database aanmaken\" toegevoegd. Bijv. als DB is gemaakt en het is niet nodig om dat te doen, omdat de gebruiker niet genoeg rechten heeft.",
109
- "fr": "Ajout de l'option \"Ne pas créer de base de données\". Par exemple. si DB a été créé et qu'il n'est pas nécessaire de le faire, car l'utilisateur n'a pas suffisamment de droits.",
110
- "it": "Aggiunta l'opzione \"Non creare database\". Per esempio. se DB è stato creato e non è necessario farlo, perché l'utente non dispone di diritti sufficienti.",
111
- "es": "Añadida la opción \"No crear base de datos\". P.ej. si se creó DB y no es necesario que lo haga, porque el usuario no tiene suficientes derechos.",
112
- "pl": "Dodano opcję „Nie twórz bazy danych”. Na przykład. jeśli baza danych została utworzona i nie jest to wymagane, ponieważ użytkownik nie ma wystarczających uprawnień.",
113
- "zh-cn": "添加了选项“不创建数据库”。例如。如果已创建数据库,则不需要这样做,因为用户没有足够的权限。"
114
114
  }
115
115
  },
116
116
  "mode": "daemon",
package/lib/aggregate.js CHANGED
@@ -48,9 +48,6 @@ function aggregation(options, data) {
48
48
  if (typeof data[i].ts !== 'number') {
49
49
  data[i].ts = parseInt(data[i].ts, 10);
50
50
  }
51
- if (data[i].ts < 946681200000) {
52
- data[i].ts *= 1000;
53
- }
54
51
 
55
52
  preIndex = Math.floor((data[i].ts - options.start) / options.step);
56
53
 
@@ -301,16 +298,26 @@ function finishAggregation(options) {
301
298
  }
302
299
  }
303
300
  }
301
+
304
302
  beautify(options);
305
303
  }
306
304
 
307
305
  function beautify(options) {
308
306
  let preFirstValue = null;
309
307
  let postLastValue = null;
310
- if (options.ignoreNull === 'true') options.ignoreNull = true; // include nulls and replace them with last value
311
- if (options.ignoreNull === 'false') options.ignoreNull = false; // include nulls
312
- if (options.ignoreNull === '0') options.ignoreNull = 0; // include nulls and replace them with 0
313
- 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
+ }
314
321
 
315
322
  // process null values, remove points outside the span and find first points after end and before start
316
323
  for (let i = 0; i < options.result.length; i++) {
@@ -367,7 +374,7 @@ function beautify(options) {
367
374
  if (firstY !== null) {
368
375
  // interpolate
369
376
  const y = preFirstValue.val + (firstY - preFirstValue.val) * (options.start - preFirstValue.ts) / (firstTS - preFirstValue.ts);
370
- options.result.unshift({ts: options.start, val: y});
377
+ options.result.unshift({ts: options.start, val: y, i: true});
371
378
  } else {
372
379
  options.result.unshift({ts: options.start, val: null});
373
380
  }
@@ -405,7 +412,7 @@ function beautify(options) {
405
412
  if (lastY !== null) {
406
413
  // make interpolation
407
414
  const _y = lastY + (postLastValue.val - lastY) * (options.end - lastTS) / (postLastValue.ts - lastTS);
408
- options.result.push({ts: options.end, val: _y});
415
+ options.result.push({ts: options.end, val: _y, i: true});
409
416
  } else {
410
417
  options.result.push({ts: options.end, val: null});
411
418
  }
@@ -427,7 +434,7 @@ function beautify(options) {
427
434
  }
428
435
  }
429
436
  } else if (options.aggregate === 'none') {
430
- if ((options.count) && (options.result.length > options.count)) {
437
+ if (options.count && options.result.length > options.count) {
431
438
  options.result = options.result.slice(0, options.count);
432
439
  }
433
440
  }
@@ -461,8 +468,10 @@ function sendResponse(adapter, msg, options, data, startTime) {
461
468
  }
462
469
  }
463
470
  options.result = aggregateData.result;
471
+
464
472
  beautify(options);
465
- if ((options.aggregate === 'none') && (options.count) && (options.result.length > options.count)) {
473
+
474
+ if (options.aggregate === 'none' && options.count && options.result.length > options.count) {
466
475
  options.result = options.result.slice(0, options.count);
467
476
  }
468
477
  aggregateData.result = options.result;
@@ -523,7 +532,7 @@ function sendResponseCounter(adapter, msg, options, data, startTime) {
523
532
  if (data[0].ts < options.start) {
524
533
  const val = data[0].val + (data[1].val - data[0].val) * ((options.start - data[0].ts) / (data[1].ts - data[0].ts));
525
534
  data.splice(0, 1);
526
- data.unshift({ts: options.start, val});
535
+ data.unshift({ts: options.start, val, i: true});
527
536
  }
528
537
 
529
538
  if (data[data.length - 2].ts === options.end) {
@@ -537,7 +546,7 @@ function sendResponseCounter(adapter, msg, options, data, startTime) {
537
546
  if (options.end < veryLast.ts) {
538
547
  const val = beforeLast.val + (veryLast.val - beforeLast.val) * ((options.end - beforeLast.ts) / (veryLast.ts - beforeLast.ts));
539
548
  data.splice(-1, 1);
540
- data.push({ts: options.end, val});
549
+ data.push({ts: options.end, val, i: true});
541
550
  }
542
551
 
543
552
  // at this point we expect [6.5, 9, 1, 4]
package/main.js CHANGED
@@ -883,7 +883,7 @@ function finish(callback) {
883
883
 
884
884
  function processMessage(msg) {
885
885
  if (msg.command === 'features') {
886
- adapter.sendTo(msg.from, msg.command, {supportedFeatures: ['update', 'delete', 'deleteRange', 'deleteAll']}, msg.callback);
886
+ adapter.sendTo(msg.from, msg.command, {supportedFeatures: ['update', 'delete', 'deleteRange', 'deleteAll', 'storeState']}, msg.callback);
887
887
  } else
888
888
  if (msg.command === 'getHistory') {
889
889
  getHistory(msg);
@@ -1572,11 +1572,11 @@ function pushValueIntoDB(id, state, isCounter, cb) {
1572
1572
  isCounter = false;
1573
1573
  }
1574
1574
 
1575
- if (sqlDPs[id][adapter.namespace].ignoreZero && (!state || state.val === undefined || state.val === null || state.val === 0)) {
1575
+ if (sqlDPs[id] && sqlDPs[id][adapter.namespace] && sqlDPs[id][adapter.namespace].ignoreZero && (!state || state.val === undefined || state.val === null || state.val === 0)) {
1576
1576
  adapter.log.debug(`pushValueIntoDB called for ${id} (type: ${sqlDPs[id].type}, ID: ${sqlDPs[id].index}) and state: ${JSON.stringify(state)} and it was ignored because the value zero or null`);
1577
1577
  return cb && cb();
1578
1578
  } else
1579
- if (state && sqlDPs[id][adapter.namespace].ignoreBelowZero && typeof state.val === 'number' && state.val < 0) {
1579
+ if (state && sqlDPs[id] && sqlDPs[id][adapter.namespace] && sqlDPs[id][adapter.namespace].ignoreBelowZero && typeof state.val === 'number' && state.val < 0) {
1580
1580
  adapter.log.debug(`pushValueIntoDB called for ${id} (type: ${sqlDPs[id].type}, ID: ${sqlDPs[id].index}) and state: ${JSON.stringify(state)} and it was ignored because the value is below 0`);
1581
1581
  return cb && cb();
1582
1582
  }
@@ -1974,12 +1974,12 @@ function getHistory(msg) {
1974
1974
  if (sqlDPs[options.id].type === undefined && sqlDPs[options.id].dbtype !== undefined) {
1975
1975
  if (sqlDPs[options.id][adapter.namespace] && sqlDPs[options.id][adapter.namespace].storageType) {
1976
1976
  if (storageTypes.indexOf(sqlDPs[options.id][adapter.namespace].storageType) === sqlDPs[options.id].dbtype) {
1977
- adapter.log.debug('For getHistory for id ' + options.id + ': Type empty, use storageType dbtype ' + sqlDPs[options.id].dbtype);
1977
+ adapter.log.debug(`For getHistory for id ${options.id}: Type empty, use storageType dbtype ${sqlDPs[options.id].dbtype}`);
1978
1978
  sqlDPs[options.id].type = sqlDPs[options.id].dbtype;
1979
1979
  }
1980
1980
  }
1981
1981
  else {
1982
- adapter.log.debug('For getHistory for id ' + options.id + ': Type empty, use dbtype ' + sqlDPs[options.id].dbtype);
1982
+ adapter.log.debug(`For getHistory for id ${options.id}: Type empty, use dbtype ${sqlDPs[options.id].dbtype}`);
1983
1983
  sqlDPs[options.id].type = sqlDPs[options.id].dbtype;
1984
1984
  }
1985
1985
  }
@@ -1987,7 +1987,7 @@ function getHistory(msg) {
1987
1987
  // read or create in DB
1988
1988
  return getId(options.id, null, err => {
1989
1989
  if (err) {
1990
- adapter.log.warn('Cannot get index of "' + options.id + '": ' + err);
1990
+ adapter.log.warn(`Cannot get index of "${options.id}": ${err}`);
1991
1991
  commons.sendResponse(adapter, msg, options, [], startTime);
1992
1992
  } else {
1993
1993
  getHistory(msg);
@@ -1995,7 +1995,7 @@ function getHistory(msg) {
1995
1995
  });
1996
1996
  }
1997
1997
  if (options.id && sqlDPs[options.id].type === undefined) {
1998
- adapter.log.warn('For getHistory for id ' + options.id + ': Type empty. Need to write data first. Index = ' + sqlDPs[options.id].index);
1998
+ adapter.log.warn(`For getHistory for id "${options.id}": Type empty. Need to write data first. Index = ${sqlDPs[options.id].index}`);
1999
1999
  commons.sendResponse(adapter, msg, options, 'Please wait till next data record is logged and reload.', startTime);
2000
2000
  return;
2001
2001
  }
@@ -2601,7 +2601,7 @@ function main() {
2601
2601
  if (adapter.config.dbtype === 'sqlite' || adapter.config.host) {
2602
2602
  connect(() => {
2603
2603
  // read all custom settings
2604
- adapter.getObjectView('system', 'custom', {}, (err, doc) => {
2604
+ adapter.getObjectView('system', 'custom' , {}, (err, doc) => {
2605
2605
  let count = 0;
2606
2606
  if (doc && doc.rows) {
2607
2607
  for (let i = 0, l = doc.rows.length; i < l; i++) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "iobroker.sql",
3
3
  "description": "Log state sql in a two-stages process (first to Redis, then to CouchDB)",
4
- "version": "1.16.1",
4
+ "version": "1.16.2",
5
5
  "author": "bluefox <dogafox@gmail.com>",
6
6
  "contributors": [
7
7
  "bluefox <dogafox@gmail.com>",
@@ -22,22 +22,22 @@
22
22
  ],
23
23
  "optionalDependencies": {
24
24
  "mysql": "^2.18.1",
25
- "pg": "^8.7.1",
25
+ "pg": "^8.7.3",
26
26
  "sqlite3": "^5.0.2",
27
- "mssql": "^6.3.1"
27
+ "mssql": "^6.4.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "sql-client": "^3.0.0",
31
31
  "@iobroker/adapter-core": "^2.5.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@alcalzone/release-script": "^3.4.2",
35
- "@alcalzone/release-script-plugin-iobroker": "^3.4.1",
36
- "@alcalzone/release-script-plugin-license": "^3.4.1",
37
- "axios": "^0.24.0",
34
+ "@alcalzone/release-script": "^3.5.2",
35
+ "@alcalzone/release-script-plugin-iobroker": "^3.5.1",
36
+ "@alcalzone/release-script-plugin-license": "^3.5.0",
37
+ "axios": "^0.26.0",
38
38
  "gulp": "^4.0.2",
39
- "mocha": "^9.1.3",
40
- "chai": "^4.3.4"
39
+ "mocha": "^9.2.0",
40
+ "chai": "^4.3.6"
41
41
  },
42
42
  "bugs": {
43
43
  "url": "https://github.com/ioBroker/ioBroker.sql/issues"