canmatrix icon indicating copy to clipboard operation
canmatrix copied to clipboard

Casting the frame id from scientific number format fails

Open djdesant opened this issue 11 months ago • 5 comments

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]))]

djdesant avatar Mar 21 '24 23:03 djdesant

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...')

pempem98 avatar Mar 23 '24 06:03 pempem98

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 ?

djdesant avatar Apr 10 '24 15:04 djdesant

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

ebroecker avatar Apr 11 '24 19:04 ebroecker

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 avatar Apr 12 '24 19:04 djdesant

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

djdesant avatar Apr 21 '24 19:04 djdesant

should be merged, if not please blame me

ebroecker avatar May 23 '24 11:05 ebroecker