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-04-2023, 07:47 PM   #451
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,657
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks.

When using first_non_empty, is there any performance difference between checking a default and custom column? Trying to figure out the optimal order for this (e.g. the more complex ones with multiple checks at the end).

Code:
program:
## Missing metadata
first_non_empty(
	if !$formats then 'plus.png' fi,
	if !$tags then 'tags.png' fi,
	if !$languages then 'languages.png' fi,
	if !$#booktype then 'catalog.png' fi,
	if !$#pagecount then 'cover_flow.png' fi,
	if !$#chaptercount && !'paperbook' in approximate_formats() then 'cover_flow.png' fi,
	if $#booktype == 'Documentation & Manuals' && !$#manualtype then 'catalog.png' fi,
	if $#kobostatus && $#kobostatus != 'Kobo Store' && !$#kobopath then 'snippets.png' fi,
)
ownedbycats is offline   Reply With Quote
Old 01-05-2023, 10:40 AM   #452
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Thanks.

When using first_non_empty, is there any performance difference between checking a default and custom column? Trying to figure out the optimal order for this (e.g. the more complex ones with multiple checks at the end).
Fetching a custom column is nanoseconds slower than fetching a standard column. Certainly not enough to worry about.

The first_non_empty() conditions should be ordered by likelihood. Put the ones first that are most likely to match, regardless of complexity.
chaley is offline   Reply With Quote
Advert
Old 01-05-2023, 09:30 PM   #453
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,657
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks. Another question: what is the difference, if any, between using a first_non_empty and an if-then-elif in a situation like this?

first_non_empty is a bit easier for me (less misplaced fi's, for one!) so I'm inclined to keep it unless there's some large advantage to the other.

Code:
program:

	if $#booktype == 'Fanfiction' then
		first_non_empty(
			if 
				$#fanficstatus == 'In-Progress' 
				&& days_between(format_date(today(), 'yyyy-MM-dd'), $#fanficupdated) >= 365 
			then 
				'clock.png' 
			fi,
			
			if 
				!'^cover:' inlist $#admintags 
			then 
				'test' 
			fi
		)
	fi
Code:
program:

	if $#booktype == 'Fanfiction' then
		if 
			$#fanficstatus == 'In-Progress' 
			&& days_between(format_date(today(), 'yyyy-MM-dd'), $#fanficupdated) >= 365 
		then
 			'clock.png'

		elif 
			!'^cover:' inlist $#admintags 
		then
			'test'
		fi
	fi

Last edited by ownedbycats; 01-05-2023 at 11:49 PM.
ownedbycats is offline   Reply With Quote
Old 01-06-2023, 05:26 AM   #454
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Thanks. Another question: what is the difference, if any, between using a first_non_empty and an if-then-elif in a situation like this?

first_non_empty is a bit easier for me (less misplaced fi's, for one!) so I'm inclined to keep it unless there's some large advantage to the other.

Code:
program:

	if $#booktype == 'Fanfiction' then
		first_non_empty(
			if 
				$#fanficstatus == 'In-Progress' 
				&& days_between(format_date(today(), 'yyyy-MM-dd'), $#fanficupdated) >= 365 
			then 
				'clock.png' 
			fi,
			
			if 
				!'^cover:' inlist $#admintags 
			then 
				'test' 
			fi
		)
	fi
Code:
program:

	if $#booktype == 'Fanfiction' then
		if 
			$#fanficstatus == 'In-Progress' 
			&& days_between(format_date(today(), 'yyyy-MM-dd'), $#fanficupdated) >= 365 
		then
 			'clock.png'

		elif 
			!'^cover:' inlist $#admintags 
		then
			'test'
		fi
	fi
The list of ifs is slightly faster (less than microseconds), not enough to worry about.

I have wondered whether I should make a variant that combines first_non_empty() and switch(), perhaps named first_true(). It would take a list of argument pairs where each pair is a condition expression and a value expression. For each pair in order it would evaluate the condition. If True then it would evaluate the value expression and return it, otherwise try the next pair. There would be a 'none are true' value at the end, like switch().

This would be faster than either first_non_empty() or a series of ifs, and would probably be easier to read. But it would be yet another maintenance and documentation chore. It is also quite easy to do in a python template. I am still thinking about it.
chaley is offline   Reply With Quote
Old 01-06-2023, 11:05 AM   #455
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by chaley View Post
I have wondered whether I should make a variant that combines first_non_empty() and switch(), perhaps named first_true(). It would take a list of argument pairs where each pair is a condition expression and a value expression. For each pair in order it would evaluate the condition. If True then it would evaluate the value expression and return it, otherwise try the next pair. There would be a 'none are true' value at the end, like switch().

This would be faster than either first_non_empty() or a series of ifs, and would probably be easier to read. But it would be yet another maintenance and documentation chore. It is also quite easy to do in a python template. I am still thinking about it.
I added the function switch_if(). It is in source now.
chaley is offline   Reply With Quote
Advert
Old 01-06-2023, 04:57 PM   #456
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,657
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I'll give it a test in a few days

Two questions here. #purchasecost is a floating-point with format of $x.xx.

Code:
program:

		if $$#purchasecost ==# '0.00' then '0.00' 
		elif $$#purchasecost <=# '0.99' then '$0.01 - $0.99' 
		elif $$#purchasecost <=# '4.99' then '$1.00 - $4.99' 
		elif $$#purchasecost <=# '10.00' then '$5.00 - $9.99' 		
		elif $$#purchasecost <=# '15.00' then '$10.00 - $14.99' 	
		elif $$#purchasecost <=# '15.00' then '$10.00 - $14.99' 
		elif $$#purchasecost <=# '20.00' then '$15.00 - $19.99' 
		elif $$#purchasecost <=# '30.00' then '$20.00 - $29.99' 
		elif $$#purchasecost >=# '30.00' then '$30.00 and up' 
		fi
a) This'll always try to show the first entry for undefineds. if $$#purchasecost ==# '' then '' best option?

b) More out of curiosity: The first time I made this template, I forgot to add the '#' to all the cmps. Line 11, >= '30.00', showed up on undefineds. This didn't happen for == or <=. How did it get 'undefined is more than 30.00'?

Last edited by ownedbycats; 01-06-2023 at 05:01 PM.
ownedbycats is offline   Reply With Quote
Old 01-06-2023, 05:12 PM   #457
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I'll give it a test in a few days

Two questions here. #purchasecost is a floating-point with format of $x.xx.

Code:
program:

		if $$#purchasecost ==# '0.00' then '0.00' 
		elif $$#purchasecost <=# '0.99' then '$0.01 - $0.99' 
		elif $$#purchasecost <=# '4.99' then '$1.00 - $4.99' 
		elif $$#purchasecost <=# '10.00' then '$5.00 - $9.99' 		
		elif $$#purchasecost <=# '15.00' then '$10.00 - $14.99' 	
		elif $$#purchasecost <=# '15.00' then '$10.00 - $14.99' 
		elif $$#purchasecost <=# '20.00' then '$15.00 - $19.99' 
		elif $$#purchasecost <=# '30.00' then '$20.00 - $29.99' 
		elif $$#purchasecost >=# '30.00' then '$30.00 and up' 
		fi
a) This'll always try to show the first entry for undefineds. if $$#purchasecost ==# '' then '' best option?

b) More out of curiosity: The first time I made this template, I forgot to add the '#' to all the cmps. Line 11, >= '30.00', showed up on undefineds. This didn't happen for == or <=. How did it get 'undefined is more than 30.00'?
You are using raw_field ($$), in which case the format is ignored and an undefined number returns the string "none" instead of the empty string. The string "none" is larger than the string "30.00". If you want to check for undefined values then you should explicitly check for "none".

Alternatively, to control results you could use raw_field() explicitly to set what value you want for undefined. For example, you could say
Code:
    v = raw_field('#purchasecost', -100000.00)
which sets v to -100000.00 if #purchasecost isn't defined. Then use the variable v in the if chain so that undefined numbers are very small and less than zero.

Finally, the last branch of the if shouldn't have a condition but should instead always return '$30.00 and up'. The test serves no purpose.
chaley is offline   Reply With Quote
Old 01-07-2023, 01:42 AM   #458
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,657
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That worked.

Tweaking my #kobopath template:

Code:
program:

	if $#kobostatus then

# Returns 'Fanfiction/Fandom' tag for fanfics
		if $$#booktype == 'Fanfiction' then
			list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction/\1')	
# Returns 'PDF' for PDFs
		elif $formats == 'PDF' then
			'PDF'
# Returns 'Loans' for Loans
		elif 'OVERDRIVE' in $formats then
			'Loans'
# Returns booktype for others
		else
			$#booktype
		fi

	fi
As seen in this screenshot, something that has multiple Fanfiction.Whatever tags lists all three. Oops!

Click image for larger version

Name:	2023-01-07 02_13_29-Edit template.png
Views:	40
Size:	37.8 KB
ID:	198858

Due to my tagging practices:
a) Fanfiction.Crossover is the always the first in the list;
a) I only have multiple tags when one is 'Fanfiction.Crossover'
b) I always prefer 'Crossover' for the first pick.

So based on this, I thought of two separate solutions:

Option #1: splitting the list:

Code:
	if $$#booktype == 'Fanfiction' then
		list_split(list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction/\1'), ',', 'ff');	
		ff_0
Disadvantage: This relies on Fanfiction.Crossover being first on the list. However, I rarely make changes to those subtags.

Option #2 A second check for 'Crossover' specifically. Here, I'm checking the taglike #fanficcat but I could also check Fanfiction.Crossover directly.
Code:
	if $$#booktype == 'Fanfiction' then
			if 'Crossover' in $#fanficcat then 'Fanfiction/Crossover'
			else list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction/\1')
		fi
Disavantage: This relies on 'Crossover' always being in #fanficcat (or Fanfiction.Crossover in tags). This is pretty much always the case.

Another disavantage: This also relies on 'Crossover' not being in #fanficcat (or Fanfiction.Crossover in tags) when unneeded. Thanks to the way FFF works with multi-fandom stories, this has happened.

Based on that second disadvantage, I'm inclined to go with option #1. Does this make sense?


Last edited by ownedbycats; 01-07-2023 at 02:17 AM.
ownedbycats is offline   Reply With Quote
Old 01-07-2023, 05:39 AM   #459
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
That worked.

Tweaking my #kobopath template:

[...]

Based on that second disadvantage, I'm inclined to go with option #1. Does this make sense?

I would avoid complexity and make the checks explicit. The new switch_if() makes it easy and compact to do the checks in order. Something like this:
Code:
program:

# Returns 'Fanfiction/Fandom' tag for fanfics
	booktype = 'Fanfiction';
	tags = 'Fanfiction.Bar, Fanfiction.Crossover, Fanfiction.Foo';
	if booktype == 'Fanfiction' then
		switch_if(
			'^Fanfiction\.Crossover$' inlist tags, 'Fanfiction/Crossover',
# More tests in the order you want
			'^Fanfiction\.Foo$' inlist tags, 'Fanfiction/Foo',
#			...
# If none of the tests find a value then end up picking the first one. 
# If the list is empty then this will return the empty string.
# You only need the list_re() if the list can contain values other than
# Fanfiction.XXX.
			list_item(list_re(tags, ',', '^Fanfiction.(.*)$', 'Fanfiction/\1'), 0, ',')
		)
	fi
chaley is offline   Reply With Quote
Old 01-07-2023, 07:48 PM   #460
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,657
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks.

I converted one of my templates to get a better idea of how the switch_if works. Is this a good place to use one?

Code:
program:
	switch_if(
		'Cleanup' in virtual_libraries(), 'polish.png',
		'Fanfiction' in $#booktype, list_split(icons_fanfic(), ':', 'ff'); 
			ff_0,
		'Documentations & Manuals' in $#booktype, 'helpbook.png',
		'Loans' in virtual_libraries(), 'overdrive.png',
		'Physical Books' in virtual_libraries(), 'paperbook.png',
		approximate_formats()=='PDF', 'pdfbook.png',
		'omnibus' inlist $#admintags, 'bookshelf.png',
		'book_open.png',
	)
original first_non_empty template:
Spoiler:
Code:
program:
	first_non_empty(
		if 'Cleanup' in virtual_libraries() then 'polish.png' fi,
		if 'Fanfiction' in $#booktype then 
			list_split(icons_fanfic(), ':', 'ff'); 
		ff_0 fi,
		if 'Documentations & Manuals' in $#booktype then 'helpbook.png' fi,
		if 'Loans' in virtual_libraries() then 'overdrive.png' fi,
		if 'Physical Books' in virtual_libraries() then 'paperbook.png' fi,
		if approximate_formats()=='PDF' then 'pdfbook.png' fi,
		if 'omnibus' inlist $#admintags then 'bookshelf.png' fi,
		'book_open.png',
	)


(at times like this, sometimes I wish there was some sort of split template editor so I could compare the results of two templates. That's probably not too useful generally though.)

Last edited by ownedbycats; 01-07-2023 at 07:51 PM.
ownedbycats is offline   Reply With Quote
Old 01-08-2023, 03:27 AM   #461
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,657
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Another example:

Code:
program:	
	if
		is_marked()
	then
		m = is_marked();
		switch_if(
			'reading_list_send_to_device' in m, 'sync.png',
			'reading_list_to_be_read' in m, 'list.png',
			'fff' in m, 'download-metadata.png',
			'marked.png'
		)
	fi

Original. (Trying to figure out why I used a 'contains' instead of 'in'.)

Spoiler:
Code:
program:	
	if is_marked() then
		m = is_marked();
		first_non_empty(
			if 'reading_list_send_to_device' in m then 'sync.png' fi,
			if 'reading_list_to_be_read' in m then 'list.png' fi,
			contains(m, "fff", 'download-metadata.png', ''),
			if m then 'marked.png' fi
		)
	fi
ownedbycats is offline   Reply With Quote
Old 01-08-2023, 06:41 AM   #462
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Thanks.

I converted one of my templates to get a better idea of how the switch_if works. Is this a good place to use one?

Code:
program:
	switch_if(
		'Cleanup' in virtual_libraries(), 'polish.png',
		'Fanfiction' in $#booktype, list_split(icons_fanfic(), ':', 'ff'); 
			ff_0,
		'Documentations & Manuals' in $#booktype, 'helpbook.png',
		'Loans' in virtual_libraries(), 'overdrive.png',
		'Physical Books' in virtual_libraries(), 'paperbook.png',
		approximate_formats()=='PDF', 'pdfbook.png',
		'omnibus' inlist $#admintags, 'bookshelf.png',
		'book_open.png',
	)
Yes, this is exactly the situation I envisioned for using switch_if().

Comment: you often use 'in' instead of 'inlist'. Using 'in' can lead to errors because it can find substrings. For example, if you have virtual libraries named "Loans" and "Temp Loans", the "in" will find them both, while inlist will find only the one as long as you use regular expression anchors on the search value.

Quote:
Originally Posted by ownedbycats View Post
Another example:

Code:
program:	
	if
		is_marked()
	then
		m = is_marked();
		switch_if(
			'reading_list_send_to_device' in m, 'sync.png',
			'reading_list_to_be_read' in m, 'list.png',
			'fff' in m, 'download-metadata.png',
			'marked.png'
		)
	fi
IIRC a book can have at most one mark. In this case you should use == instead of 'in', because == is much faster. You could also rewrite the if/then to get rid of it.

Example:
Code:
program:	
	m = is_marked();
	switch_if(
		'reading_list_send_to_device' == m, 'sync.png',
		'reading_list_to_be_read' == m, 'list.png',
		'fff' == m, 'download-metadata.png',
		m, 'marked.png',
		''
	)
chaley is offline   Reply With Quote
Old 01-08-2023, 06:45 AM   #463
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,657
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by chaley View Post
IIRC a book can have at most one mark. In this case you should use == instead of 'in', because == is much faster. You could also rewrite the if/then to get rid of it.

Example:
Code:
program:	
	m = is_marked();
	switch_if(
		'reading_list_send_to_device' == m, 'sync.png',
		'reading_list_to_be_read' == m, 'list.png',
		'fff' == m, 'download-metadata.png',
		m, 'marked.png',
		''
	)
Here's the slight problem with that (applies to all three listed):

Click image for larger version

Name:	2023-01-08 07_44_51-Template tester.png
Views:	63
Size:	26.3 KB
ID:	198891
ownedbycats is offline   Reply With Quote
Old 01-08-2023, 06:46 AM   #464
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Here's the slight problem with that (applies to all three listed):

Attachment 198891
Ooops. I didn't know that the mark had more text. Using 'in' is the right way to go.
chaley is offline   Reply With Quote
Old 01-08-2023, 06:55 AM   #465
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,657
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I do keep forgetting that virtual_libraries is a list though. I can see that especially messing up since I have 'read' and 'unread' vls.

Also, is there a difference between using approximate_formats and $formats for the =='PDF'?
ownedbycats 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 12:56 PM.


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