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 07-07-2021, 04:01 AM   #136
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,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
It worked
ownedbycats is offline   Reply With Quote
Old 07-07-2021, 04:27 AM   #137
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,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by ownedbycats View Post
Also, are there any other improvements that can be made to this? I notice there's a slight delay whenever the column updates. I've thought of taking out the #currentlyreading check and instead just having it run its checks directly, but I'm not sure if that would help or if there's a better way.
An update on this: #currentlyreading was originally a bit sloppy coded. (I'd actually improved it a while ago but forgot to actually copy the new template in, oops) I just updated it and it seems to have helped with the other column too.

Last edited by ownedbycats; 07-07-2021 at 04:36 AM.
ownedbycats is offline   Reply With Quote
Advert
Old 07-07-2021, 06:14 AM   #138
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I might've asked this before, but does it do all the checks, or only continue the check when it passes the other ones?
Logical conditional expressions do "shortcutting", which means that they stop as soon as they know the answer. In practice, for "a && b" it will stop if a is false, returning ''. For "a || b" it will stop if a is true, returning '1'.
Quote:
If the latter, since #currentlyreading is another composite (psuedobool, it returns 'true' if it passes certain checks), would putting it last be better practice for performance?
Probably. It depends on the complexity of the other parts of the &&. In this template, almost certainly.

In general, for a sequence of && clauses put them in the order you expect them to most often fail. For a sequence of || clauses put them in the order you expect them to most often succeed.
Quote:
Also, are there any other improvements that can be made to this?
Given that the variable 'a' is used in only one place, it is best to remove the assignment and change the line
Code:
strcat(format_number(subtract(a, 1), '{0:,d}'), '/',ccount)
to be
Code:
strcat(format_number(re(input, '.*\/file(\d+).*', '\1') - 1, '{0:,d}'), '/',ccount)
The expression "a - 1" is faster than the expression "subtract(a, 1)" because it avoids the function call.

Last edited by chaley; 07-07-2021 at 12:35 PM. Reason: Fix shortcutting
chaley is offline   Reply With Quote
Old 07-07-2021, 03:58 PM   #139
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,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That worked. I swapped the order of the bookmark check and the status check. Also I didn't realize it was possible to avoid calling subtract.
ownedbycats is offline   Reply With Quote
Old 07-09-2021, 05:21 PM   #140
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,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
For columns specifically, does commented out template code have any affect on performance? e.g. before the virtual_libraries() thing got fixed, would commenting it out just have it skip entirely or calculate the result and then toss it out?

Last edited by ownedbycats; 07-09-2021 at 05:27 PM.
ownedbycats is offline   Reply With Quote
Advert
Old 07-09-2021, 05:24 PM   #141
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
For columns specifically, does commented out template code have any affect on performance?
No, it doesn't.
chaley is offline   Reply With Quote
Old 07-17-2021, 05:31 PM   #142
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,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question:

I have this template in an Action Chains single-field edit for semi-automated updating of my Kobo collection/shelf column:

Code:
program:
	g = field('#genres');
	k = field('#kobocoll');
	vl = field('#vls');

	v = first_non_empty(
		list_contains(vl, ',', '^Loans$', 'Loans', ''),
		list_contains(g, ',', '^Fanfiction$', 'Fanfiction', ''),
		list_contains(g, ',', '^Horses$', 'Horses', ''),
		list_contains(g, ',', '^Cozy Mystery$', 'Cozy Mysteries', ''),
		list_contains(g, ',', '^(Fantasy|Science Fiction)$', 'Fantasy & Sci-Fi', ''),
	);

	list_union(k, v, ',')
Performance isn't an issue, it's only run on demand. But since the "Loans" virtual library only criteria is that the book has an .OVERDRIVE format, would it be better practice to check for that rather than the VL?
ownedbycats is offline   Reply With Quote
Old 07-17-2021, 05:42 PM   #143
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question:
...
Performance isn't an issue, it's only run on demand. But since the "Loans" virtual library only criteria is that the book has an .OVERDRIVE format, would it be better practice to check for that rather than the VL?
It depends on how you check for the format. If you use approximate_formats() then doing
Code:
'OVERDRIVE' inlist approximate_formats()
will be slightly faster unless you are reasonably sure the #vls column is already evaluated (e.g., it is displayed in a column). In any event the difference will be minor.

If you use any of the formats_???() functions then the time needed to touch the disk to check the physical files will swamp any template processing time.
chaley is offline   Reply With Quote
Old 08-23-2021, 04:45 AM   #144
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,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question: for my composite chapter count column:

Click image for larger version

Name:	2021-08-23 05_41_51-calibre — __ My Books __ Fanfiction __.png
Views:	2547
Size:	1.5 KB
ID:	188857

Is it possible, with a template, to display icon only if the first number is one less than the second?

1/2 - icon.png
2/2 - no icon
99/100 - icon.png
50/100 - no icon
50 - no icon

If it helps, here's the composite. It pulls the numbers from #chaptercount and #kobobookmark:

Code:
program:

input = $#kobobookmark;
status = $#fanficstatus;
ccount = $$#chaptercount;

	if 
		$#fanficcat
	then
		if		
				substr(input, 0, 10) == 'OEBPS/file'
			&& 	
				!status inlist 'Anthology,Oneshot'

		then		
			strcat(format_number(re(input, '.*\/file(\d+).*', '\1') - 1, '{0:,d}'), '/',ccount)
		else
			ccount
		fi

	elif
		ccount == 'None'
	then
		'Not Set'

	elif
		ccount >#1
	then
		ccount

	fi
Thank you.

Last edited by ownedbycats; 08-23-2021 at 04:49 AM.
ownedbycats is offline   Reply With Quote
Old 08-23-2021, 05:26 AM   #145
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question: for my composite chapter count column:

Attachment 188857

Is it possible, with a template, to display icon only if the first number is one less than the second?

1/2 - icon.png
2/2 - no icon
99/100 - icon.png
50/100 - no icon
50 - no icon

If it helps, here's the composite. It pulls the numbers from #chaptercount and #kobobookmark:
Yes. Use an advanced rule that examines the values and generates an icon if needed. Something like this:
Code:
program:
	t = $#tool;
	if '/' in t then
		f = re(t, '(.*)/.*', '\1');
		s = re(t, '.*/(.*)', '\1');
		if f <# s then
			'icon.png'
		fi
	fi
chaley is offline   Reply With Quote
Old 08-23-2021, 03:55 PM   #146
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,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thank you. That also seems to get the 50/100 example though. I'll see if math functions might help here.
ownedbycats is offline   Reply With Quote
Old 08-23-2021, 04:46 PM   #147
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Thank you. That also seems to get the 50/100 example though. I'll see if math functions might help here.
Sorry, I read "less than" not "one less than". The prototype template would be:
Code:
program:
	t = $#tool;
	if '/' in t then
		f = re(t, '(.*)/.*', '\1');
		s = re(t, '.*/(.*)', '\1');
		if (s - f) ==# 1 then
			'icon.png'
		fi
	fi
chaley is offline   Reply With Quote
Old 08-23-2021, 08:58 PM   #148
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,998
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I actually managed to come up with pretty much the same thing before seeing your post. Thank you.
ownedbycats is offline   Reply With Quote
Old 09-24-2021, 09:54 AM   #149
kevn57
Connoisseur
kevn57 began at the beginning.
 
kevn57's Avatar
 
Posts: 93
Karma: 10
Join Date: Jun 2011
Location: Albany NY
Device: Moonreader+
This is a repost as I posted in the wrong thread

I'm a complete nube in calibre template language.

I'm trying to take the output of the plugin Pagecount which is the number of words in a book and dividing that by 320 which is my words per minute reading rate and output the total number of minutes to read the book into my custom integer col "#minutes"

I don't know how to assign the product of divide(vals, 320); to my custom column #minutes.

program:
col = '#pagecount';
vals = from_selection(col);
'#minutes' = divide(vals, 320);

But I get this result EXCEPTION: Formatter: Expected end of program, found '=' near '#minutes' on line 4
kevn57 is offline   Reply With Quote
Old 09-24-2021, 10:21 AM   #150
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
from_selection() is used in Action Chains Formula action to perform mathematical operations that needs input from more than one book.

Templates for composite columns only work for mathematical operations that pulls the data from one book at at time.

If I understand what you want to do correctly, your template should look like this:

Code:
program:
    $$#pagecount / 320
capink is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Library Management: various questions not worth their own thread ownedbycats Library Management 225 Yesterday 02:07 PM
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates Boilerplate4U Development 13 07-07-2020 02:35 AM
Questions on Kobo [Interfered with another thread topic] spdavies Kobo Reader 8 10-12-2014 11:37 AM
[OLD Thread] Some questions before buying the fire. darthreader13 Kindle Fire 7 05-10-2013 09:19 PM
Thread management questions meme Feedback 6 01-31-2011 05:07 PM


All times are GMT -4. The time now is 09:49 PM.


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