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
Connoisseur
1ily doesn't litter1ily doesn't litter
 
Posts: 63
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,449
Karma: 8012886
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
Advert
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: 11,012
Karma: 75555555
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:	369
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:	388
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,449
Karma: 8012886
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: 11,012
Karma: 75555555
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
Advert
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,449
Karma: 8012886
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: 11,012
Karma: 75555555
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: 549
Karma: 1717097
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:	660
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,449
Karma: 8012886
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: 549
Karma: 1717097
Join Date: Feb 2019
Location: Bavaria
Device: iPad Pro, Kobo Libra 2
Learning never stops - thank you!
Wiggo is offline   Reply With Quote
Old 11-02-2024, 04:06 PM   #746
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,449
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by major4579 View Post
I'm trying to figure out how to jump to the next Marked book in my library (for various reasons). I want to see the UnMarked books surrounding the Marked book.
[...]
Moderator Notice
Please don't double post. Your other post is sufficient. I deleted the post in this thread.
chaley is offline   Reply With Quote
Old 11-03-2024, 12:44 AM   #747
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: 11,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question: I have a stored template, colours_daysbetween(), formatted as colours_daysbetween($#lastread, '#00aaff', '#69cfff', '#9bdeff').

Code:
program:

	arguments(date, colourA, colourB, colourC);
	now = format_date(today(), 'yyyy-MM-dd');

	if days_between(now,date) <#1 then colourA
	elif days_between(now,date) <=# 14 then colourB
	elif days_between(now,date) <=# 30 then colourC 
	fi
I don't remember where I got this (I possibly wrote it myself) but is there any particular reason to use a format_date() instead of just 'today()'? The template works when tested with the latter.
ownedbycats is offline   Reply With Quote
Old 11-03-2024, 05:27 AM   #748
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,449
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question: I have a stored template, colours_daysbetween(), formatted as colours_daysbetween($#lastread, '#00aaff', '#69cfff', '#9bdeff').

Code:
program:

	arguments(date, colourA, colourB, colourC);
	now = format_date(today(), 'yyyy-MM-dd');

	if days_between(now,date) <#1 then colourA
	elif days_between(now,date) <=# 14 then colourB
	elif days_between(now,date) <=# 30 then colourC 
	fi
I don't remember where I got this (I possibly wrote it myself) but is there any particular reason to use a format_date() instead of just 'today()'? The template works when tested with the latter.
Using format_date() ensures that the hours, minutes, and seconds are removed from the date, setting it to midnight. That makes the days_between() calculation more predictable in the face of differing times of day. That might not be important here, in which case using today() directly will be be faster.
chaley is offline   Reply With Quote
Old 11-03-2024, 06:08 PM   #749
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: 11,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Ah yeah, I think that's what I was trying to do.

As long as I use $(field) instead of $$(raw_field) in the date argument, would that make it line up to midnight (assuming a datetime column)?

Last edited by ownedbycats; 11-03-2024 at 07:13 PM.
ownedbycats is offline   Reply With Quote
Old 11-04-2024, 05:40 AM   #750
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,449
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Ah yeah, I think that's what I was trying to do.

As long as I use $(field) instead of $$(raw_field) in the date argument, would that make it line up to midnight (assuming a datetime column)?
Depends on how 'field' is formatted. If it is formatted without time information then yes unless some part of the conversion chain does rounding. You do need to decide what to do with fractional days. Said another way, exactly what is a day? Is it 24 hours or a change of the calendar? Should 00:01 - 23:59 be one day, which is what will happen if comparing calendar days instead of durations.

I also must ask: why is this precision so important? Why not let a day be 24 hours, making everything easier?
chaley 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 218 07-11-2025 07:34 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 05:11 PM.


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