-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New database plugin: misc issues #165
Comments
Point 1: yes that's right and the problem here is that the plugin does not know if the current value of an item is the initial value (set by SH while starting up) or a value from a later update. So the value will always be inserted into the database. Other plugins like the To solve this I suggest to implement one of the following solutions:
I would prefer the first implementation in the item class, because it is more generic and other plugins or logics could benefit from this. See also comments in 56cd106 Point 2: I need to have a closer look at this to find out what is wrong here. Can you provide the database data for this item and the timestamp when the result was queried? Could be that the data is not suitable for such a query. Was it a problem with the |
imho i would also prefer the first implementation. But i would vote for the "None" item value as long as none has been set instead of adding yet another property. |
I guess we can forget the second issue I've been mentioning.. Stupid me :( Only thing I'm wondering.. If I query a timespan where an item was 0 all the time I don't get a "0" as a result but a None. If I want to use the result for a calculation it actually fails. |
OK, thanks for clarifying! Maybe the None value is because the database does not contain a value at all? So no rows returned and None will be returned. But this should be the case for the other plugins too. |
So if I query an item for lets say 60 minutes I do get a correct result. If I query it for the last 10 minutes I might get a None as long as there was no change in the last 10 minutes and the value was 0. Happens mostly with booleans of course, at least with the avg operand. |
Doch noch ein Problem. Frage ich avg eines booleans der letzten 25 Minuten ab, das vor ca. 20 Minuten für 3 Minuten eingeschaltet war, erhalte ich 1.0
Frage ich für die letzten 15 Minuten ab, wo auch wirklich nichts eingeschaltet war, gibt's das theoretisch korrekte "none"
|
This always depends on the data in database. If there are only records matched the time range with value 1 it will always return 1. Listing the database values would help to clarify this. |
Find attached the database entries. The item got activated at 20.23 and turned off at 20.27 In my opinion the avg result for an item that was turned on for 6 minutes in the last hour has to be 0.1 - am i wrong? I get a 0.11 when I query the last 350 minutes. |
It seems that the off at 20:27 is not dumped to the database - at least your SQL file does only contain a value for 19:54 and 20:23, but missing 20:27. I guess the off was the last item change, which will only be dumped to the database on the next item change. The database contains all item values except the last/current one (because it's not clear, how long this item will be on the current value to fill up the duration field in the database). |
What do the other think about this idea setting all items initially to @cstrassburg, do you have any opinion about this? |
The "off" was the last change and is put in the item table. The duration of the last "on" entry is correctly written in the database as 213159ms = 3,5 minutes (20.23-20.27) |
I've tried to run the SQL query from 6 posts above directly in phpmyadmin - the result is correct (0.11)! So there has to be some error with interpreting the result..?
-> 0.11 That was the query from the plugin (exactly the same but wrong result):
-> 1.0 |
The mentioned wrong result is from a query for 09:06:15 (in the morning). The data ZIP contains entries for 19:54 and 20:23, but not the value for around 09:06. So it is not possible to check the query and the result. Executing the logged query later/now may return other results because more data could be logged to the database in the meantime. I bet when the plugin will execute the query again it will also return the "correct" value. But it is impossible to reproduce this since the queries always start from "now" back some time. If you could also provide the data for 09:06 I could check when time columns to find out how the log table looked at this time and manually try to select the data. |
Hmm, I see. Yes, querying sh.steckdosen.eg.bad_heizung.SA.db('avg', '860i', '840i') now also results in 0.11 Attached is the full log table for the specific boolean item |
I guess the problem is that the 0 from the item table gets ignored in the calculation? |
Ich habe mal die letzten 2 Probleme oben in die Liste eingefügt, hoffe, es ist alles halbwegs verständlich. |
Danke dafuer, aber ich denke diese Probleme lassen sich nicht alle loesen: Punkt 1: das hatte ich schonmal versucht zu loesen und einfach den letzten Wert vor Statzeitpunkt mit zu selektieren. Das hat aber Probleme mit den Charts, die sich per Interval aktualisieren, gemacht (u.a. Zickzacklinien). Ausserden ist es schwierig (vielleicht auch nicht korrekt moeglich) den Wert vor Startzeitpunkt mit in die Selektion auchzunehmen, da man eigentlich nicht weiss, wie man diesen Wert gewichtet in der Selektion beruecksichtigen sollte. Punkt 2: den aktuellen Wert zu beruecksichtigen ist etwas schwierig, da man den aus der item-Tabelle holen muesste aber noch nicht klar ist fuer welche Dauer das gesetzt bleibt. Man koennte auf "bis jetzt" ausweichen. Alternativ einen Log-Eintrag bei Aenderung in die log-Tabelle schreiben - aber dann mit welcher Duration? So richtig faellt mir da keine schoene Loesung fuer ein... - du mit deinen bool-Items in den Charts; wer macht sowas schon 😉 Dass das vorher bei dir kein Problem war. Muesste mit sqlite aehnlich gewesen sein. Punkt 3: es werden Aenderungen in die Datenbank geschrieben. Wenn das Item initial auf 0 steht und bleibt, wird auch kein Eintrag geschrieben. Nur dann, wenn es sich aendert. Das ist deswegen so, weil man nicht wiess, ob das der initiale Wert ist oder ein gesetzter Wert. Man koennte hier die Idee mit den @psilo909 schaue ich mir an, danke fuer's Feedback! Soeben getan, bitte nochmal pruefen. |
Heho, Danke für die Antworten.. Das Problem mit den Charts, die mitten drin anfangen, hab ich auch bei beliebigen Items, mit normalen Einträgen in mysql. Läuft ja alles irgendwie darauf hinaus, dass entweder der erste oder letzte Wert nicht in der abgefragten Zeitspanne drin sind und daher die Queries nicht passen. Vermutlich stelle ich mir das zu simpel vor, aber im Prinzip müsste doch Folgendes klappen: Der Wert 1 wird mit seiner Duration von 6 Minuten "normal" in die Abfrage genommen. Selbes gilt für alle anderen Werte innerhalb der Zeitspanne außer dem "Ersten" und "Letzten", die u.U. nicht in der abgefragten Zeit liegen. Wie das Beispiel von psilo zeigt, besteht das Problem übrigens nicht nur bei boolschen Werten, sondern bei ALLEN Items, bei denen die Werte über einen längeren Zeitpunkt konstant bleiben. Also Sollwerte, Lüfterstufen, Lichthelligkeiten, etc. Und ja, die Probleme waren mit sqlite sicher auch da.. ;) |
ich habe seit neustem eine: 2016-12-12 18:05:16 ERROR Main Can not execute query: SELECT MIN(time), MAX(val_num) FROM log WHERE item_id = %s AND time > (SELECT COALESCE(MAX(time), 0) FROM log WHERE item_id = %s AND time < %s) AND time <= %s AND time + duration > (SELECT COALESCE(MAX(time), 0) FROM log WHERE item_id = %s AND time < %s) GROUP BY ROUND(time / %s) None (args [91, 91, 1481475916635, 1481562316636, 91, 1481475916635, 864000]): (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'None' at line 1") tritt bei meinem plot.period beim heizungsraum auf, bspw muss am max liegen, der avg chart geht |
Ja, der Fehler sollte bei min/max/on sein, da dort kein order-by in der Abfrage verwendet wird. Das habe ich mit dem letzten Commit in https://github.com/smarthomeNG/plugins/blob/ea1b82199c5579bf1f4073ce2097bf648790ad9e/database/__init__.py#L320 eigentlich korrigiert. Ist das auch dein Stand? |
@ohinckel ne, alles gut jetzt! hatte noch nicht gepulled seitdem die aufräumaktion hier läuft. habe sorge, dass es mir alles zerschiesst und wegen kindergeburtstagen, defekten sektoren auf meinen NAS platten und zahnarztterminen seitdem keine muße gehabt. sorry for that |
Kann ich noch irgendwas Brauchbares beitragen @ohinckel ? Ist die Problematik nachvollziehbar oder hab das Prob nur ich..? |
gibts was neues zu den "fehlenden" werten? die lücken hatte ich auf sqlite def. nicht |
@onkelandy nein, soweit schon alles klar. Kann aber nicht so einfach umgesetzt werden, da es sich nicht mit der Query erschlagen laesst, sondern manuell hinterher gerechnet werden muss. Ob es dafuer eine saubere Loesung gibt, weiss ich nicht. Meine vorherige Idee einfach den letzten bzw. den ersten Wert mit zu selektieren hatte zu den zickzack Linenen gefuehrt - allerdings nur bei Chart-Updates. Vielleicht sollte man in diesen Faellen die Abfrage dann ohne ersten/letzten Wert machen, sonst immer mit. @psilo909 nein, bisher nicht. Ich weiss auch nicht welche Abfragen im rtr angezeigt werden und ob das ein Problem bei der Abfrage oder den Werten ist. Habe es mir bisher noch nicht genauer angeschaut. |
@ohinckel Könntest vielleicht mal den "alten" Abfragecode hier posten oder einsetzen.. vielleicht könnte man ja übergangsweise mal ne Option im Plugin einbauen, dass man selbst einstellt, ob die Berechnung korrekt sein soll oder die Live-Update-Anzeige. Wäre auf jeden Fall ein paar Tests wert. Ein gutes Neues! |
Das Locking ist nun entsprechend erweitert. Aktuell ist es nun in allen Methoden drin, die kein explizites Locking selbst machen (in dem z.B. ein bereits erstellter Cursor uebergeben wird). Auch die |
Cool, ich habs mal upgedatet.. momentan scheint alles recht gut zu funktionieren. Davor hat er definitiv nichts in die Datenbank geschrieben, jedenfalls wird im Graph nix angezeigt. Ich meld mich wenn es News gibt |
Bin nun auch wieder am Testen.. Musste leider die gesamte Bestands-DB droppen. Kriege mit der Version aus @ohinckel 's branch jetzt sowas hier: 2017-05-22 18:40:12 ERROR Main Item knx_global.weather.wind: problem running <bound method Database.update_item of <plugins.database.Database object at 0x7fa903e4dcf8>>: 'int' object has no attribute 'timetuple' |
@psilo909, super, danke dir fuer den Hinweis. Der Fehler hat sich mit dem letzten Umbau eingeschlichen und ist jetzt gefixt. Dafuer gibt es jetzt auch einen Test, damit das nicht nochmal kaputt geht ;-) |
@ohinckel kann bestätigen, dass es jetzt weg ist :) dann beobachte ich mal.. seit gestern hat mich leider eine meiner fritzbox logiken zugespammt, jetzt sieht das log wieder "beobachtbar" leer aus. |
Bisher fehlerfrei, great work!!! Sollen wir nochmal alle gemeinsam überlegen, wie man das Ganze jetzt doch etwas mehr vom Kern entkoppeln könnte? @cstrassburg war damit ja auch nicht wirklich glücklich |
Habe soweit auch keine Fehlermeldungen mehr, sieht gut aus, Verbindung läuft stabil. @psilo909 hast du sqlite auch mal probiert? Ich denke, das Wichtigste wäre mal die config-Zeile aus smarthome.conf raus zu bringen ;) |
@onkelandy nein, ich bin nicht sicher, wie sich das mit der visu verhält, wenn ich beide gleichzeitig an habe?! multiinstance sollte man aber so oder so mal testen |
hmm gerade hatte ich reichlich strange charts auf der übersichtseite (threads etc.).. leider keinen screenshot gemacht, nach f5 drücken wars weg.. ich beobachte.. scheint speziell da zu sein, wo es relativ schnell tickt.. |
Das Ausgliedern kann man in einem neuen Issue diskutieren. Ich finde aber, dass Datenbankunterstuetzung zum Core gehoeren sollte, weil dadurch es auch a) anderen Plugins ermoeglicht wird Datenbanken generell zu unterstuetzen/verwenden, b) es in Logiken eingebunden werden kann, c) alle das gleiche Interface verwenden (verringert Komplexitaet durch Vermeidung des Einsatzes verschiedener Frameworks). Die Konfiguration im der sh-Konfig ist global zu sehen und definiert nur die allgemein unterstuetzten Datenbanktreiber (egal ob diese in Plugins, Logiken oder sonstwo verwendet werden). Hat mit der eigentlichen Datenbankverbindung erstmal nichts zu tun. Die referenziert nur auf diese konfigurierten Treiber. Das Ganze koennte man aber evtl. noch herausziehen und in die Plugin-Konfig verschieben. Wir sollten aber versuchen die Der Einsatz beider Plugins (sqlite, database) sollte funktionieren solange man nicht beide Plugins fuer die gleichen Items definiert. |
@ohinckel 2ter issue wäre ok für mich. grundlegend finde ich nur, dass die entscheidung dann alle tragen sollten, also insbes auch @msinn , @bmxp und @cstrassburg. |
gleiches problem übrigens auch bei aktuellen temperaturwerten.. es scheint weiterzuticken aber von dem zeitpunkt an, wo man die visu "offen gelassen" hat. die alten werte scheinen irgendwann einfach zu verschwinden. |
Koennte schon mit dem Plugin zu tun haben, da dort die Kannst du mir evtl. das SmartHome Debug Log geben (fuer Database und Visu Plugin), damit ich mir die Abfragen anschauen kann? Gut waere auch ein entsprechender Auszug der Daten fuer die Items aus der Datenbank. |
es ist jederzeit reproduzierbar.. einfach die jew items im chart so ~30 min im browser offen lassen. müsste bei dir ggf auch passieren |
bei komplett geclearten (aber noch ohne werte vorhandenen) tabellen kommt auch noch der hier: 2017-05-29 16:20:32 ERROR Main Can not execute query: SELECT MAX(version) FROM database_version; (args []): (1146, "Table 'smarthome.database_version' doesn't exist") In dem Fall aus meiner Sicht kein Error. Oder funzt das nur, wenn es auch die Tabellen noch nicht gibt? |
schon versucht mein thema nachzustellen? wenn ich doch mit debug mitloggen soll, bitte nur eine kurze info... |
Kein Fehler, sondern nur der Versuch herauszufinden ob es die Versionstabelle schon gibt oder nicht. Ein SELECT ist verbreiteter im SQL-Standard als ein "CREATE TABLE IF NOT EXISTS". Daher die Abfrage die beim der ersten Nutzung des Plugins fehlschlaegt.
Ja, kein Fehler nur unschoen. Ich habe in diesem Fall noch ein INFO-Log eingebaut damit der Benutzer weiss, dass dieser Fehler bei der Erstnutzung ignoriert werden. Zu den Charts: dafuer habe ich noch einen Fix committed. Weiss aber nicht ob der damit etwas zu tun hat. Auf jeden Fall haben sich vorher die Chart-Update-Zyklen immer verkleinert - das ist korrigiert, die bleiben nun gleich. |
ich finde für den normalen user irritiert es halt als "ERROR".. der denkt da stimmt was nicht. charts scheinen besser zu sein, muss das morgen aber noch tieferlegen. |
Update: gerade mehrere Stunden die SV offen gelassen - Charts zeigen das Verhalten nicht mehr. Damit haben wir aktuell m.E. keine Bugs mehr. Yippeahh |
Vielleicht koennen wir die drei offene Punkte aus der Beschreibung noch pruefen:
|
zu 2) @ohinckel ich habe für das vorletzte update die gesamte DB resetted. Es ist nicht mehr aufgetreten |
Ich habe die Punkte aus der Beschreibung nun alle erledigt. Das einzige was jetzt noch fehlt ist:
Mein Vorschlag: fuer die einzelnen Sachen nochmal getrennte Issues erstellen, damit diese getrennt voneinander behandelt werden koennen. Um das hier zum Abschluss zu bringen, wuerde ich einen neuen PR fuer meinen Branch einstellen, den wir dann mergen koennen. |
Reported by @onkelandy:
query result is None if last log value was written before the query timeframe:
When querying db('avg','10i','now') and there is no value in the log for that period (just in the item table) the plugin returns a "None"
query result "avg" is wrong as the last entry in item table is ignored:
When a boolean item was on for 6 minutes in a row but off the rest of the time during the last hour the query ('avg', '60i') always returns 1.0 instead of 0.1 because the last value, the "0", is only written in the item table. -> resolved with the latest version
no database entry when value of item is 0:
When configuring an item to use the database (database=yes) the item in MySQL doesn't get created as long as the item stays 0. Only when turning it on, the item gets created. -> is more a core thing: should items initially get a value or
None
(because we do not know the current value until it gets change/set)database query doesn't seem to work correctly:
sh.steckdosen.eg.bad_heizung.SA.db('avg','1m','now') returns a value of 0.02 even though the item was turned on for over a minute constantly.
NOTE: Ouch, did use 5m for 5 minutes not 5i :( Nevertheless there's a problem when getting as zero as result of a query.
Error on item initialization:
2017-05-10 23:21:08 WARNING Database dump nas_nas Database: problem updating WP.Status.Temperatur.Boileroben: Packet sequence number wrong - got 1 expected 12
-> use lock on database access inparse_item
Reported by @psilo909:
TypeError: unorderable types: int() > NoneType()
error is logged. -> never occured with the new versionOther issues:
fix license header - Fix licence header: remove cstrassburg, add ohinckel #178
create a dump method to dump the whole database (maybe a timerange can be provided to only dump a specific range instead of all since the database could grow a lot over the time)
provide a delete item method for item removal: this method can be used to completely remove a given item from
item
andlog
table (if data exists).create a cleanup job: remove all item which are currently not used anymore to keep the database clean (beware of using this in a multi-instance setup since one instance doesn't know items from another one and will remove them).
lock database while dump running: to avoid errors while dump is running when other quieries were issues to the database the database should create some (short) locks for the dump queries.
add date-time columns: for the microseconds columns
time
andchanged
should also be a date-time column (time_date
,changed_date
) containing a formatted date string (YYYY-mm-dd hh:ii:ss
) - could also contain microsecond part.move the database config line from smarthome.conf to the plugins.conf -> can't be moved, since this is DB-API support is core functionality (could be used by other plugins or logics too and is not restricted to be used by the database plugin). -> will be discussed in New database plugin: final architecture #208
sleep short of time between reconnect try in
lib/db.py
/Database.verify()
- done 1b3ab8fThe text was updated successfully, but these errors were encountered: