jurialmunkey / script.skinvariables

A helper script for Kodi skinners to construct multiple variables
GNU General Public License v3.0
37 stars 16 forks source link

DBTYPE details ratings go 15 decimal places #50

Closed MikeSiLVO closed 3 months ago

MikeSiLVO commented 3 months ago

Looking to use this as replacement for Embuary Helper to provide ratings but the numbers are too long and/or not rounded correctly?

screenshot00010

Thanks :)

jurialmunkey commented 3 months ago

Sorry can you explain a bit more what you're doing and how it relates to SV?

jurialmunkey commented 3 months ago

If you're talking about this method https://github.com/jurialmunkey/script.skinvariables/wiki/Skin-Tools-and-Helpers#get-dbtype-details-container

It just requests from json rpc and returns the values. It doesn't do any label formatting - that's how the values are stored in your library database and what it gets back from json rpc.

MikeSiLVO commented 3 months ago

I am trying to use the DBTYPE details in a hidden list with id "9100" plugin://script.skinvariables/?info=get_dbitem_movie_details&dbid=$INFO[ListItem.DBID]&reload=$INFO[ListItem.Title]

Then when calling the ratings I get the above numbers instead of 6.6 i see 6.599999 etc..

$INFO[Container(9100).ListItem.Property(ratings.imdb.rating)]
$INFO[Container(9100).ListItem.Property(ratings.tomatometerallcritics.rating)]
$INFO[Container(9100).ListItem.Property(ratings.tomatometerallaudience.rating)]

Am I misunderstanding how to use the DBTYPE details?

MikeSiLVO commented 3 months ago

Hmm, I just checked my DB and indeed many are formatted strangely but the longest ones only go six decimal places not 15 and many also have the correct rating like 6.5 instead of anything longer.

Almost all my library has been scraped using the movie db python 3 scraper. Any idea whats going on here? Not sure how I can use this as replacement for the ratings outside DialogVideoInfo... 💭

MikeSiLVO commented 3 months ago

I just made an NFO for the movie posted above, refreshed the item, and this is a couple of the ratings from the NFO:

    <rating default="false" max="100" name="tomatometerallaudience">
      <value>66.0</value>
      <votes>4115</votes>
    </rating>
    <rating default="true" max="10" name="imdb">
      <value>6.6</value>
      <votes>133224</votes>
    </rating>

It is still showing the really long number in the INFOlabel...

From my DB: DB_Browser_for_SQLite_tpIDlyfmue

No idea where that 6.59999 is coming from...

jurialmunkey commented 3 months ago

I just checked my DB and indeed many are formatted strangely but the longest ones only go six decimal places not 15 ... Any idea whats going on here?

Float point calculation inaccuracy because floats are approximations not accurate numbers. Only integers provide accurate numbers.

for e.g. 0.1 + 0.1 + 0.1 does not equal 0.3

image

Which is why using floats to store values is a bad idea. Not sure why someone decided on that instead of using an integer percentage. Will need to do some wrangling unfortunately....

jurialmunkey commented 3 months ago

Added _integer _percentage and _rounded affixes for floating point numbers. The _percentage affix assumes a value out of 10 (which seems to be how db stores ratings -- which is probably source of floating point error in the first place as it is dividing by max value to get to a number out of 10).

e.g.

ListItem.Property(ratings.imdb.rating)
8.399999618530273

ListItem.Property(ratings.imdb.rating_integer)
8

ListItem.Property(ratings.imdb.rating_rounded)
8.4

ListItem.Property(ratings.imdb.rating_percentage)
84%
MikeSiLVO commented 3 months ago

Works great, thanks!