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 10-21-2024, 05:18 PM   #736
1ily
Enthusiast
1ily doesn't litter1ily doesn't litter
 
Posts: 37
Karma: 190
Join Date: Sep 2023
Device: Kobo Libra 2
Quote:
Originally Posted by chaley View Post
You are using the string (lexical) comparison operator (<) instead of the numeric comparison operator (<#).

As said in the template language manual, which is your friend:


BTW: the first_matching_cmp() or the switch_if() functions seem to satisfy your needs and are faster than a series of if statements.

BTW2: it seems you should be using >=# in the second relational clause of the if statements. Otherwise you are skipping exact matches.
Thank you for your help. I added switch_if() statements and updated the relational clauses as recommended. This fixed it, and it works flawlessly!
1ily is offline   Reply With Quote
Old 10-21-2024, 06:13 PM   #737
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,011
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Code:
program:

	readgoal = strcat('readinggoal:', format_date(today(), 'yyyy'));
	challenge =	strcat('rgchallenges:purchases', format_date(today(), 'yyyy'));

	if
		format_date($date, 'yyyy') == format_date(today(), 'yyyy')
		&& readgoal in $#admintags
		&& $#purchasesource
		&& $#cost !='0.00'

	then
		list_union(challenge, $#admintags, ',')
	else
		$#admintags
	fi
Line 7 I'm trying to check whether the book's timestamp/date is set to this year. Is this the best method to do so?
I can't think offhand of a better way without using a python stored template. That said, changing format_date($date, 'yyyy') to format_date_field($date, 'yyyy') will be faster.

EDIT: For consistency with field_list_count() and the new operator field_inlist (addition submitted to Kovid) I submitted a change to rename format_date_field() to field_format_date(). The old name format_date_field() is an alias and will continue to work. My intention is that any new functions and operators that work on fields will be prefixed with 'field_'.

EDIT2: I might reverse the naming convention and put the _field at the end, changing field_list_count() to list_count_field(). The new operator would be inlist_field instead of field_inlist. In this case the format_date_field() wouldn't be renamed. Still thinking ...

Last edited by chaley; 10-21-2024 at 06:51 PM.
chaley is offline   Reply With Quote
Old 10-22-2024, 10:08 AM   #738
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: 9,465
Karma: 64488089
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Regarding format_date_field, something odd happened: I had a book today that matched all the criteria (added today, had the readinggoal tag, had a purchasesource and a non-0 cost).

However, when I used format_date_field() it didn't add the challenge tag. Changing it back to format_date() worked.

I tested with both $date and $$date.
Attached Thumbnails
Click image for larger version

Name:	2024-10-22 11_09_38-Template tester dialog number 1 (multiple template dialogs allowed).png
Views:	26
Size:	57.4 KB
ID:	211582   Click image for larger version

Name:	2024-10-22 11_09_46-Template tester dialog number 1 (multiple template dialogs allowed).png
Views:	22
Size:	56.9 KB
ID:	211583  

Last edited by ownedbycats; 10-22-2024 at 10:11 AM.
ownedbycats is offline   Reply With Quote
Old 10-22-2024, 10:45 AM   #739
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,011
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Regarding format_date_field, something odd happened: I had a book today that matched all the criteria (added today, had the readinggoal tag, had a purchasesource and a non-0 cost).

However, when I used format_date_field() it didn't add the challenge tag. Changing it back to format_date() worked.

I tested with both $date and $$date.
format_date_field() takes the name of the field, not the value. So use format_date_field('date').

EDIT: until today's change is incorporated you must use format_date_field('timestamp') instead of 'date'.

Last edited by chaley; 10-22-2024 at 11:49 AM. Reason: Correction
chaley is offline   Reply With Quote
Old 10-22-2024, 12:26 PM   #740
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: 9,465
Karma: 64488089
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
ah, the timestamp/date thing. Why does that column have two separate lookups anyways?

EDIT: Looks like the pull request has already been merged in.

Last edited by ownedbycats; 10-22-2024 at 12:40 PM.
ownedbycats is offline   Reply With Quote
Old 10-22-2024, 12:51 PM   #741
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,011
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
ah, the timestamp/date thing. Why does that column have two separate lookups anyways?

EDIT: Looks like the pull request has already been merged in.
Yes it has. One consequence: field_list_count() is now list_count_field(). You must change to the new name wherever you used the old one.

Last edited by chaley; 10-22-2024 at 01:19 PM. Reason: Spelling
chaley is offline   Reply With Quote
Old 10-22-2024, 12:52 PM   #742
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: 9,465
Karma: 64488089
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Yeah, I noticed my columns errored when I updated from source. Got it fixed.
ownedbycats is offline   Reply With Quote
Old 10-25-2024, 02:01 PM   #743
Wiggo
Leftutti
Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.
 
Wiggo's Avatar
 
Posts: 486
Karma: 1153449
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
list_count_field

I have a column #series authors (thx chaley)

Spoiler:
Code:
python:
def evaluate(book, context):
    if book.series is None:
        return ''
    db = context.db.new_api
    ans = set()
    # Get the list of books in the series
    ids = db.search(f'series:"={book.series}"', '')
    if ids:
        # Get all the author_sort values for the books in the series
        author_sorts = (v for v in db.all_field_for('author_sort', ids).values())
        # Add the names to the result set, removing duplicates
        for aus in author_sorts:
            ans.update(v.strip() for v in aus.split('&'))
    # Make a sorted comma-separated string from the result set
    return ', '.join(v.replace(',', ';') for v in sorted(ans))


And I have a column symbol for more than one series author
Code:
program:
	if list_count($#series_authors, ',') > 1 then
		'series_authors.png'
	fi
I wanted to replace list_count by list_count_field but I get an error
Code:
program:
	if list_count_field('#series_authors') > 1 then
		'series_authors.png'
	fi
Click image for larger version

Name:	calibre_qcZIUEVOZW.jpg
Views:	17
Size:	121.6 KB
ID:	211650

I installed Calibre 7.20.100 but as always, I have no idea.
Wiggo is offline   Reply With Quote
Old 10-25-2024, 02:10 PM   #744
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,011
Karma: 7257321
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Wiggo View Post
I have a column #series authors (thx chaley)

Spoiler:
Code:
python:
def evaluate(book, context):
    if book.series is None:
        return ''
    db = context.db.new_api
    ans = set()
    # Get the list of books in the series
    ids = db.search(f'series:"={book.series}"', '')
    if ids:
        # Get all the author_sort values for the books in the series
        author_sorts = (v for v in db.all_field_for('author_sort', ids).values())
        # Add the names to the result set, removing duplicates
        for aus in author_sorts:
            ans.update(v.strip() for v in aus.split('&'))
    # Make a sorted comma-separated string from the result set
    return ', '.join(v.replace(',', ';') for v in sorted(ans))


And I have a column symbol for more than one series author
Code:
program:
	if list_count($#series_authors, ',') > 1 then
		'series_authors.png'
	fi
I wanted to replace list_count by list_count_field but I get an error
Code:
program:
	if list_count_field('#series_authors') > 1 then
		'series_authors.png'
	fi
Attachment 211650

I installed Calibre 7.20.100 but as always, I have no idea.
Composite columns are strings, not multi-valued lists. list_count_field() would be slower than list_count(), so the it doesn't try. Doing further error checking would slow it down even more.
chaley is offline   Reply With Quote
Old 10-25-2024, 02:29 PM   #745
Wiggo
Leftutti
Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.Wiggo ought to be getting tired of karma fortunes by now.
 
Wiggo's Avatar
 
Posts: 486
Karma: 1153449
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
Learning never stops - thank you!
Wiggo 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 168 10-26-2024 12:12 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 12:20 PM.


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