| 
			
			 | 
		#571 | 
| 
			
			
			
			 Junior Member 
			
			![]() Posts: 6 
				Karma: 10 
				Join Date: Jan 2021 
				
				
				
				Device: Kobo Clara 
				
				
				 | 
	
	
	
		
		
			
			 
				
				Ranking Position
			 
			
			
			Hello everyone,  
		
	
		
		
		
		
		
		
		
		
		
		
		
			I'm using Calibre Portable to manage my ebooks and I have a column named Ranking with a numeric value for each book. I would like to create a new column called Ranking Position that displays the position of each book based on their value in the Ranking column (book with highest value has position number 1). I'm not very familiar with Calibre's functions, so I was wondering if anyone could help me with the steps to populate this new column automatically. Thank you in advance!  
		Last edited by Levinas2021; 04-13-2023 at 02:54 PM.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#572 | |
| 
			
			
			
			 Bibliophagist 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 48,175 
				Karma: 174315444 
				Join Date: Jul 2010 
				Location: Vancouver 
				
				
				Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
 i.e. [IMG]https://i.imgur.com/gr3wMI2.jpeg[/IMG] instead of [IMG]https://i.imgur.com/gr3wMI2[/IMG]  
		 | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#573 | 
| 
			
			
			
			 Custom User Title 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,359 
				Karma: 79528341 
				Join Date: Oct 2018 
				Location: Canada 
				
				
				Device: Kobo Libra H2O, formerly Aura HD 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Small unrelated question: 
		
	
		
		
		
		
		
		
		
		
		
		
	
	{field:|prefix_text|suffix_text} Seeing as it's used for the separator, it possible to use a pipe as either prefix_ or suffix_? I got an error even when I enclosed it in single or double-quotes.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#574 | |
| 
			
			
			
			 Addict 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 295 
				Karma: 2534928 
				Join Date: Nov 2022 
				Location: Canada 
				
				
				Device: Kobo Aura 2 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
 Code: 
	python:
def evaluate(book, context):
	vals = context.funcs.book_values('#ranking', 'title:true', '&', 0).split('&')
	vals = sorted([float(v) for v in vals], reverse=True)
	return str(1 + vals.index(float(book.get('#ranking'))))
 
		 | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#575 | 
| 
			
			
			
			 Junior Member 
			
			![]() Posts: 6 
				Karma: 10 
				Join Date: Jan 2021 
				
				
				
				Device: Kobo Clara 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Hi everyone, 
		
	
		
		
			I'm having trouble with adding code to the "model" field (column Ranking Position) in my application. I've tried adding the code to the field, but it keeps giving me an error. I'm not sure what I'm doing wrong. I've attached some screenshots to show what I've tried. When I test the function in the "Edit Model" option, it works fine and returns the value "1" (Screenshot 1). However, when I try to use it in the "model" field for the column Ranking Position, it returns an error (Screenshots 2 and 3). Can anyone help me understand what I'm doing wrong and how I can successfully add my code to the "model" field? I would greatly appreciate any guidance or suggestions. Thank you! Screenshot 1 ![]() Screenshots 2 and 3 Last edited by issybird; 04-13-2023 at 08:44 PM.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#576 | |
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				Join Date: Jan 2010 
				Location: Notts, England 
				
				
				Device: Kobo Libra 2 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
 The problem is that those functions can be slow. Since you are writing in Python you would be better served using the calibre database API, which is much faster. Glancing at your template I think you want Code: 
	context.db.new_api.get_custom_book_data('#ranking')
 | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#577 | |
| 
			
			
			
			 Addict 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 295 
				Karma: 2534928 
				Join Date: Nov 2022 
				Location: Canada 
				
				
				Device: Kobo Aura 2 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
  | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#578 | 
| 
			
			
			
			 Custom User Title 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,359 
				Karma: 79528341 
				Join Date: Oct 2018 
				Location: Canada 
				
				
				Device: Kobo Libra H2O, formerly Aura HD 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Since this slightly got buried in the other conversation, any idea? I also tried using escape character on the pipe but that didn't seem to help.
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#579 | |
| 
			
			
			
			 Addict 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 295 
				Karma: 2534928 
				Join Date: Nov 2022 
				Location: Canada 
				
				
				Device: Kobo Aura 2 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
  | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#580 | 
| 
			
			
			
			 Custom User Title 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,359 
				Karma: 79528341 
				Join Date: Oct 2018 
				Location: Canada 
				
				
				Device: Kobo Libra H2O, formerly Aura HD 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Yes, I think thsts probably the only way.
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#581 | ||
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				Join Date: Jan 2010 
				Location: Notts, England 
				
				
				Device: Kobo Libra 2 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
 Quote: 
	
 Example: Code: 
	program: finish_formatting($series_index, '02s', ' |', '| ')  | 
||
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#582 | 
| 
			
			
			
			 Junior Member 
			
			![]() Posts: 6 
				Karma: 10 
				Join Date: Jan 2021 
				
				
				
				Device: Kobo Clara 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			The code would be something like this? 
		
	
		
		
		
		
		
		
		
		
		
		
	
	python: def evaluate(book, context): context.db.new_api.get_custom_book_data('#ranking' ) vals = sorted([float(v) for v in vals], reverse=True) return str(1 + vals.index(float(book.get('#ranking'))))  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#583 | |
| 
			
			
			
			 Custom User Title 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,359 
				Karma: 79528341 
				Join Date: Oct 2018 
				Location: Canada 
				
				
				Device: Kobo Libra H2O, formerly Aura HD 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
   How do I get a stored template into an SFM template, anyways? Example: I had this SFM template for a save path: Code: 
	{#kobopath}/{author_sort:sublist(0,1,&)}/{title} - {authors}
{device_path()} isn't a field, and entering it without the squiggly brackets just adds it literally I looked through the template page but couldn't find this  
		 | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#584 | |
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				Join Date: Jan 2010 
				Location: Notts, England 
				
				
				Device: Kobo Libra 2 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
 Code: 
	{:'device_path()'}
 | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#585 | 
| 
			
			
			
			 Custom User Title 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,359 
				Karma: 79528341 
				Join Date: Oct 2018 
				Location: Canada 
				
				
				Device: Kobo Libra H2O, formerly Aura HD 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Thanks  
		
	
		
		
		
		
		
		
		
		
		
		
	
	![]() I did a ctrl+F for "{:" and found only a brief example buried in the middle of the approximate_formats() entry. No wonder I missed it  
		 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
![]()  | 
            
        
            
            
  | 
    
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Library Management: various questions not worth their own thread | ownedbycats | Library Management | 253 | 10-21-2025 09:15 AM | 
| [Metadata Source Plugin] Questions regarding parse select, docs and ref templates | Boilerplate4U | Development | 13 | 07-07-2020 03:35 AM | 
| Questions on Kobo [Interfered with another thread topic] | spdavies | Kobo Reader | 8 | 10-12-2014 12:37 PM | 
| [OLD Thread] Some questions before buying the fire. | darthreader13 | Amazon Fire | 7 | 05-10-2013 10:19 PM | 
| Thread management questions | meme | Feedback | 6 | 01-31-2011 06:07 PM |