View Single Post
Old 08-17-2023, 05:38 AM   #7
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,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by imnnrv View Post
Thank you for you help!

It almost works, except it doesn't count some of authors/books: it think there is less than X books of this authors even if there are 10 and more books.
I've tried to rename them, move these books to new library - all the same (so it doesn't depends on library size). Tried to make X=1 and even then there was 1 author (3 books) counted as <1.
Made test with plugin "Author Book Count': it counts right, so i don't think it's problem with tags.

Can you please check the code for mistakes?

program:
first_author = list_item($authors, 0, '&');
books_by_author = book_count('authors:"""=' & first_author & '"""', 0);
X = 2;
if books_by_author < X then
answer = template('Fiction/{languages}/{author_sort} - {pubdate} - {title}')
else
answer = template('Fiction/{languages}/{author_sort:sublist(0,1,&)}/{series}/{series:|| }{series_index:|| - }{pubdate} - {title}')
fi;
answer
I forgot to specify numeric comparison instead of lexical (string) comparison in my original template. In lexical comparison, '10' is less than '2'.

Try this:
Code:
program:
	first_author = list_item($authors, 0, '&');
	books_by_author = book_count('authors:"""=' & first_author & '"""', 0);
	X = 2;
	if books_by_author <# X then
		answer = template('Fiction/{languages}/{author_sort} - {pubdate} - {title}')
	else
		answer = template('Fiction/{languages}/{author_sort:sublist(0,1,&)}/{series}/{series:|| }{series_index:|| - }{pubdate} - {title}')
	fi;
	answer
The change is
Quote:
if books_by_author <# X then
chaley is offline   Reply With Quote