ebroecker / canmatrix

Converting Can (Controller Area Network) Database Formats .arxml .dbc .dbf .kcd ...
BSD 2-Clause "Simplified" License
933 stars 401 forks source link

Casting the frame id from scientific number format fails #778

Closed djdesant closed 6 months ago

djdesant commented 8 months ago

db.enum_attribs_to_values() File "C:\…\MdfMetaData.venv\Lib\site-packages\canmatrix\canmatrix.py", line 2317, in e num_attribs_to_values frame.attributes[define] = self.frame_defines[define].values[int(frame.attributes[define])] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: '8.52715012702708E-317'

Please consider the casting to float before int. Example: frame.attributes[define] = self.frame_defines[define].values[int(float(frame.attributes[define]))]

pempem98 commented 8 months ago

I guest this is the precision issue of the library decimal I used to get this issue before when I tried to read string '1' and convert it into decimal.Decimal type. The result comes as decimal.Decimal('1.00000000000000000000003216...')

djdesant commented 7 months ago

I guest this is the precision issue of the library decimal I used to get this issue before when I tried to read string '1' and convert it into decimal.Decimal type. The result comes as decimal.Decimal('1.00000000000000000000003216...')

Are there more possible workarounds ? @pempem98 Could you please describe your alternative proposal for solving this problem ?

ebroecker commented 7 months ago

I don't know a better workaround. Also - I was not able to reproduce the error.

pip install git+https://github.com/ebroecker/canmatrix.git@issue_778

djdesant commented 7 months ago

I don't know a better workaround. Also - I was not able to reproduce the error.

pip install git+https://github.com/ebroecker/canmatrix.git@issue_778

Thanks for fixing.

Probably you have a clean database example without scientific numbers. I'll give you short exctract from the dbc in my case:

BA "GenMsgCycleTime" BO 2360127010 100; BA "GenMsgSendType" BO 2360127010 8.48332452797837E-317; BA "VFrameFormat" BO 2360127010 3; BA "VFrameFormat" BO 2566875426 3; BA "GenMsgCycleTime" BO 2360156846 100; BA "GenMsgSendType" BO 2360156846 8.48390950170305E-317; BA "VFrameFormat" BO 2360156846 3;

As you can see the attribute "GenMsgSendType" is marginally small number and could surely be replaced by zero, but this would require manual post-editing in an ASCII text editor after each change of the database in Vector DB Editor.

djdesant commented 7 months ago

@ebroecker, when are you planning to merge the current branch into master ?

ebroecker commented 6 months ago

should be merged, if not please blame me