Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 03-16-2022, 11:01 AM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,829
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Custom rating column in the database

In the Calibre database, a custom rating column with half-stars stores its numbers in a strange way. I have books with all 10 ratings, and matching up book ids in the database shows:

1 - unused?
2 - unused?
3 - 3 stars
4 - 4 stars
5 - 2 stars
6 - 1 star
7 - 5 stars
8 - 1.5 stars
9 - 3.5 stars
10 - 2.5 stars
11 - unused?
12 - 0.5 stars
13 - 4.5 stars

Why are 1, 2, and 11 unused?

Last edited by ownedbycats; 03-16-2022 at 11:05 AM.
ownedbycats is offline   Reply With Quote
Old 03-16-2022, 01:45 PM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,376
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Almost certainly you got the wrong column. It is (in theory) impossible to put a value in a Rating column outside the range 0 .. 10. Furthermore, the value 2 will show 1 star and any value over 10 will show 5 stars.

The code that translates the number into stars is
Code:
def rating_to_stars(value, allow_half_stars=False, star='★', half='⯨'):
    r = max(0, min(int(value or 0), 10)) # value is limited to 0 .. 10
    ans = star * (r // 2) # generate (r int_divide by 2) stars.
    if allow_half_stars and r % 2: # if half stars and r mod 2 != 0, add it
        ans += half
    return ans
chaley is offline   Reply With Quote
Advert
Old 03-16-2022, 01:50 PM   #3
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,829
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
that's odd -- looking at custom_columns showed that #ratings had an id of 40, so I was looking at custom_column_40:

Click image for larger version

Name:	2022-03-16 14_49_21-Window.png
Views:	248
Size:	2.6 KB
ID:	192809

And all the book IDs and stuff were in books_custom_column_40_link.
ownedbycats is offline   Reply With Quote
Old 03-16-2022, 01:58 PM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,376
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
that's odd -- looking at custom_columns showed that #ratings had an id of 40, so I was looking at custom_column_40:

Attachment 192809

And all the book IDs and stuff were in books_custom_column_40_link.
I don't know what you are showing me. It looks like rating values containing the correct values.

The values in the _link table are row IDs, not ratings. ID 3 has the value of 6, or 3 stars.
chaley is offline   Reply With Quote
Old 03-16-2022, 02:05 PM   #5
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,829
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
custom_columns:

Click image for larger version

Name:	2022-03-16 15_00_49-Window.png
Views:	219
Size:	10.4 KB
ID:	192810

custom_column_40 is what I showed above

books_custom_column_40_link:

Click image for larger version

Name:	2022-03-16 15_02_04-Window.png
Views:	96
Size:	16.6 KB
ID:	192811

from what it looks like, book 6337 has a value of 3, which is assigned to 6 (which displays as 3 stars).

Not sure why ids 1, 2, and 11 are not present in custom_column_40, or why the values are in a seemingly random order (I can see why the even whole-stars would appear above the odd half-stars, but other than that is confusing).
ownedbycats is offline   Reply With Quote
Advert
Old 03-16-2022, 02:14 PM   #6
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,376
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The _link table is a standard many-to-one SQL link table. It matches book_ids to the data table ID. Nothing in this table should be interpreted as a rating. The data table contains the actual rating value, referenced by the data table ID which in this case is a row number.

The order of rows in a _link table depends on the order that values were created and deleted. For example, it should be that if you remove rating X from all books then all those books will disappear from the _link table and the line containing X will disappear from the data table. If you later add X to some book then a line will appear at the end of the _link table and X will appear at the end of the data table with a new row number.
chaley is offline   Reply With Quote
Old 03-16-2022, 02:31 PM   #7
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,829
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
ah, I think I see what happened -- I think I added half-star (odd) ratings to a few books, but then I copied everything over from the other column (which only has evens) and overwrote them.

Last edited by ownedbycats; 03-16-2022 at 02:35 PM.
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using RE to extract pattern from custom column into another custom column activedirectory Library Management 1 12-15-2019 08:07 PM
Build Custom Stars Rating Column. oren64 Calibre 2 09-18-2016 04:18 AM
Custom column - Rating twstdwspr Library Management 7 09-24-2015 08:14 PM
Decimal "Rating" column (Custom) and Stars Chris_Snow Library Management 6 04-06-2015 12:25 PM
Custom column returns value based on value of another custom column? calvin-c Calibre 3 09-14-2013 02:24 PM


All times are GMT -4. The time now is 09:32 AM.


MobileRead.com is a privately owned, operated and funded community.