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 01-17-2023, 05:20 PM   #481
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
In this specific case, the switch_if() is in #kobopath, which is called by the save template ({#kobopath:re(_,/)}/{author_sort:sublist(0,1,&)}/{title} - {authors}).

Just to be safe, I set up this template rule, so I tend to know right away that I loaded up the wrong version.

Click image for larger version

Name:	2023-01-17 18_20_22-Create_edit a column icon rule.png
Views:	47
Size:	19.6 KB
ID:	199102
ownedbycats is offline   Reply With Quote
Old 01-21-2023, 08:17 PM   #482
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
New question:

I have a composite colum, #chapters, which formats the chapter count:

Code:
program:
	input = $#kobobookmark;
# Don't change this to 'count' as that's a function
	ccount = $$#chaptercount;

	if 
## Checks that a Fanfiction has a Kobo bookmark of the right format and is not anthology|oneshot
		$#booktype=='Fanfiction'
		&& substr(input, 0, 10) == 'OEBPS/file'
## I'm not sure why this line is backwards
		&& $#fanficstatus in 'Anthology,Oneshot'
	then
## Extracts number from bookmark, subtracts 1, and then formats them as 'currentchap/totalchap'
		strcat(format_number(re(input, '.*\/file(\d+).*', '\1') - 1, '{0:,d}'), '/',ccount)

## Display 'Not Set' if there's no chapter count
	elif
		ccount == 'None'
	then
		'Not Set'

## Display regular chapter count - ignore '1' on most books (magazines, reference books, etc)
	elif
		$#booktype=='Fanfiction'
		||ccount >#1
	then
		ccount
	fi
If the conditionals match, lines the first if-then makes a result that looks like '10/20' or '5/5.' (I use this to track how many chapters I've read in a fanfic. )

I have a stored template, fanfic_unreadchaps(), that checks the composite column and subtracts the first number from the second. 10/20 produces '10' and 5/5 produces '0.'

Code:
program:
	if '/' in $#chapters then
		f = re($#chapters, '(.*)/.*', '\1');
		s = re($#chapters, '.*/(.*)', '\1');
		(s - f)
	fi

This is used in several places; saved searches, column colour/icon rules, action chains templates.

Would performance improve much if I used something like this, that checked the relevant columns directly rather than the composite?

Code:
program:
input = $#kobobookmark;
	if 
		$#booktype == 'Fanfiction'
		&& substr(input, 0, 10) == 'OEBPS/file'
		&& !$#fanficstatus in 'Anthology,Oneshot'
	then
		currentchap = re(input, '.*\/file(\d+).*', '\1') - 1;
		totalchap = $#chaptercount;

		totalchap - currentchap
	fi

Last edited by ownedbycats; 01-21-2023 at 10:03 PM.
ownedbycats is offline   Reply With Quote
Advert
Old 01-21-2023, 09:22 PM   #483
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Additionally, something I forgot: logical-and is '&&.' What is a logical-or?

EDIT: Found it in the reference. ||

ANOTHER EDIT: In the Calibre search, it's possible to do something like this to find matches in both groups:

(title:foo AND author:bar) OR (title:bar AND author:bar)

if possible, how would the same thing be done in a template?

Last edited by ownedbycats; 01-21-2023 at 10:06 PM.
ownedbycats is offline   Reply With Quote
Old 01-22-2023, 05:43 AM   #484
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
[...]
This is used in several places; saved searches, column colour/icon rules, action chains templates.

Would performance improve much if I used something like this, that checked the relevant columns directly rather than the composite?

Code:
program:
input = $#kobobookmark;
	if 
		$#booktype == 'Fanfiction'
		&& substr(input, 0, 10) == 'OEBPS/file'
		&& !$#fanficstatus in 'Anthology,Oneshot'
	then
		currentchap = re(input, '.*\/file(\d+).*', '\1') - 1;
		totalchap = $#chaptercount;

		totalchap - currentchap
	fi
Really hard to say, as it depends on the usage pattern. When doing rules or anything else that nests composite access, the composites are evaluated once per book, then cached. The first use evaluates the composite. Second and later uses see the cached result.

If the composite is used only once then the second approach is faster because the template isn't as complicated. However, the second approach introduces maintenance problems, as you would have two (or more) places that make assumptions about column contents.

Of course, the fastest would be to use a Python template for #chapters. These are as fast as native calibre code.

Note: the composite cache is cleared whenever metadata changes. If you are using these templates in action chains where the chains alter metadata then the cache won't be as effective.
chaley is offline   Reply With Quote
Old 01-22-2023, 05:55 AM   #485
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Additionally, something I forgot: logical-and is '&&.' What is a logical-or?

EDIT: Found it in the reference. ||

ANOTHER EDIT: In the Calibre search, it's possible to do something like this to find matches in both groups:

(title:foo AND author:bar) OR (title:bar AND author:bar)

if possible, how would the same thing be done in a template?
In an "if" in a template? More or less as you wrote it.
Code:
('foo' in $title && 'bar' in $author) || ('bar' in $title && 'bar' in $author)
Note that the expression can be simplified in both cases, removing the duplicate author check.
Code:
('foo' in $title || 'bar' in $title) && 'bar' in $author
Code:
(title:foo OR title:bar) AND author:bar
They both can be further simplified using regular expressions.
Code:
'foo|bar' in $title && 'bar' in $author
Code:
title:~foo|bar AND author:bar
chaley is offline   Reply With Quote
Advert
Old 01-22-2023, 01:42 PM   #486
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That works! I was able to combine two if-thens that returned the same value:

Code:
	if 
		select($identifiers, 'url') 
		&& !'Anthology' in $#fanficstatus
	then
		if 
			$publisher == 'Archive of Our Own'
			&& !select($identifiers, 'ao3')
		then 'metadata.png' 

		elif 
			$publisher == 'FanFiction.net'
			&& !select($identifiers, 'ffnet')
		then 'metadata.png' 
		fi
	fi,

into this:

Code:
	if 
		select($identifiers, 'url') 
		&& !'Anthology' in $#fanficstatus
	then
		if 					
			($publisher == 'Archive of Our Own' 
			&& !select($identifiers, 'ao3'))
			|| 
			($publisher == 'FanFiction.net' 
			&& !select($identifiers, 'ffnet'))
		then 'metadata.png' 
		fi
	fi,
ownedbycats is offline   Reply With Quote
Old 01-22-2023, 03:30 PM   #487
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
That works! I was able to combine two if-thens that returned the same value:

Code:
	if 
		select($identifiers, 'url') 
		&& !'Anthology' in $#fanficstatus
	then
		if 
			$publisher == 'Archive of Our Own'
			&& !select($identifiers, 'ao3')
		then 'metadata.png' 

		elif 
			$publisher == 'FanFiction.net'
			&& !select($identifiers, 'ffnet')
		then 'metadata.png' 
		fi
	fi,

into this:

Code:
	if 
		select($identifiers, 'url') 
		&& !'Anthology' in $#fanficstatus
	then
		if 					
			($publisher == 'Archive of Our Own' 
			&& !select($identifiers, 'ao3'))
			|| 
			($publisher == 'FanFiction.net' 
			&& !select($identifiers, 'ffnet'))
		then 'metadata.png' 
		fi
	fi,
FWIW: if one of the (x && y) expressions occurs significantly more often than the other then it should be the first. The formatter does "shortcutting" where it stops evaluating when the result is known. If the first expression before the || returns true then the second expression isn't evaluated.
chaley is offline   Reply With Quote
Old 01-24-2023, 02:57 AM   #488
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question:

Previously, in the template I have to generate Kobo collections (not composite; Action Chains single-field edit) was something like this:

Code:
if $#booktype == 'Fanfiction' then 'Fanfiction' fi,
if $#booktype == 'Fiction' then 'Fiction' fi,
if $#booktype == 'Nonfiction' then 'Nonfiction' fi,
(#booktype is enumerated)

Obviously, that could be simplified:

Code:
program:
	genre = $#subjects;

	colls = strcat(	
		$#booktype,	
		if 'overdrive' in approximate_formats() then 'Loans,' fi,
		if $$#purchasecost == '0.00' then 'Freebies,' fi,
		if '^Horses$' inlist genre then 'Horses,' fi,
		if '^Cozy Mystery$' inlist genre then 'Cozy Mysteries,' fi,
		if '^(Fantasy|Science Fiction|Paranormal)$' inlist genre then 'Fantasy & Sci-Fi,' fi,
		if 'Omnibus' in $#admintags then 'Omnibuses' fi
);

 new_colls = list_union($#kobocoll, colls, ',')
How do I get #booktype to also return a comma?

Last edited by ownedbycats; 01-24-2023 at 03:01 AM.
ownedbycats is offline   Reply With Quote
Old 01-24-2023, 04:30 AM   #489
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: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question:
[...]
Code:
program:
	genre = $#subjects;

	colls = strcat(	
		$#booktype,	
		if 'overdrive' in approximate_formats() then 'Loans,' fi,
		if $$#purchasecost == '0.00' then 'Freebies,' fi,
		if '^Horses$' inlist genre then 'Horses,' fi,
		if '^Cozy Mystery$' inlist genre then 'Cozy Mysteries,' fi,
		if '^(Fantasy|Science Fiction|Paranormal)$' inlist genre then 'Fantasy & Sci-Fi,' fi,
		if 'Omnibus' in $#admintags then 'Omnibuses' fi
);

 new_colls = list_union($#kobocoll, colls, ',')
How do I get #booktype to also return a comma?
Add the comma to the strcat().
Code:
program:
	genre = $#subjects;

	colls = strcat(	
		$#booktype, ',',
		[...]
Don't worry about the possibility of colls ending in a comma. The list_union() will remove it.
chaley is offline   Reply With Quote
Old 01-24-2023, 05:45 AM   #490
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
#kobocoll is a taglike column so I'd think it'd remove excess commas anyways. Thanks
ownedbycats is offline   Reply With Quote
Old 02-03-2023, 12:43 PM   #491
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
New question:

I created several user-categories to group the entries in taglike #fanficcat. (For several reasons, I prefer to leave the column itself as nonhierarchical entries.)
Click image for larger version

Name:	2023-02-03 13_41_47-Window.png
Views:	78
Size:	10.0 KB
ID:	199438

To find books that have entries not present in the categories, I search for #fanficcat:true AND @Fanfiction.Fandoms:.false. Is it possible to also check this with a template?

EDIT:

Code:
program: 
	if 
		$#fanficcat 
		&& !'Fandom' inlist user_categories() 
	then 
		'aaaa' 
	fi

Last edited by ownedbycats; 02-05-2023 at 09:50 PM.
ownedbycats is offline   Reply With Quote
Old 02-05-2023, 05:00 PM   #492
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
In the book list, there's a stray comma at the beginning of this composite taglike. Where is it coming from?

EDIT: It goes away if I run the strcat through list_remove_duplicates.
Attached Thumbnails
Click image for larger version

Name:	2023-02-05 17_59_54-Window.png
Views:	42
Size:	422.5 KB
ID:	199501  

Last edited by ownedbycats; 02-05-2023 at 05:03 PM.
ownedbycats is offline   Reply With Quote
Old 02-05-2023, 07:13 PM   #493
isarl
Addict
isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.
 
Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
Quote:
Originally Posted by ownedbycats View Post
To find books that have entries not present in the categories, I search for #fanficcat:true AND @Fanfiction.Fandoms:.false. Is it possible to also check this with a template?
I'm not familiar with using @ in a search like that and can't find it in the user manual. How does that work?
isarl is offline   Reply With Quote
Old 02-05-2023, 07:24 PM   #494
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: 8,624
Karma: 61176603
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
You need to set up a user category. In the tag browser click 'configure' and then 'manage authors, tags > user categories.'
ownedbycats is offline   Reply With Quote
Old 02-05-2023, 07:58 PM   #495
isarl
Addict
isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.
 
Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
So it's effectively a prefix for user categories in the same way that # is a prefix for user columns?
isarl 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 138 04-23-2024 11:49 AM
[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 03:14 AM.


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