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 11-26-2013, 02:06 AM   #1
crackshot91
Enthusiast
crackshot91 has learned how to buy an e-book online
 
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!
crackshot91 is offline   Reply With Quote
Old 11-26-2013, 02:51 AM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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);
If you are not using custom columns called "likes" and "dislikes", you just switch out the names. All custom columns when named must start with "#", as I used in the example.

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.
eschwartz is offline   Reply With Quote
Advert
Old 11-26-2013, 03:14 AM   #3
crackshot91
Enthusiast
crackshot91 has learned how to buy an e-book online
 
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!
crackshot91 is offline   Reply With Quote
Old 11-26-2013, 03:25 AM   #4
crackshot91
Enthusiast
crackshot91 has learned how to buy an e-book online
 
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.
crackshot91 is offline   Reply With Quote
Old 11-26-2013, 07:07 AM   #5
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,336
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by crackshot91 View Post
The "sort/search column by: Number" setting doesn't seem to help.
What version of calibre are you running? There was a bug some time back that broke this, but it works for me in calibre 1.12.

You can add leading zeros with something like
Code:
format_number(divide(field("#likes"),dislikes_val), '{0:06.2f}');
You will need to make the "6.2" be something that makes sense for you.
chaley is offline   Reply With Quote
Advert
Old 11-26-2013, 09:28 AM   #6
crackshot91
Enthusiast
crackshot91 has learned how to buy an e-book online
 
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.
crackshot91 is offline   Reply With Quote
Old 11-26-2013, 02:47 PM   #7
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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.
eschwartz is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 02:19 PM.


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