![]() |
#1 |
Enthusiast
![]() Posts: 40
Karma: 98
Join Date: Jan 2011
Device: Kindle 3G
|
Sorting fanfiction by like/dislike ratio using custom columns?
Hello! I am using calibre, along with the Fanfiction Downloader plugin, to manage a relatively large library of fanfiction for offline reading. When downloading a story, two of the metadata fields that are used are "likes" and "dislikes"
I was wondering if it was possible to create a custom column that calculates the ratio of likes:dislikes? Or perhaps more simply, just divides the likes by the dislikes? For example: a story with 112 likes and 17 dislikes would fill this custom column with a value of 6.59, while a story with 1157 likes and 22 dislikes would be sorted higher, with a value of 52.59. Is there a way to do simple division of one column over another, and have the result in a separate column? And maybe for stories with no dislikes, instead of dividing by zero (surely a null result), give it a super high number, like 2000? This is the best idea I can come up with for sorting stories by rating, because at the moment, all I can do is sort by the number of likes, and kinda glance at the dislikes to guess the ratio. I'm not very good with math and formulas, so I don't know if it's even possible, but it'd be cool if I could somehow give more weight to stories with a larger number of votes, but a similar like/dislike value. For example, a story with 568 likes and 25 dislikes would somehow get a larger value than a story with 112 likes and 5 dislikes, even though the likes/dislikes ratio is similar. I hope this post is clear enough. Thanks! |
![]() |
![]() |
![]() |
#2 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Use the following custom column, of type "column built from other columns":
Code:
program: # Return value of dislikes, if empty use 0.002 # This causes multiplication by 500 if no dislikes dislikes_val=cmp(field("#dislikes"),1, 0.002, field("#dislikes"), field("#dislikes")); # Main program -- as it is the last function, # it is returned as template value divide(field("#likes"),dislikes_val); This will give you a ratio of likes/dislikes. If there are no dislikes, use likes*500 instead. This avoids giving a value of "Template Error" due to a divide by zero error. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Enthusiast
![]() Posts: 40
Karma: 98
Join Date: Jan 2011
Device: Kindle 3G
|
Yes, thank you! This works wonderfully. Now I don't have to guesstimate ratios, and I can find the really good stuff quickly. Thanks a bunch!
![]() |
![]() |
![]() |
![]() |
#4 |
Enthusiast
![]() Posts: 40
Karma: 98
Join Date: Jan 2011
Device: Kindle 3G
|
Shoot sorry, this is a problem I've been having for a while. Is there a way to get leading zeros for the ratio number? When I sort by likes/dislikes, I get stuff like this.
Also it takes all the numbers that begin with 9, sorts them, then sorts all the 8's, and so on. (8.9 is listed before, or higher than, 78.62.) I don't know how to make it so that calibre sorts them numerically properly. The "sort/search column by: Number" setting doesn't seem to help. Last edited by crackshot91; 11-26-2013 at 03:32 AM. |
![]() |
![]() |
![]() |
#5 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,336
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You can add leading zeros with something like Code:
format_number(divide(field("#likes"),dislikes_val), '{0:06.2f}'); |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Enthusiast
![]() Posts: 40
Karma: 98
Join Date: Jan 2011
Device: Kindle 3G
|
haha, updating seems to have done the trick. I was still running version 1.0! :O
Thanks for your help, guys. |
![]() |
![]() |
![]() |
#7 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Glad to hear it.
It's all chaley, really, he invented this AND gave me my intro to template formatting. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Metadata and custom columns | dbolack | Development | 9 | 03-05-2012 09:07 AM |
sorting by two columns | BeccaPrice | Calibre | 9 | 01-22-2012 05:54 AM |
Custom Columns - How are you using yours? | nynaevelan | Library Management | 19 | 04-18-2011 12:42 AM |
Custom Columns Question | Greg Waddell | Calibre | 5 | 03-31-2011 12:34 AM |
0.7.46 and custom columns | meme | Library Management | 4 | 02-21-2011 04:21 AM |