FreeOpcUa / python-opcua

LGPL Pure Python OPC-UA Client and Server
http://freeopcua.github.io/
GNU Lesser General Public License v3.0
1.36k stars 658 forks source link

save_node_value accuracy in sql history #443

Open brubbel opened 7 years ago

brubbel commented 7 years ago

Hi, In save_node_value() (linked here), the value of the data written to SQL is converted to a string as follows: str(datavalue.Value.Value) However, this results in a reduced accuracy for floats (although this value is only for human reading) e.g.

>>> import time
>>> a = time.time()
>>> str(a)
'1493390413.37'

The correct way would be:

>>> repr(a)
'1493390413.372789'

More info:

Python versions prior to 3.2 use 12 digits for the whole number when using str(). http://stackoverflow.com/questions/20586011/python-precision-in-string-formatting-with-float-numbers

zerox1212 commented 7 years ago

You can make a patch if you want, but this field is only for looking at the database from another tool. In fact it is really only there for debugging purposes. UA server will always restore the binary from SQL which does not lose accuracy.

zerox1212 commented 7 years ago

Also if you are working on SQLite history feel free to clean up the code. There is some duplication that could be done better. It would make Scrutinizer happy. :)

brubbel commented 7 years ago

Ok, I'll test it for some period and submit a patch.