Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 10-18-2024, 03:31 PM   #136
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,302
Karma: 7955525
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
18 Oct 2024 (in calibre 7.21)

New template function
  • list_count_field()
    Code:
    list_count_field(lookup_name)
    returns the count of items in the field with the lookup name lookup_name. The field must be multi-valued such as authors or tags, otherwise the function raises an error. This function is much faster than list_count() because it operates directly on calibre data without converting it to a string first. Example: list_count_field('tags')

Last edited by chaley; 11-21-2024 at 10:12 AM.
chaley is offline   Reply With Quote
Old 10-18-2024, 03:42 PM   #137
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: 10,505
Karma: 73517101
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
This will be useful!
ownedbycats is offline   Reply With Quote
Advert
Old 10-18-2024, 05:02 PM   #138
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,576
Karma: 7463599
Join Date: Sep 2020
Device: none
Very useful indeed, thank you! As this provides sorting for multi-valued fields, I can see myself doing less searches like authors:#=2, tags:#=3 and so on.

I've just tested it and have already set two columns using:

program: field_list_count('tags')
program: field_list_count('authors');

Is the semicolon needed, BTW? I'm never sure.
Attached Thumbnails
Click image for larger version

Name:	MWSnap 2024-10-18, 17_53_42.png
Views:	289
Size:	23.8 KB
ID:	211484   Click image for larger version

Name:	MWSnap 2024-10-18, 17_53_33.png
Views:	301
Size:	23.0 KB
ID:	211485  
Comfy.n is offline   Reply With Quote
Old 10-18-2024, 05:32 PM   #139
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,302
Karma: 7955525
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Comfy.n View Post
program: field_list_count('tags')
program: field_list_count('authors');

Is the semicolon needed, BTW? I'm never sure.
A semicolon ending the last line of a template is optional.

Truth: according to the syntax it is illegal. Coding the template language parser to optionally accept it was easier than not, and it doesn't hurt anything.
chaley is offline   Reply With Quote
Old 10-19-2024, 12:10 AM   #140
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: 10,505
Karma: 73517101
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I ran into a slightly strange issue when counting a custom column. Template tester it works right:

Click image for larger version

Name:	2024-10-19 01_06_53-Template tester dialog number 1 (multiple template dialogs allowed).png
Views:	530
Size:	24.1 KB
ID:	211486

But when I try to modify my #timesread composite:

Click image for larger version

Name:	2024-10-19 01_07_11-Edit template (only one template dialog allowed).png
Views:	501
Size:	25.2 KB
ID:	211487

The expected number displays in the book list but not book details.

Spoiler:
Click image for larger version

Name:	2024-10-19 01_12_30-calibre — __ My Books __ Currently Reading __.png
Views:	535
Size:	968.7 KB
ID:	211488


Yes, #datesread is a taglike. I also tried restarting and the error persists.

Last edited by ownedbycats; 10-19-2024 at 12:27 AM.
ownedbycats is offline   Reply With Quote
Advert
Old 10-19-2024, 01:11 AM   #141
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,576
Karma: 7463599
Join Date: Sep 2020
Device: none
I did a test out of curiosity and got the same for a probably identical column, as you have helped me populate it: on template tester it's ok as well as in the book list; on BD, it gives #readdates' is not a field - line number 1

Anyway, in my case the readdates/datesread gets populated only by the Mark as Read chain, which runs on double-click event, and it does increment #timesread already.

Last edited by Comfy.n; 10-19-2024 at 01:56 AM.
Comfy.n is offline   Reply With Quote
Old 10-19-2024, 01:28 AM   #142
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: 10,505
Karma: 73517101
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Yeah, I used to use a manual integer for #timesread too, but then I realized that the list_count composite would work instead.

Since field_list_count() is faster, it'd be ideal if it works for this use-case.

Last edited by ownedbycats; 10-19-2024 at 01:30 AM.
ownedbycats is offline   Reply With Quote
Old 10-19-2024, 01:36 AM   #143
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,576
Karma: 7463599
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by ownedbycats View Post
Since field_list_count() is faster, it'd be ideal if it works for this use-case.
I noticed it sort a tad faster than list_count, initially.

Quote:
Originally Posted by ownedbycats View Post
Yeah, I used to use a manual integer for #timesread too, but then I realized that the list_count composite would work instead.
Oh, I see! I remember now that you've shared the list count template with me and now I can picture another advantage over the integer: it means one less action on my double-click event chain. Will do some tests with the composite instead, thanks.

edit: I just tested list_count instead of integer on 7.20 stable and it meant a visible speed improvement on the double-click chain. Running from source I can use field_list_count but the timings are different from regular use.

Last edited by Comfy.n; 10-19-2024 at 02:14 AM.
Comfy.n is offline   Reply With Quote
Old 10-19-2024, 06:42 AM   #144
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,302
Karma: 7955525
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I ran into a slightly strange issue when counting a custom column. Template tester it works right:

Attachment 211486

But when I try to modify my #timesread composite:

Attachment 211487

The expected number displays in the book list but not book details.



Yes, #datesread is a taglike. I also tried restarting and the error persists.
Fix submitted.

In the meantime simply ignore the error. The error happens because of how the template tester is used in this case (editing a composite). Calling field_list_count() works in a composite. Until the fix is in source there might be a few log messages.
chaley is offline   Reply With Quote
Old 10-19-2024, 10:27 AM   #145
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,302
Karma: 7955525
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I ran into a slightly strange issue when counting a custom column. Template tester it works right:
[...]
The expected number displays in the book list but not book details.
Ignoring the error doesn't fix the book details problem, but the submitted fix does.

Here is a copy of the changed file (calibre/utils/formatter.py) if you want to try it before @kovid accepts the change.
Attached Files
File Type: zip formatter.zip (14.7 KB, 284 views)

Last edited by chaley; 10-19-2024 at 10:29 AM.
chaley is offline   Reply With Quote
Old 10-19-2024, 11:23 AM   #146
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: 10,505
Karma: 73517101
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
thank you!

Looking at the pull request, it was just forgetting to account for custom columns?
ownedbycats is offline   Reply With Quote
Old 10-19-2024, 11:51 AM   #147
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,302
Karma: 7955525
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
thank you!

Looking at the pull request, it was just forgetting to account for custom columns?
There are 2 commits. The first changes how field_list_count() checks if a field exists, using a faster more reliable technique. The second, the one you note, fixes the underlying problem that has been there for some 10 years. The second is not required by the first.
chaley is offline   Reply With Quote
Old 10-20-2024, 11:53 AM   #148
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: 10,505
Karma: 73517101
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
The changes are now in Calibre source
ownedbycats is offline   Reply With Quote
Old 10-23-2024, 09:00 AM   #149
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,302
Karma: 7955525
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
23 Oct 2024 (in calibre preview 7.21)

New template binary operator inlist_field
  • inlist_field does the same as inlist except that the right-hand expression must evaluate to a field (column) name. This operator is much faster than inlist because it doesn't convert the field contents to a string. In addition, it works on fields that use a separator other than comma, for example authors. Note that the operator requires the field name not the value, so using $tags will not work. Example:
    Code:
    'foo$' inlist_field 'tags'

Last edited by chaley; 11-21-2024 at 10:12 AM.
chaley is offline   Reply With Quote
Old 10-23-2024, 10:33 AM   #150
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: 10,505
Karma: 73517101
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
so for a custom column, it's just #whatever?

EDIT: I pulled the latest changes but I am not seeing inlist_field.

Last edited by ownedbycats; 10-23-2024 at 10:41 AM.
ownedbycats is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A few questions... (template language, mainly) Clem2605 Library Management 2 12-30-2020 03:25 AM
Template Language phossler Calibre 8 01-12-2016 04:37 PM
Help needed with template language Mamaijee Devices 12 02-19-2013 01:52 AM
Help with template language Pepin33 Calibre 8 11-11-2012 08:32 AM
Template language question BookJunkieLI Library Management 7 02-02-2012 06:55 PM


All times are GMT -4. The time now is 06:48 PM.


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