View Single Post
Old 12-09-2024, 06:25 AM   #186
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,482
Karma: 8025704
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
In my series:true VL, what would be the lowest-impact way to exclude series with only one book?
This template search should be fast enough to use in a VL. You probably want to make it a stored template.
Code:
python:
def evaluate(book, context):
	# Return True ('yes') if the value in 'field' is used by more than 'test_count' books.
	# This template only works with single value fields such as Series, Publisher, and enumerations
	field = 'series'
	test_count = 1

	db = context.db.new_api
	id_map = context.globals.get('id_map')
	if id_map is None:
		context.globals['id_map'] = id_map = db.get_item_name_map(field)
		context.globals['item_book_count'] = db.get_usage_count_by_id(field)
	item_book_count = context.globals['item_book_count']

	item_id = id_map.get(book.get(field))
	if item_id is None or item_book_count.get(item_id, 0) <= test_count:
		return ''
	return 'yes'
chaley is offline   Reply With Quote