iobroker.sql 2.1.0 → 2.1.3
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/README.md +9 -0
- package/admin/i18n/de/translations.json +1 -1
- package/admin/i18n/zh-cn/translations.json +2 -2
- package/admin/words.js +3 -3
- package/io-package.json +38 -37
- package/lib/aggregate.js +273 -206
- package/main.js +4 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -520,6 +520,15 @@ sendTo('sql.0', 'getEnabledDPs', {}, function (result) {
|
|
|
520
520
|
-->
|
|
521
521
|
|
|
522
522
|
## Changelog
|
|
523
|
+
### 2.1.3 (2022-06-12)
|
|
524
|
+
* (Apollon77) Make sure debug log is active according to the settings
|
|
525
|
+
|
|
526
|
+
### 2.1.2 (2022-06-08)
|
|
527
|
+
* (Apollon77) Huge performance optimizations for GetHistory calls
|
|
528
|
+
|
|
529
|
+
### 2.1.1 (2022-05-30)
|
|
530
|
+
* (Apollon77) Fix crash cases reported by Sentry
|
|
531
|
+
|
|
523
532
|
### 2.1.0 (2022-05-27)
|
|
524
533
|
* (Apollon77) Fix crash cases reported by Sentry
|
|
525
534
|
* (Apollon77) Fix several places where pooled connections might have not been returned to pool correctly and add logging for it
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"Round real to": "Runden Sie bei der Abfrage die Zahlen auf",
|
|
51
51
|
"SQL history adapter settings": "SQL History Adapter Einstellungen",
|
|
52
52
|
"Start or enable adapter first": "Adapter muss zuerst aktiviert werden",
|
|
53
|
-
"Storage retention": "
|
|
53
|
+
"Storage retention": "Aufbewahrungsdauer",
|
|
54
54
|
"Store as": "Speichern als",
|
|
55
55
|
"String": "Zeichenfolge",
|
|
56
56
|
"Test connection": "Verbindung testen",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"Enter a number or leave the field empty": "输入一个数字或将该字段留空以不限制记录的值",
|
|
35
35
|
"File for sqlite": "申请sqlite",
|
|
36
36
|
"History adapter settings": "历史记录适配器设置",
|
|
37
|
-
"Host": "
|
|
37
|
+
"Host": "主机",
|
|
38
38
|
"Input path with the file name.": "例如。 ",
|
|
39
39
|
"Maximum concurrent connections": "最大并发连接数",
|
|
40
40
|
"Maximum concurrent connections:": "最大并发连接数:",
|
|
41
41
|
"Number": "数字",
|
|
42
42
|
"Number of days to keep the data.": "保留数据的天数。",
|
|
43
|
-
"Ok": "
|
|
43
|
+
"Ok": "确定",
|
|
44
44
|
"Password": "密码",
|
|
45
45
|
"Password confirm": "确认密码",
|
|
46
46
|
"Password confirmation is not equal with password!": "密码确认不等于密码!",
|
package/admin/words.js
CHANGED
|
@@ -37,13 +37,13 @@ systemDictionary = {
|
|
|
37
37
|
"Enter a number or leave the field empty": { "en": "Enter a number or leave the field empty to not limit the recorded values", "de": "Eine Zahl angeben oder das Feld leer lassen, um die aufgezeichneten Werte nicht einzuschränken", "ru": "Введите число или оставьте поле пустым, чтобы не ограничивать записываемые значения", "pt": "Digite um número ou deixe o campo vazio para não limitar os valores registrados", "nl": "Voer een getal in of laat het veld leeg om de geregistreerde waarden niet te beperken", "fr": "Entrez un nombre ou laissez le champ vide pour ne pas limiter les valeurs enregistrées", "it": "Immettere un numero o lasciare il campo vuoto per non limitare i valori registrati", "es": "Introduzca un número o deje el campo vacío para no limitar los valores registrados", "pl": "Wpisz liczbę lub pozostaw puste pole, aby nie ograniczać rejestrowanych wartości", "zh-cn": "输入一个数字或将该字段留空以不限制记录的值"},
|
|
38
38
|
"File for sqlite": { "en": "File for sqlite", "de": "Datei für sqlite", "ru": "Файл для sqlite", "pt": "Arquivo para sqlite", "nl": "Bestand voor sqlite", "fr": "Fichier pour sqlite", "it": "File per sqlite", "es": "Archivo para sqlite", "pl": "Plik dla sqlite", "zh-cn": "申请sqlite"},
|
|
39
39
|
"History adapter settings": { "en": "History adapter settings", "de": "History-Adapter Einstellungen", "ru": "Настройки драйвера history", "pt": "Configurações do adaptador de histórico", "nl": "Geschiedenis adapter instellingen", "fr": "Paramètres de l'adaptateur d'historique", "it": "Impostazioni della scheda Cronologia", "es": "Configuración del adaptador de historial", "pl": "Ustawienia adaptera historii", "zh-cn": "历史记录适配器设置"},
|
|
40
|
-
"Host": { "en": "Host", "de": "Server", "ru": "Хост", "pt": "Hospedeiro", "nl": "Host", "fr": "Hôte", "it": "Ospite", "es": "Anfitrión", "pl": "Gospodarz", "zh-cn": "
|
|
40
|
+
"Host": { "en": "Host", "de": "Server", "ru": "Хост", "pt": "Hospedeiro", "nl": "Host", "fr": "Hôte", "it": "Ospite", "es": "Anfitrión", "pl": "Gospodarz", "zh-cn": "主机"},
|
|
41
41
|
"Input path with the file name.": { "en": "E.g. /opt/sqlite/data.db", "de": "Z.B. /opt/sqlite/data.db", "ru": "Например /opt/sqlite/data.db", "pt": "Por exemplo. /opt/sqlite/data.db", "nl": "Bijv. /opt/sqlite/data.db", "fr": "Par exemple. /opt/sqlite/data.db", "it": "Per esempio. /opt/sqlite/data.db", "es": "P.ej. /opt/sqlite/data.db", "pl": "Na przykład. /opt/sqlite/data.db", "zh-cn": "例如。 "},
|
|
42
42
|
"Maximum concurrent connections": { "en": "Maximum concurrent connections", "de": "Max. gleichzeitige Verbindungen", "ru": "Максимальное количество одновременных подключений", "pt": "Máximo de conexões simultâneas", "nl": "Maximum aantal gelijktijdige verbindingen", "fr": "Nombre maximal de connexions simultanées", "it": "Numero massimo di connessioni simultanee", "es": "Máximas conexiones concurrentes", "pl": "Maksymalna liczba jednoczesnych połączeń", "zh-cn": "最大并发连接数"},
|
|
43
43
|
"Maximum concurrent connections:": { "en": "Maximum concurrent connections:", "de": "Maximale Anzahl parallele Verbindungen:", "ru": "Максимальное количество одновременных подключений:", "pt": "Máximo de conexões simultâneas:", "nl": "Maximale gelijktijdige verbindingen:", "fr": "Connexions simultanées maximales :", "it": "Numero massimo di connessioni simultanee:", "es": "Máximo de conexiones simultáneas:", "pl": "Maksymalna liczba jednoczesnych połączeń:", "zh-cn": "最大并发连接数:"},
|
|
44
44
|
"Number": { "en": "Number", "de": "Zahl", "ru": "Число", "pt": "Número", "nl": "Aantal", "fr": "Nombre", "it": "Numero", "es": "Numer", "pl": "Numer", "zh-cn": "数字"},
|
|
45
45
|
"Number of days to keep the data.": { "en": "Number of days to keep the data.", "de": "Anzahl der Tage, um die Daten aufzubewahren.", "ru": "Количество дней хранения данных.", "pt": "Número de dias para manter os dados.", "nl": "Aantal dagen om de gegevens te bewaren.", "fr": "Nombre de jours de conservation des données.", "it": "Numero di giorni di conservazione dei dati.", "es": "Número de días para conservar los datos.", "pl": "Liczba dni przechowywania danych.", "zh-cn": "保留数据的天数。"},
|
|
46
|
-
"Ok": { "en": "Ok", "de": "Ok", "ru": "Ok", "pt": "Ok", "nl": "OK", "fr": "D'accord", "it": "Ok", "es": "De acuerdo", "pl": "Ok", "zh-cn": "
|
|
46
|
+
"Ok": { "en": "Ok", "de": "Ok", "ru": "Ok", "pt": "Ok", "nl": "OK", "fr": "D'accord", "it": "Ok", "es": "De acuerdo", "pl": "Ok", "zh-cn": "确定"},
|
|
47
47
|
"Password": { "en": "Password", "de": "Passwort", "ru": "Пароль", "pt": "Senha", "nl": "Wachtwoord", "fr": "Mot de passe", "it": "Parola d'ordine", "es": "Contraseña", "pl": "Hasło", "zh-cn": "密码"},
|
|
48
48
|
"Password confirm": { "en": "Password confirm", "de": "Passwort-Wiederholung", "ru": "Подтверждение пароля", "pt": "Confirmação de senha", "nl": "Wachtwoord bevestigen", "fr": "Confirmer le mot de passe", "it": "Conferma la password", "es": "Contraseña confirmada", "pl": "Potwierdź hasło", "zh-cn": "确认密码"},
|
|
49
49
|
"Password confirmation is not equal with password!": {"en": "Password confirmation is not equal with password!", "de": "Passwort-Bestätigung stimmt nicht mit dem Passwort überein!", "ru": "Подтверждение пароля не совпадает с паролем!", "pt": "A confirmação da senha não é igual com a senha!", "nl": "Wachtwoordbevestiging is niet gelijk aan wachtwoord!", "fr": "La confirmation du mot de passe n'est pas égale au mot de passe!", "it": "La conferma della password non è uguale alla password!", "es": "La confirmación de la contraseña no es igual a la contraseña!", "pl": "Potwierdzenie hasła nie jest równe hasłu!", "zh-cn": "密码确认不等于密码!"},
|
|
@@ -53,7 +53,7 @@ systemDictionary = {
|
|
|
53
53
|
"Round real to": { "en": "On query round numbers to", "de": "Runden Sie bei der Abfrage die Zahlen auf", "ru": "По запросу округлить числа до", "pt": "Na consulta arredondar os números para", "nl": "Op query ronde getallen naar", "fr": "Sur requête arrondir les nombres à", "it": "Su interrogazione arrotondare i numeri a", "es": "En consulta números redondos a", "pl": "Na zapytanie okrągłe liczby do", "zh-cn": "在查询轮数到"},
|
|
54
54
|
"SQL history adapter settings": { "en": "SQL history adapter settings", "de": "SQL History Adapter Einstellungen", "ru": "Настройки профайлера в SQL базу данных", "pt": "Configurações do adaptador de histórico SQL", "nl": "Instellingen voor SQL-geschiedenisadapter", "fr": "Paramètres de l'adaptateur d'historique SQL", "it": "Impostazioni della scheda cronologia SQL", "es": "Configuración del adaptador de historial SQL", "pl": "Ustawienia adaptera historii SQL", "zh-cn": "SQL历史记录适配器设置"},
|
|
55
55
|
"Start or enable adapter first": { "en": "Start or enable adapter first", "de": "Adapter muss zuerst aktiviert werden", "ru": "Сначала надо запустить или активировать драйвер", "pt": "Inicie ou ative o adaptador primeiro", "nl": "Start of schakel eerst de adapter in", "fr": "Démarrer ou activer l'adaptateur en premier", "it": "Inizia o abilita prima l'adattatore", "es": "Comience o habilite el adaptador primero", "pl": "Najpierw włącz lub włącz adapter", "zh-cn": "首先启动或启用适配器"},
|
|
56
|
-
"Storage retention": { "en": "Storage retention", "de": "
|
|
56
|
+
"Storage retention": { "en": "Storage retention", "de": "Aufbewahrungsdauer", "ru": "Сохранять в файле", "pt": "Retenção de armazenamento", "nl": "Opslag retentie", "fr": "Conservation du stockage", "it": "Conservazione di memoria", "es": "Retención de almacenamiento", "pl": "Przechowywanie danych", "zh-cn": "存储保留"},
|
|
57
57
|
"Store as": { "en": "Store as", "de": "Speichern als", "ru": "Сохранить как", "pt": "Armazenar como", "nl": "Opslaan als", "fr": "Magasin comme", "it": "Conservare come", "es": "Przechowuj jako", "pl": "Przechowuj jako", "zh-cn": "存储为"},
|
|
58
58
|
"String": { "en": "String", "de": "Zeichenfolge", "ru": "строка", "pt": "Corda", "nl": "Draad", "fr": "Chaîne", "it": "Stringa", "es": "Strunowy", "pl": "Strunowy", "zh-cn": "细绳"},
|
|
59
59
|
"Test connection": { "en": "Test connection", "de": "Verbindung testen", "ru": "Проверить соединение", "pt": "Conexão de teste", "nl": "Test verbinding", "fr": "Test de connexion", "it": "Connessione di prova", "es": "Conexión de prueba", "pl": "Testuj połączenie", "zh-cn": "测试连接"},
|
package/io-package.json
CHANGED
|
@@ -26,8 +26,44 @@
|
|
|
26
26
|
"pl": "Rejestrowanie stanów w SQL DB",
|
|
27
27
|
"zh-cn": "将状态记录到SQL DB"
|
|
28
28
|
},
|
|
29
|
-
"version": "2.1.
|
|
29
|
+
"version": "2.1.3",
|
|
30
30
|
"news": {
|
|
31
|
+
"2.1.3": {
|
|
32
|
+
"en": "Make sure debug log is active according to the settings",
|
|
33
|
+
"de": "Stellen Sie sicher, dass das Debug-Log gemäß den Einstellungen aktiv ist",
|
|
34
|
+
"ru": "Убедитесь, что журнал debug активен в соответствии с настройками",
|
|
35
|
+
"pt": "Certifique-se de que o log de depuração está ativo de acordo com as configurações",
|
|
36
|
+
"nl": "Zorg ervoor dat het logboek actief is volgens de instellingen",
|
|
37
|
+
"fr": "Assurez-vous que le journal debug est actif selon les paramètres",
|
|
38
|
+
"it": "Assicurarsi che il registro di debug sia attivo in base alle impostazioni",
|
|
39
|
+
"es": "Asegúrese de que el registro de depuración está activo según la configuración",
|
|
40
|
+
"pl": "Umożliwia to, że log debug jest aktywny zgodnie z ustawieniami",
|
|
41
|
+
"zh-cn": "B. 根据环境,确保有色色逻辑积极。"
|
|
42
|
+
},
|
|
43
|
+
"2.1.2": {
|
|
44
|
+
"en": "Huge performance optimizations for GetHistory calls",
|
|
45
|
+
"de": "Riesige Leistungsoptimierungen für GetHistory-Anrufe",
|
|
46
|
+
"ru": "Огромная оптимизация производительности для звонков GetHistory",
|
|
47
|
+
"pt": "Otimizações de desempenho enormes para chamadas GetHistory",
|
|
48
|
+
"nl": "Grote prestaties voor GetHistory",
|
|
49
|
+
"fr": "Des optimisations de performance énormes pour les appels GetHistory",
|
|
50
|
+
"it": "Ottimizzazione delle prestazioni enormi per le chiamate GetHistory",
|
|
51
|
+
"es": "Amplias optimizaciones de rendimiento para llamadas GetHistory",
|
|
52
|
+
"pl": "Optymalizacja wyników Huge'a dla GetHistory'ego nawołuje się do optymalizacji wydajności",
|
|
53
|
+
"zh-cn": "GetHistory呼声的优越性"
|
|
54
|
+
},
|
|
55
|
+
"2.1.1": {
|
|
56
|
+
"en": "Fix crash cases reported by Sentry",
|
|
57
|
+
"de": "Von Sentry gemeldete Absturzfälle beheben",
|
|
58
|
+
"ru": "Исправить случаи сбоев, о которых сообщил Sentry",
|
|
59
|
+
"pt": "Corrigir casos de travamento relatados pelo Sentinela",
|
|
60
|
+
"nl": "Herstel crashgevallen gemeld door Sentry",
|
|
61
|
+
"fr": "Correction des cas de plantage signalés par Sentry",
|
|
62
|
+
"it": "Risolvi i casi di crash segnalati da Sentry",
|
|
63
|
+
"es": "Solucionar casos de fallas informados por Sentry",
|
|
64
|
+
"pl": "Napraw przypadki awarii zgłoszone przez Sentry",
|
|
65
|
+
"zh-cn": "修复 Sentry 报告的崩溃案例"
|
|
66
|
+
},
|
|
31
67
|
"2.1.0": {
|
|
32
68
|
"en": "Fix crash cases reported by Sentry\nFix several places where pooled connections might have not been returned to pool correctly and add logging for it\nWork around an issue in used Pooling library that potentially gave out too many connections\nOptimize retention check to better spread the first checks over time\nDefault to not use datapoint buffering as in 1.x when set to 0\nMake sure disabling \"Log changes only\" also really do not log the changes anymore\nAllow storeState and GetHistory also to be called for \"unknown ids\"\nAdjust the fallback logic for type detection to use the type of the state value to log as last fallback\nFix storing booleans on MSSQL",
|
|
33
69
|
"de": "Von Sentry gemeldete Absturzfälle beheben\nBeheben Sie mehrere Stellen, an denen gepoolte Verbindungen möglicherweise nicht korrekt an den Pool zurückgegeben wurden, und fügen Sie die Protokollierung dafür hinzu\nUmgehung eines Problems in der verwendeten Pooling-Bibliothek, das möglicherweise zu viele Verbindungen ausgegeben hat\nOptimieren Sie die Aufbewahrungsprüfung, um die ersten Prüfungen besser über die Zeit zu verteilen\nStandardmäßig keine Datenpunktpufferung wie in 1.x verwenden, wenn auf 0 gesetzt\nStellen Sie sicher, dass durch Deaktivieren von \"Nur Änderungen protokollieren\" die Änderungen auch wirklich nicht mehr protokolliert werden\nAufruf von storeState und GetHistory auch für \"unbekannte IDs\" zulassen\nPassen Sie die Fallback-Logik für die Typerkennung so an, dass der Typ des Statuswerts als letzter Fallback protokolliert wird\nFehler beim Speichern von booleschen Werten in MSSQL behoben",
|
|
@@ -75,42 +111,6 @@
|
|
|
75
111
|
"es": "Ocultar la configuración que no es relevante cuando no se utiliza \"solo cambios de registro\"\nPermitir todos los valores numéricos para antirrebote nuevamente",
|
|
76
112
|
"pl": "Ukryj ustawienia nieistotne, gdy nie używasz opcji „tylko rejestruj zmiany”\nZezwól ponownie na odrzucenie wszystkich wartości liczbowych",
|
|
77
113
|
"zh-cn": "不使用“仅记录更改”时隐藏不相关的设置\n再次允许所有数值去抖动"
|
|
78
|
-
},
|
|
79
|
-
"1.16.0": {
|
|
80
|
-
"en": "Support only `js-controller` 3.3.x+\nUsed system/custom view for collecting the objects\nImplemented option to ignore zero- or/and below zero- values",
|
|
81
|
-
"de": "Unterstützt nur `js-controller` 3.3.x+\nVerwendete Systemansicht/benutzerdefinierte Ansicht zum Sammeln der Objekte\nImplementierte Option zum Ignorieren von Null- oder/und Unter-Null-Werten",
|
|
82
|
-
"ru": "Поддерживает только `js-controller` 3.3.x+\nИспользуемый системный / пользовательский вид для сбора объектов\nРеализована возможность игнорировать нулевые и / или отрицательные значения.",
|
|
83
|
-
"pt": "Suporte apenas `js-controller` 3.3.x+\nSistema usado / visão personalizada para coletar os objetos\nOpção implementada para ignorar valores zero ou / e abaixo de zero",
|
|
84
|
-
"nl": "Ondersteuning alleen `js-controller` 3.3.x+\nGebruikt systeem/aangepaste weergave voor het verzamelen van de objecten\nGeïmplementeerde optie om nul- of/en onder nul-waarden te negeren",
|
|
85
|
-
"fr": "Supporte uniquement `js-controller` 3.3.x+\nSystème utilisé/vue personnalisée pour la collecte des objets\nOption implémentée pour ignorer les valeurs zéro ou/et inférieures à zéro",
|
|
86
|
-
"it": "Supporta solo `js-controller` 3.3.x+\nSistema utilizzato/vista personalizzata per la raccolta degli oggetti\nOpzione implementata per ignorare i valori zero o/o inferiori a zero",
|
|
87
|
-
"es": "Admite solo `js-controller` 3.3.x+\nSistema usado / vista personalizada para recolectar los objetos.\nOpción implementada para ignorar valores cero o inferiores a cero",
|
|
88
|
-
"pl": "Obsługuje tylko `js-controller` 3.3.x+\nWykorzystany widok systemowy/niestandardowy do zbierania obiektów\nZaimplementowana opcja ignorowania wartości zerowych lub/i poniżej zera",
|
|
89
|
-
"zh-cn": "仅支持 `js-controller` 3.3.x+\n用于收集对象的系统/自定义视图\n已实现忽略零或/和低于零值的选项"
|
|
90
|
-
},
|
|
91
|
-
"1.15.7": {
|
|
92
|
-
"en": "fixed the support of Admin5",
|
|
93
|
-
"de": "Die Unterstützung von Admin5 wurde behoben",
|
|
94
|
-
"ru": "исправлена поддержка Admin5",
|
|
95
|
-
"pt": "consertou o suporte do Admin5",
|
|
96
|
-
"nl": "de ondersteuning van Admin5 opgelost",
|
|
97
|
-
"fr": "correction du support d'Admin5",
|
|
98
|
-
"it": "risolto il supporto di Admin5",
|
|
99
|
-
"es": "arreglado el soporte de Admin5",
|
|
100
|
-
"pl": "naprawiono obsługę Admin5",
|
|
101
|
-
"zh-cn": "修复了对Admin5的支持"
|
|
102
|
-
},
|
|
103
|
-
"1.15.6": {
|
|
104
|
-
"en": "added support of Admin5",
|
|
105
|
-
"de": "Unterstützung von Admin5 hinzugefügt",
|
|
106
|
-
"ru": "добавлена поддержка Admin5",
|
|
107
|
-
"pt": "adicionado suporte de Admin5",
|
|
108
|
-
"nl": "toegevoegde ondersteuning van Admin5",
|
|
109
|
-
"fr": "ajout de la prise en charge d'Admin5",
|
|
110
|
-
"it": "aggiunto il supporto di Admin5",
|
|
111
|
-
"es": "soporte agregado de Admin5",
|
|
112
|
-
"pl": "dodana obsługa Admin5",
|
|
113
|
-
"zh-cn": "增加了对Admin5的支持"
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
116
|
"mode": "daemon",
|
|
@@ -162,6 +162,7 @@
|
|
|
162
162
|
"custom": "json"
|
|
163
163
|
},
|
|
164
164
|
"tier": 1,
|
|
165
|
+
"eraseOnUpload": true,
|
|
165
166
|
"connectionType": "none",
|
|
166
167
|
"dataSource": "push",
|
|
167
168
|
"messages": [
|
package/lib/aggregate.js
CHANGED
|
@@ -48,25 +48,35 @@ function initAggregate(options) {
|
|
|
48
48
|
|
|
49
49
|
log(`${options.logId} Initialize: maxIndex = ${options.maxIndex}, step = ${options.step}, start = ${options.start}, end = ${options.end}`);
|
|
50
50
|
// pre-fill the result with timestamps (add one before start and one after end)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
51
|
+
options.result.length = options.maxIndex + 2;
|
|
52
|
+
// We define the array length but do not prefill values, we do that on runtime when needed
|
|
53
|
+
options.result[0] = {
|
|
54
|
+
val: {ts: null, val: null},
|
|
55
|
+
max: {ts: null, val: null},
|
|
56
|
+
min: {ts: null, val: null},
|
|
57
|
+
start: {ts: null, val: null},
|
|
58
|
+
end: {ts: null, val: null}
|
|
59
|
+
};
|
|
60
|
+
options.result[options.maxIndex + 2] = {
|
|
61
|
+
val: {ts: null, val: null},
|
|
62
|
+
max: {ts: null, val: null},
|
|
63
|
+
min: {ts: null, val: null},
|
|
64
|
+
start: {ts: null, val: null},
|
|
65
|
+
end: {ts: null, val: null}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
if (options.aggregate === 'average') {
|
|
69
|
+
options.averageCount[0] = 0;
|
|
70
|
+
options.averageCount[options.maxIndex + 2] = 0;
|
|
71
|
+
}
|
|
63
72
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
if (options.aggregate === 'percentile' || options.aggregate === 'quantile') {
|
|
74
|
+
options.quantileDatapoints[0] = [];
|
|
75
|
+
options.quantileDatapoints[options.maxIndex + 2] = [];
|
|
76
|
+
}
|
|
77
|
+
if (options.aggregate === 'integral') {
|
|
78
|
+
options.integralDatapoints[0] = [];
|
|
79
|
+
options.integralDatapoints[options.maxIndex + 2] = [];
|
|
70
80
|
}
|
|
71
81
|
return options;
|
|
72
82
|
}
|
|
@@ -112,9 +122,25 @@ function aggregation(options, data) {
|
|
|
112
122
|
}
|
|
113
123
|
options.overallLength++;
|
|
114
124
|
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
if (options.result[index] === undefined) { // lazy initialization of datastructure
|
|
126
|
+
options.result[index] = {
|
|
127
|
+
val: {ts: null, val: null},
|
|
128
|
+
max: {ts: null, val: null},
|
|
129
|
+
min: {ts: null, val: null},
|
|
130
|
+
start: {ts: null, val: null},
|
|
131
|
+
end: {ts: null, val: null}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
if (options.aggregate === 'average') {
|
|
135
|
+
options.averageCount[index] = 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (options.aggregate === 'percentile' || options.aggregate === 'quantile') {
|
|
139
|
+
options.quantileDatapoints[index] = [];
|
|
140
|
+
}
|
|
141
|
+
if (options.aggregate === 'integral') {
|
|
142
|
+
options.integralDatapoints[index] = [];
|
|
143
|
+
}
|
|
118
144
|
}
|
|
119
145
|
|
|
120
146
|
aggregationLogic(data[i], index, options);
|
|
@@ -217,203 +243,220 @@ function finishAggregation(options) {
|
|
|
217
243
|
let postBorderValueRemoved = false;
|
|
218
244
|
const originalResultLength = options.result.length;
|
|
219
245
|
|
|
220
|
-
|
|
246
|
+
let startIndex = 0;
|
|
247
|
+
let endIndex = options.result.length;
|
|
248
|
+
const finalResult = [];
|
|
249
|
+
|
|
250
|
+
for (let ii = startIndex; ii < endIndex; ii++) {
|
|
221
251
|
// no one value in this period
|
|
222
|
-
if (options.result[ii].start.ts === null) {
|
|
252
|
+
if (options.result[ii] === undefined || options.result[ii].start.ts === null) {
|
|
223
253
|
if (ii === 0) {
|
|
224
254
|
preBorderValueRemoved = true;
|
|
225
255
|
} else if (ii === originalResultLength - 1) {
|
|
226
256
|
postBorderValueRemoved = true;
|
|
227
257
|
}
|
|
228
|
-
options.result.splice(ii, 1);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
options.result[ii].end.ts === options.result[ii].min.ts) {
|
|
241
|
-
options.result.splice(ii + 1, 0, {
|
|
242
|
-
ts: options.result[ii].end.ts,
|
|
243
|
-
val: options.result[ii].end.val
|
|
244
|
-
});
|
|
245
|
-
options.result[ii] = {
|
|
246
|
-
ts: options.result[ii].start.ts,
|
|
247
|
-
val: options.result[ii].start.val
|
|
248
|
-
};
|
|
249
|
-
} // if just 3 values: start, min == max, end
|
|
250
|
-
else {
|
|
251
|
-
options.result.splice(ii + 1, 0, {
|
|
252
|
-
ts: options.result[ii].max.ts,
|
|
253
|
-
val: options.result[ii].max.val
|
|
254
|
-
});
|
|
255
|
-
options.result.splice(ii + 2, 0, {
|
|
256
|
-
ts: options.result[ii].end.ts,
|
|
257
|
-
val: options.result[ii].end.val
|
|
258
|
-
});
|
|
259
|
-
options.result[ii] = {
|
|
260
|
-
ts: options.result[ii].start.ts,
|
|
261
|
-
val: options.result[ii].start.val
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
} else
|
|
265
|
-
if (options.result[ii].start.ts === options.result[ii].max.ts) {
|
|
266
|
-
// just one value in this period: start == max, min == end
|
|
267
|
-
if (options.result[ii].min.ts === options.result[ii].end.ts) {
|
|
268
|
-
options.result.splice(ii + 1, 0, {
|
|
269
|
-
ts: options.result[ii].end.ts,
|
|
270
|
-
val: options.result[ii].end.val
|
|
271
|
-
});
|
|
272
|
-
options.result[ii] = {
|
|
273
|
-
ts: options.result[ii].start.ts,
|
|
274
|
-
val: options.result[ii].start.val
|
|
275
|
-
};
|
|
276
|
-
} // start == max, min, end
|
|
277
|
-
else {
|
|
278
|
-
options.result.splice(ii + 1, 0, {
|
|
279
|
-
ts: options.result[ii].min.ts,
|
|
280
|
-
val: options.result[ii].min.val
|
|
281
|
-
});
|
|
282
|
-
options.result.splice(ii + 2, 0, {
|
|
283
|
-
ts: options.result[ii].end.ts,
|
|
284
|
-
val: options.result[ii].end.val
|
|
285
|
-
});
|
|
286
|
-
options.result[ii] = {
|
|
287
|
-
ts: options.result[ii].start.ts,
|
|
288
|
-
val: options.result[ii].start.val
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
} else
|
|
292
|
-
if (options.result[ii].end.ts === options.result[ii].max.ts) {
|
|
293
|
-
// just one value in this period: start == min, max == end
|
|
294
|
-
if (options.result[ii].min.ts === options.result[ii].start.ts) {
|
|
295
|
-
options.result.splice(ii + 1, 0, {
|
|
296
|
-
ts: options.result[ii].end.ts,
|
|
297
|
-
val: options.result[ii].end.val
|
|
298
|
-
});
|
|
299
|
-
options.result[ii] = {
|
|
300
|
-
ts: options.result[ii].start.ts,
|
|
301
|
-
val: options.result[ii].start.val
|
|
302
|
-
};
|
|
303
|
-
} // start, min, max == end
|
|
304
|
-
else {
|
|
305
|
-
options.result.splice(ii + 1, 0, {
|
|
306
|
-
ts: options.result[ii].min.ts,
|
|
307
|
-
val: options.result[ii].min.val
|
|
308
|
-
});
|
|
309
|
-
options.result.splice(ii + 2, 0, {
|
|
310
|
-
ts: options.result[ii].end.ts,
|
|
311
|
-
val: options.result[ii].end.val
|
|
312
|
-
});
|
|
313
|
-
options.result[ii] = {
|
|
314
|
-
ts: options.result[ii].start.ts,
|
|
315
|
-
val: options.result[ii].start.val
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
} else
|
|
258
|
+
//options.result.splice(ii, 1);
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
// just one value in this period: max == min == start == end
|
|
262
|
+
if (options.result[ii].start.ts === options.result[ii].end.ts) {
|
|
263
|
+
finalResult.push({
|
|
264
|
+
ts: options.result[ii].start.ts,
|
|
265
|
+
val: options.result[ii].start.val
|
|
266
|
+
});
|
|
267
|
+
} else
|
|
268
|
+
if (options.result[ii].min.ts === options.result[ii].max.ts) {
|
|
269
|
+
// if just 2 values: start == min == max, end
|
|
319
270
|
if (options.result[ii].start.ts === options.result[ii].min.ts ||
|
|
320
271
|
options.result[ii].end.ts === options.result[ii].min.ts) {
|
|
321
|
-
|
|
322
|
-
|
|
272
|
+
finalResult.push({
|
|
273
|
+
ts: options.result[ii].start.ts,
|
|
274
|
+
val: options.result[ii].start.val
|
|
275
|
+
});
|
|
276
|
+
finalResult.push({
|
|
277
|
+
ts: options.result[ii].end.ts,
|
|
278
|
+
val: options.result[ii].end.val
|
|
279
|
+
});
|
|
280
|
+
} // if just 3 values: start, min == max, end
|
|
281
|
+
else {
|
|
282
|
+
finalResult.push({
|
|
283
|
+
ts: options.result[ii].start.ts,
|
|
284
|
+
val: options.result[ii].start.val
|
|
285
|
+
});
|
|
286
|
+
finalResult.push({
|
|
323
287
|
ts: options.result[ii].max.ts,
|
|
324
288
|
val: options.result[ii].max.val
|
|
325
289
|
});
|
|
326
|
-
|
|
290
|
+
finalResult.push({
|
|
327
291
|
ts: options.result[ii].end.ts,
|
|
328
292
|
val: options.result[ii].end.val
|
|
329
293
|
});
|
|
330
|
-
|
|
294
|
+
}
|
|
295
|
+
} else
|
|
296
|
+
if (options.result[ii].start.ts === options.result[ii].max.ts) {
|
|
297
|
+
// just one value in this period: start == max, min == end
|
|
298
|
+
if (options.result[ii].min.ts === options.result[ii].end.ts) {
|
|
299
|
+
finalResult.push({
|
|
331
300
|
ts: options.result[ii].start.ts,
|
|
332
301
|
val: options.result[ii].start.val
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
// just one value in this period: start == min, max, end
|
|
336
|
-
if (options.result[ii].max.ts > options.result[ii].min.ts) {
|
|
337
|
-
options.result.splice(ii + 1, 0, {
|
|
338
|
-
ts: options.result[ii].min.ts,
|
|
339
|
-
val: options.result[ii].min.val
|
|
340
|
-
});
|
|
341
|
-
options.result.splice(ii + 2, 0, {
|
|
342
|
-
ts: options.result[ii].max.ts,
|
|
343
|
-
val: options.result[ii].max.val
|
|
344
|
-
});
|
|
345
|
-
} else {
|
|
346
|
-
options.result.splice(ii + 1, 0, {
|
|
347
|
-
ts: options.result[ii].max.ts,
|
|
348
|
-
val: options.result[ii].max.val
|
|
349
|
-
});
|
|
350
|
-
options.result.splice(ii + 2, 0, {
|
|
351
|
-
ts: options.result[ii].min.ts,
|
|
352
|
-
val: options.result[ii].min.val
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
options.result.splice(ii + 3, 0, {
|
|
302
|
+
});
|
|
303
|
+
finalResult.push({
|
|
356
304
|
ts: options.result[ii].end.ts,
|
|
357
305
|
val: options.result[ii].end.val
|
|
358
306
|
});
|
|
359
|
-
|
|
307
|
+
} // start == max, min, end
|
|
308
|
+
else {
|
|
309
|
+
finalResult.push({
|
|
360
310
|
ts: options.result[ii].start.ts,
|
|
361
311
|
val: options.result[ii].start.val
|
|
362
|
-
};
|
|
312
|
+
});
|
|
313
|
+
finalResult.push({
|
|
314
|
+
ts: options.result[ii].min.ts,
|
|
315
|
+
val: options.result[ii].min.val
|
|
316
|
+
});
|
|
317
|
+
finalResult.push({
|
|
318
|
+
ts: options.result[ii].end.ts,
|
|
319
|
+
val: options.result[ii].end.val
|
|
320
|
+
});
|
|
363
321
|
}
|
|
322
|
+
} else
|
|
323
|
+
if (options.result[ii].end.ts === options.result[ii].max.ts) {
|
|
324
|
+
// just one value in this period: start == min, max == end
|
|
325
|
+
if (options.result[ii].min.ts === options.result[ii].start.ts) {
|
|
326
|
+
finalResult.push({
|
|
327
|
+
ts: options.result[ii].start.ts,
|
|
328
|
+
val: options.result[ii].start.val
|
|
329
|
+
});
|
|
330
|
+
finalResult.push({
|
|
331
|
+
ts: options.result[ii].end.ts,
|
|
332
|
+
val: options.result[ii].end.val
|
|
333
|
+
});
|
|
334
|
+
} // start, min, max == end
|
|
335
|
+
else {
|
|
336
|
+
finalResult.push({
|
|
337
|
+
ts: options.result[ii].start.ts,
|
|
338
|
+
val: options.result[ii].start.val
|
|
339
|
+
});
|
|
340
|
+
finalResult.push({
|
|
341
|
+
ts: options.result[ii].min.ts,
|
|
342
|
+
val: options.result[ii].min.val
|
|
343
|
+
});
|
|
344
|
+
finalResult.push({
|
|
345
|
+
ts: options.result[ii].end.ts,
|
|
346
|
+
val: options.result[ii].end.val
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
} else
|
|
350
|
+
if (options.result[ii].start.ts === options.result[ii].min.ts ||
|
|
351
|
+
options.result[ii].end.ts === options.result[ii].min.ts) {
|
|
352
|
+
// just one value in this period: start == min, max, end
|
|
353
|
+
finalResult.push({
|
|
354
|
+
ts: options.result[ii].start.ts,
|
|
355
|
+
val: options.result[ii].start.val
|
|
356
|
+
});
|
|
357
|
+
finalResult.push({
|
|
358
|
+
ts: options.result[ii].max.ts,
|
|
359
|
+
val: options.result[ii].max.val
|
|
360
|
+
});
|
|
361
|
+
finalResult.push({
|
|
362
|
+
ts: options.result[ii].end.ts,
|
|
363
|
+
val: options.result[ii].end.val
|
|
364
|
+
});
|
|
365
|
+
} else {
|
|
366
|
+
finalResult.push({
|
|
367
|
+
ts: options.result[ii].start.ts,
|
|
368
|
+
val: options.result[ii].start.val
|
|
369
|
+
});
|
|
370
|
+
// just one value in this period: start == min, max, end
|
|
371
|
+
if (options.result[ii].max.ts > options.result[ii].min.ts) {
|
|
372
|
+
finalResult.push({
|
|
373
|
+
ts: options.result[ii].min.ts,
|
|
374
|
+
val: options.result[ii].min.val
|
|
375
|
+
});
|
|
376
|
+
finalResult.push({
|
|
377
|
+
ts: options.result[ii].max.ts,
|
|
378
|
+
val: options.result[ii].max.val
|
|
379
|
+
});
|
|
380
|
+
} else {
|
|
381
|
+
finalResult.push({
|
|
382
|
+
ts: options.result[ii].max.ts,
|
|
383
|
+
val: options.result[ii].max.val
|
|
384
|
+
});
|
|
385
|
+
finalResult.push({
|
|
386
|
+
ts: options.result[ii].min.ts,
|
|
387
|
+
val: options.result[ii].min.val
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
finalResult.push({
|
|
391
|
+
ts: options.result[ii].end.ts,
|
|
392
|
+
val: options.result[ii].end.val
|
|
393
|
+
});
|
|
364
394
|
}
|
|
365
395
|
}
|
|
366
396
|
if (options.removeBorderValues) { // we cut out the additional results
|
|
367
397
|
if (!preBorderValueRemoved) {
|
|
368
|
-
|
|
398
|
+
finalResult.splice(0, 1);
|
|
369
399
|
}
|
|
370
400
|
if (!postBorderValueRemoved) {
|
|
371
|
-
|
|
401
|
+
finalResult.length--;
|
|
372
402
|
}
|
|
373
403
|
}
|
|
404
|
+
options.result = finalResult;
|
|
374
405
|
} else if (options.aggregate === 'average') {
|
|
406
|
+
let startIndex = 0;
|
|
407
|
+
let endIndex = options.result.length;
|
|
408
|
+
const finalResult = [];
|
|
375
409
|
if (options.removeBorderValues) { // we cut out the additional results
|
|
376
|
-
options.result.splice(0, 1);
|
|
377
|
-
options.averageCount.splice(0, 1);
|
|
378
|
-
options.result.
|
|
379
|
-
options.averageCount.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
410
|
+
// options.result.splice(0, 1);
|
|
411
|
+
// options.averageCount.splice(0, 1);
|
|
412
|
+
// options.result.length--;
|
|
413
|
+
// options.averageCount.length--;
|
|
414
|
+
startIndex++;
|
|
415
|
+
endIndex--;
|
|
416
|
+
}
|
|
417
|
+
for (let k = startIndex; k < endIndex; k++) {
|
|
418
|
+
if (options.result[k] !== undefined && options.result[k].val.ts) {
|
|
419
|
+
finalResult.push({
|
|
384
420
|
ts: options.result[k].val.ts,
|
|
385
421
|
val: options.result[k].val.val !== null ? Math.round(options.result[k].val.val / options.averageCount[k] * 100) / 100 : null
|
|
386
|
-
};
|
|
422
|
+
});
|
|
387
423
|
} else {
|
|
388
424
|
// no one value in this interval
|
|
389
|
-
options.result.splice(k, 1);
|
|
390
|
-
options.averageCount.splice(k, 1);
|
|
425
|
+
//options.result.splice(k, 1);
|
|
426
|
+
//options.averageCount.splice(k, 1); // not needed to clean up because not used anymore afterwards
|
|
391
427
|
}
|
|
392
428
|
}
|
|
429
|
+
options.result = finalResult;
|
|
393
430
|
} else if (options.aggregate === 'integral') {
|
|
431
|
+
let preBorderValueRemoved = false;
|
|
432
|
+
let postBorderValueRemoved = false;
|
|
433
|
+
const originalResultLength = options.result.length;
|
|
434
|
+
const finalResult = [];
|
|
435
|
+
|
|
394
436
|
for (let k = 0; k < options.result.length; k++) {
|
|
395
437
|
let indexStartTs = options.start + ((k - 1) * options.step);
|
|
396
438
|
let indexEndTs = indexStartTs + options.step;
|
|
397
|
-
if (options.integralDatapoints[k].length) {
|
|
439
|
+
if (options.integralDatapoints[k] && options.integralDatapoints[k].length) {
|
|
398
440
|
// Sort datapoints by ts first
|
|
399
441
|
options.integralDatapoints[k].sort(sortByTs);
|
|
400
442
|
}
|
|
401
443
|
// Make sure that we have entries that always start at the beginning of the interval
|
|
402
|
-
if ((!options.integralDatapoints[k].length || options.integralDatapoints[k][0].ts > indexStartTs) && options.integralDatapoints[k - 1] && options.integralDatapoints[k -1][options.integralDatapoints[k - 1].length - 1]) {
|
|
444
|
+
if ((!options.integralDatapoints[k] || !options.integralDatapoints[k].length || options.integralDatapoints[k][0].ts > indexStartTs) && options.integralDatapoints[k - 1] && options.integralDatapoints[k -1][options.integralDatapoints[k - 1].length - 1]) {
|
|
403
445
|
// if the first entry of this interval started somewhere in the start of the interval, add a start entry
|
|
404
446
|
// same if there is no entry at all in the timeframe, use last entry from interval before
|
|
447
|
+
options.integralDatapoints[k] = options.integralDatapoints[k] || [];
|
|
405
448
|
options.integralDatapoints[k].unshift({
|
|
406
449
|
ts: indexStartTs,
|
|
407
450
|
val: options.integralDatapoints[k - 1][options.integralDatapoints[k - 1].length - 1].val
|
|
408
451
|
});
|
|
409
452
|
log(`${options.logId} Integral: ${k}: Added start entry for interval with ts=${indexStartTs}, val=${options.integralDatapoints[k][0].val}`);
|
|
410
|
-
} else if (options.integralDatapoints[k].length && options.integralDatapoints[k][0].ts > indexStartTs) {
|
|
453
|
+
} else if (options.integralDatapoints[k] && options.integralDatapoints[k].length && options.integralDatapoints[k][0].ts > indexStartTs) {
|
|
411
454
|
options.integralDatapoints[k].unshift({
|
|
412
455
|
ts: indexStartTs,
|
|
413
456
|
val: options.integralDatapoints[k][0].val
|
|
414
457
|
});
|
|
415
458
|
log(`${options.logId} Integral: ${k}: Added start entry for interval with ts=${indexStartTs}, val=${options.integralDatapoints[k][0].val} with same value as first point in interval because no former datapoint was found`);
|
|
416
|
-
} else if (options.integralDatapoints[k].length && options.integralDatapoints[k][0].ts < indexStartTs) {
|
|
459
|
+
} else if (options.integralDatapoints[k] && options.integralDatapoints[k].length && options.integralDatapoints[k][0].ts < indexStartTs) {
|
|
417
460
|
// if the first entry of this interval started before the start of the interval, search for the last value before the start of the interval, add as start entry
|
|
418
461
|
let preFirstIndex = null;
|
|
419
462
|
for (let kk = 0; kk < options.integralDatapoints[k].length; kk++) {
|
|
@@ -431,32 +474,35 @@ function finishAggregation(options) {
|
|
|
431
474
|
}
|
|
432
475
|
}
|
|
433
476
|
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
if (!options.result[k].val.ts) {
|
|
438
|
-
options.result[k].val.ts = Math.round(options.start + (((k - 1) + 0.5) * options.step));
|
|
477
|
+
const point = {
|
|
478
|
+
ts: options.result[k] !== undefined && options.result[k].val.ts ? options.result[k].val.ts : Math.round(options.start + (((k - 1) + 0.5) * options.step)),
|
|
479
|
+
val: null
|
|
439
480
|
}
|
|
481
|
+
|
|
482
|
+
const integralDatapoints = options.integralDatapoints[k] || [];
|
|
483
|
+
const vals = integralDatapoints.map(dp => `[${dp.ts}, ${dp.val}]`);
|
|
484
|
+
log(`${options.logId} Integral: ${k}: ${integralDatapoints.length} datapoints for interval for ${indexStartTs} - ${indexEndTs}: ${vals.join(',')}`);
|
|
485
|
+
|
|
440
486
|
// Calculate Intervals and always calculate till the interval end (start made sure above already)
|
|
441
|
-
for (let kk = 0; kk <
|
|
442
|
-
const valEndTs =
|
|
443
|
-
let valDuration = valEndTs -
|
|
487
|
+
for (let kk = 0; kk < integralDatapoints.length; kk++) {
|
|
488
|
+
const valEndTs = integralDatapoints[kk + 1] ? Math.min(integralDatapoints[kk + 1].ts, indexEndTs) : indexEndTs;
|
|
489
|
+
let valDuration = valEndTs - integralDatapoints[kk].ts;
|
|
444
490
|
if (valDuration < 0) {
|
|
445
|
-
log(`${options.logId} Integral: ${k}[${kk}] data do not belong to this interval, ignore ${JSON.stringify(
|
|
491
|
+
log(`${options.logId} Integral: ${k}[${kk}] data do not belong to this interval, ignore ${JSON.stringify(integralDatapoints[kk])} (vs. ${valEndTs})`)
|
|
446
492
|
break;
|
|
447
493
|
}
|
|
448
494
|
if (valDuration === 0) {
|
|
449
|
-
log(`${options.logId} Integral: ${k}[${kk}] valDuration zero, ignore ${JSON.stringify(
|
|
495
|
+
log(`${options.logId} Integral: ${k}[${kk}] valDuration zero, ignore ${JSON.stringify(integralDatapoints[kk])}`)
|
|
450
496
|
continue;
|
|
451
497
|
}
|
|
452
|
-
let valStart = parseFloat(
|
|
498
|
+
let valStart = parseFloat(integralDatapoints[kk].val) || 0;
|
|
453
499
|
// End value is the next value, or if none, assume "linearity
|
|
454
|
-
let valEnd = parseFloat((
|
|
500
|
+
let valEnd = parseFloat((integralDatapoints[kk + 1] ? integralDatapoints[kk + 1].val : (options.integralDatapoints[k + 1] && options.integralDatapoints[k + 1][0] ? options.integralDatapoints[k + 1][0].val : valStart))) || 0;
|
|
455
501
|
if (options.integralInterpolation !== 'linear' || valStart === valEnd) {
|
|
456
502
|
const integralAdd = valStart * valDuration / options.integralUnit;
|
|
457
503
|
// simple rectangle linear interpolation
|
|
458
504
|
log(`${options.logId} Integral: ${k}[${kk}] : Add ${integralAdd} from val=${valStart} for ${valDuration}`);
|
|
459
|
-
|
|
505
|
+
point.val += integralAdd;
|
|
460
506
|
} else if ((valStart >= 0 && valEnd >= 0) || (valStart <= 0 && valEnd <= 0)) {
|
|
461
507
|
// start and end are both positive or both negative, or one is 0
|
|
462
508
|
let multiplier = 1;
|
|
@@ -471,7 +517,7 @@ function finishAggregation(options) {
|
|
|
471
517
|
const trianglePart = (maxVal - minVal) * valDuration * 0.5 / options.integralUnit;
|
|
472
518
|
const integralAdd = (rectPart + trianglePart) * multiplier;
|
|
473
519
|
log(`${options.logId} Integral: ${k}[${kk}] : Add R${rectPart} + T${trianglePart} => ${integralAdd} from val=${valStart} to ${valEnd} for ${valDuration}`);
|
|
474
|
-
|
|
520
|
+
point.val += integralAdd;
|
|
475
521
|
} else {
|
|
476
522
|
// Values are on different sides of 0, so we need to find the 0 crossing
|
|
477
523
|
const zeroCrossing = Math.abs((valStart * valDuration) / (valEnd - valStart));
|
|
@@ -480,60 +526,81 @@ function finishAggregation(options) {
|
|
|
480
526
|
const trianglePart2 = valEnd * (valDuration - zeroCrossing) * 0.5 / options.integralUnit;
|
|
481
527
|
const integralAdd = trianglePart1 + trianglePart2;
|
|
482
528
|
log(`${options.logId} Integral: ${k}[${kk}] : Add T${trianglePart1} + T${trianglePart2} => ${integralAdd} from val=${valStart} to ${valEnd} for ${valDuration} (zero crossing ${zeroCrossing})`);
|
|
483
|
-
|
|
529
|
+
point.val += integralAdd;
|
|
484
530
|
}
|
|
485
531
|
}
|
|
486
|
-
options.result[k] = {
|
|
487
|
-
ts:
|
|
532
|
+
/*options.result[k] = {
|
|
533
|
+
ts: options.result[k].val.ts,
|
|
488
534
|
val: options.result[k].val.val
|
|
535
|
+
}*/
|
|
536
|
+
if (point.val !== null) {
|
|
537
|
+
finalResult.push(point);
|
|
538
|
+
} else {
|
|
539
|
+
if (k === 0) {
|
|
540
|
+
preBorderValueRemoved = true;
|
|
541
|
+
} else if (k === originalResultLength - 1) {
|
|
542
|
+
postBorderValueRemoved = true;
|
|
543
|
+
}
|
|
489
544
|
}
|
|
490
545
|
}
|
|
491
546
|
if (options.removeBorderValues) { // we cut out the additional results
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
// no one value in this interval
|
|
498
|
-
options.result.splice(j, 1);
|
|
547
|
+
if (!preBorderValueRemoved) {
|
|
548
|
+
finalResult.splice(0, 1);
|
|
549
|
+
}
|
|
550
|
+
if (!postBorderValueRemoved) {
|
|
551
|
+
finalResult.length--;
|
|
499
552
|
}
|
|
500
553
|
}
|
|
554
|
+
options.result = finalResult;
|
|
501
555
|
} else if (options.aggregate === 'percentile' || options.aggregate === 'quantile') {
|
|
556
|
+
let startIndex = 0;
|
|
557
|
+
let endIndex = options.result.length;
|
|
558
|
+
const finalResult = [];
|
|
502
559
|
if (options.removeBorderValues) { // we cut out the additional results
|
|
503
|
-
options.result.splice(0, 1);
|
|
560
|
+
/*options.result.splice(0, 1);
|
|
504
561
|
options.quantileDatapoints.splice(0, 1);
|
|
505
|
-
options.result.
|
|
506
|
-
options.quantileDatapoints.
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
562
|
+
options.result.length--
|
|
563
|
+
options.quantileDatapoints.length--;*/
|
|
564
|
+
startIndex++;
|
|
565
|
+
endIndex--;
|
|
566
|
+
}
|
|
567
|
+
for (let k = startIndex; k < endIndex; k++) {
|
|
568
|
+
if (options.result[k] !== undefined && options.result[k].val.ts) {
|
|
569
|
+
const point = {
|
|
511
570
|
ts: options.result[k].val.ts,
|
|
512
571
|
val: quantile(options.quantile, options.quantileDatapoints[k])
|
|
513
572
|
};
|
|
514
|
-
log(`${options.logId} Quantile ${k} ${
|
|
573
|
+
log(`${options.logId} Quantile ${k} ${point.ts}: ${options.quantileDatapoints[k].join(', ')} -> ${point.val}`);
|
|
574
|
+
finalResult.push(point);
|
|
515
575
|
} else {
|
|
516
576
|
// no one value in this interval
|
|
517
|
-
options.result.splice(k, 1);
|
|
518
|
-
options.quantileDatapoints.splice(k, 1);
|
|
577
|
+
//options.result.splice(k, 1);
|
|
578
|
+
//options.quantileDatapoints.splice(k, 1); // not needed to clean up because not used anymore afterwards
|
|
519
579
|
}
|
|
520
580
|
}
|
|
581
|
+
options.result = finalResult;
|
|
521
582
|
} else {
|
|
583
|
+
let startIndex = 0;
|
|
584
|
+
let endIndex = options.result.length;
|
|
585
|
+
const finalResult = [];
|
|
522
586
|
if (options.removeBorderValues) { // we cut out the additional results
|
|
523
|
-
options.result.splice(0, 1);
|
|
524
|
-
options.result.
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
587
|
+
// options.result.splice(0, 1);
|
|
588
|
+
// options.result.length--;
|
|
589
|
+
startIndex++;
|
|
590
|
+
endIndex--;
|
|
591
|
+
}
|
|
592
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
593
|
+
if (options.result[j] !== undefined && options.result[j].val.ts) {
|
|
594
|
+
finalResult.push({
|
|
529
595
|
ts: options.result[j].val.ts,
|
|
530
596
|
val: options.result[j].val.val
|
|
531
|
-
};
|
|
597
|
+
});
|
|
532
598
|
} else {
|
|
533
599
|
// no one value in this interval
|
|
534
|
-
options.result.splice(j, 1);
|
|
600
|
+
//options.result.splice(j, 1);
|
|
535
601
|
}
|
|
536
602
|
}
|
|
603
|
+
options.result = finalResult;
|
|
537
604
|
}
|
|
538
605
|
|
|
539
606
|
beautify(options);
|
|
@@ -680,7 +747,7 @@ function beautify(options) {
|
|
|
680
747
|
}
|
|
681
748
|
} else if (options.aggregate === 'none') {
|
|
682
749
|
if (options.count && options.result.length > options.count) {
|
|
683
|
-
options.result
|
|
750
|
+
options.result.splice(0, options.result.length - options.count);
|
|
684
751
|
}
|
|
685
752
|
}
|
|
686
753
|
|
|
@@ -725,7 +792,7 @@ function sendResponse(adapter, msg, options, data, startTime) {
|
|
|
725
792
|
beautify(options);
|
|
726
793
|
|
|
727
794
|
if (options.aggregate === 'none' && options.count && options.result.length > options.count) {
|
|
728
|
-
options.result
|
|
795
|
+
options.result.splice(0, options.result.length - options.count);
|
|
729
796
|
}
|
|
730
797
|
aggregateData.result = options.result;
|
|
731
798
|
} else {
|
|
@@ -789,7 +856,7 @@ function sendResponseCounter(adapter, msg, options, data, startTime) {
|
|
|
789
856
|
}
|
|
790
857
|
|
|
791
858
|
if (data[data.length - 2].ts === options.end) {
|
|
792
|
-
data.
|
|
859
|
+
data.length--;
|
|
793
860
|
}
|
|
794
861
|
|
|
795
862
|
const veryLast = data[data.length - 1];
|
|
@@ -798,7 +865,7 @@ function sendResponseCounter(adapter, msg, options, data, startTime) {
|
|
|
798
865
|
// interpolate from end time to last
|
|
799
866
|
if (options.end < veryLast.ts) {
|
|
800
867
|
const val = beforeLast.val + (veryLast.val - beforeLast.val) * ((options.end - beforeLast.ts) / (veryLast.ts - beforeLast.ts));
|
|
801
|
-
data.
|
|
868
|
+
data.length--;
|
|
802
869
|
data.push({ts: options.end, val, i: true});
|
|
803
870
|
}
|
|
804
871
|
|
package/main.js
CHANGED
|
@@ -2213,7 +2213,7 @@ function getCachedData(options, callback) {
|
|
|
2213
2213
|
}
|
|
2214
2214
|
|
|
2215
2215
|
options.length = cache.length;
|
|
2216
|
-
callback(cache, options.returnNewestEntries && options.count && cache.length >= options.count, !!Object.keys(sqlDPs[options.index || options.id].inFlight).length, earliestTs);
|
|
2216
|
+
callback(cache, options.returnNewestEntries && options.count && cache.length >= options.count, !!(sqlDPs[options.index || options.id] && sqlDPs[options.index || options.id].inFlight && Object.keys(sqlDPs[options.index || options.id].inFlight).length), earliestTs);
|
|
2217
2217
|
}
|
|
2218
2218
|
|
|
2219
2219
|
|
|
@@ -2403,7 +2403,7 @@ function getHistory(msg) {
|
|
|
2403
2403
|
}
|
|
2404
2404
|
|
|
2405
2405
|
sqlDPs[options.id] = sqlDPs[options.id] || {};
|
|
2406
|
-
const debugLog = options.debugLog = !!(sqlDPs[options.id] && sqlDPs[options.id][adapter.namespace] && sqlDPs[options.id][adapter.namespace].enableDebugLogs);
|
|
2406
|
+
const debugLog = options.debugLog = !!((sqlDPs[options.id] && sqlDPs[options.id][adapter.namespace] && sqlDPs[options.id][adapter.namespace].enableDebugLogs) || adapter.config.enableDebugLogs);
|
|
2407
2407
|
|
|
2408
2408
|
if (options.ignoreNull === 'true') options.ignoreNull = true; // include nulls and replace them with last value
|
|
2409
2409
|
if (options.ignoreNull === 'false') options.ignoreNull = false; // include nulls
|
|
@@ -2470,7 +2470,7 @@ function getHistory(msg) {
|
|
|
2470
2470
|
if ((isFull && cacheData.length) && (options.aggregate === 'onchange' || options.aggregate === '' || options.aggregate === 'none')) {
|
|
2471
2471
|
cacheData = cacheData.sort(sortByTs);
|
|
2472
2472
|
if (options.count && cacheData.length > options.count && options.aggregate === 'none') {
|
|
2473
|
-
cacheData
|
|
2473
|
+
cacheData.splice(0, cacheData.length - options.count);
|
|
2474
2474
|
debugLog && adapter.log.debug(`${options.logId} cut cacheData to ${options.count} values`);
|
|
2475
2475
|
}
|
|
2476
2476
|
adapter.log.debug(`${options.logId} Send: ${cacheData.length} values in: ${Date.now() - startTime}ms`);
|
|
@@ -2507,7 +2507,7 @@ function getHistory(msg) {
|
|
|
2507
2507
|
}
|
|
2508
2508
|
}
|
|
2509
2509
|
}
|
|
2510
|
-
data
|
|
2510
|
+
data.splice(options.count);
|
|
2511
2511
|
options.debugLog && adapter.log.debug(`${options.logId} pre-cut data to ${options.count} oldest values`);
|
|
2512
2512
|
}
|
|
2513
2513
|
|
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": "2.1.
|
|
4
|
+
"version": "2.1.3",
|
|
5
5
|
"author": "bluefox <dogafox@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"bluefox <dogafox@gmail.com>",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"optionalDependencies": {
|
|
24
24
|
"mysql2": "^2.3.3",
|
|
25
25
|
"pg": "^8.7.3",
|
|
26
|
-
"sqlite3": "^5.0.
|
|
27
|
-
"mssql": "^8.1.
|
|
26
|
+
"sqlite3": "^5.0.8",
|
|
27
|
+
"mssql": "^8.1.2"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"sql-client": "^3.0.0",
|