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-10-2025, 11:44 AM   #1
p@perm0nk
Junior Member
p@perm0nk began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Mar 2025
Device: Kobo Clara BW
Template: Working with if-elif

Hello,

I have a custom column that shows the days spent on reading a book. I am trying to create another column that shows the text value based on the days spent. Here is the code I am using:
Code:
program:
	p = $$#daystaken;
	
	if p < 4  then 'Fast Paced'
	elif ((p >= 4) && (p < 8)) then 'Medium Paced'
	elif p >=8 then 'Slow Paced'
	fi
The problem is that my code doesn't work. For example, days spent = 11 and I am expecting the column to show 'Slow Paced' but it is currently showing 'Fast Paced'. Also, funny thing is that if the days are between 0-9, it works but it doesn't work if days >= 10. Can someone guide me please? )

p@perm0nk is offline   Reply With Quote
Old 03-10-2025, 11:54 AM   #2
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: 11,366
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I think your issue is you forgot the # for the numbers. I made this mistaek too.

If not: What do you get if you remove line 4 (fast paced)? (You need to change the next one to use an 'if.') Does it become the right value, error, or display nothing? I troubleshoot templates this way by go line-by-line. (I think breakpoints are supposed to also do this but I've not figured out how to use them entirely.)

Last edited by ownedbycats; 03-10-2025 at 12:10 PM.
ownedbycats is offline   Reply With Quote
Advert
Old 03-10-2025, 12:00 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: 11,366
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
You can also do this with a switch_if(), I think. I find it a bit easier to use.

Here's a similar example I use:

Code:
program:
cost = $$#purchasecost;

	switch_if(
		cost == 'none', '',
		'kobopoints:' inlist $#admintags, '[Kobo VIP]',
		cost ==# '00.00', '$0.00',
		cost <=# '00.99', '$0.01 - $0.99',
		cost <=# '04.99', '$1.00 - $4.99',
		cost <=# '10.00', '$5.00 - $9.99',
		cost <=# '15.00', '$10.00 - $14.99',
		cost <=# '15.00', '$10.00 - $14.99',
		cost <=# '20.00', '$15.00 - $19.99',
		cost <=# '30.00', '$20.00 - $29.99',
		'$30.00 and up' 
	)
Here, you could remove the p >=8 check by putting it in the last.

Last edited by ownedbycats; 03-10-2025 at 12:06 PM.
ownedbycats is offline   Reply With Quote
Old 03-10-2025, 12:55 PM   #4
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 924
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
Would it be something like that?


Code:
program:
p = $$#daystaken + 0;

if p < 4 then
'Slow pace'
elif p < 8 then
'Fast pace'
else
'Medium pace'
fi

Last edited by dunhill; 03-10-2025 at 01:19 PM.
dunhill is offline   Reply With Quote
Old 03-10-2025, 01: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: 11,366
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by dunhill View Post
Would it be something like that?


Code:
program:
 p = $$#daystaken + 0;

 if p < 4 then
 'Fast Paced'
 elif p < 8 then
 'Medium Paced'
 else
 'Slow Paced'
 fi
it doesn't use numerical comparisons, so I think it's get wrong results.
ownedbycats is offline   Reply With Quote
Advert
Old 03-10-2025, 04:14 PM   #6
p@perm0nk
Junior Member
p@perm0nk began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Mar 2025
Device: Kobo Clara BW
Thanks very much @ownedbycats and @dunhill.

I updated the code based on your ideas. I added # in front of numbers and used only < instead of >. It is working now. Here is the working code:
Code:
program:
	p = $$#daystaken;
	
	if p <=# 4  then 'Fast Paced'
	elif p<=# 8 then 'Medium Paced'
	elif p<=# 15  then 'Slow Paced'
	else 'Unknown'
	fi
p@perm0nk is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Series template not working send to device algernonramone Library Management 4 06-05-2024 03:46 PM
Cailbre copy to device save template not working algernonramone Calibre 3 03-16-2023 05:51 PM
custom template suddenly stoppped working shoelesshunter Library Management 5 08-07-2020 12:28 AM
Send to Device Template not working dkperez Library Management 3 12-01-2016 09:36 PM
[Old Thread] Save Template not working TGinAZ Calibre 7 01-18-2012 02:03 AM


All times are GMT -4. The time now is 04:05 AM.


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