![]() |
#196 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Can a user category be referenced in a template? e.g. if #column is 'foo' and user category is '@bar' then 'foobar'.
If so, would anything break if I then added 'foobar' to that user category? |
![]() |
![]() |
![]() |
#197 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The template function user_categories() returns a list of user categories that the book is in. Using that then this template might return what you might want: Code:
program: if 'foo' == $#column && '^bar$' inlist user_categories() then 'foobar' fi |
|
![]() |
![]() |
Advert | |
|
![]() |
#198 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
New question: Is there a way to test the performance of a template? I suspect one of my composites is causing slowness, but I'm not sure which one it is.
|
![]() |
![]() |
![]() |
#199 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
In my experience performance problems arise if a composite is used for sorting or searching. This requires calibre to evaluate the column for every book in the (virtual) library. In other cases the composite is evaluated when it is to be displayed. Also note that most of the time a GPM template is faster than a TPM or Single Function Mode template. Reason: calibre can cache the "compiled" GPM template. Finally, some functions are just slow, such as any of the format_* functions that must look at the disk to get the answer. |
|
![]() |
![]() |
![]() |
#200 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Wouldn't measuring the time elapsed (in template tester) provide some kind of rough measure, by which you can compare different templates? e.g.
Code:
program: start = format_date(today(), 'to_number'); strcat('a'); format_date(today(), 'to_number') - start Code:
def evaluate(self, formatter, kwargs, mi, locals, template): from calibre.utils.date import now start = now() template_output = formatter.__class__().safe_format(template, mi, 'TEMPLATE_ERROR', mi) diff = now() - start return diff.total_seconds() Code:
program: time_it("program: strcat('a')") Last edited by capink; 12-10-2021 at 06:24 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#201 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Another problem is that the template time depends on the metadata, especially if there are conditionals. For example, the time to split and join tags depends on the number of tags. This argues for some ability to average multiple invocations of the template. Finally, the execution context matters. By this I mean whether the template is being used in search/sort, and for display purposes whether the column value has been cached. In the latter case the formatter doesn't even know it was used. My feeling: if templates are complex enough to need this level of profiling then one should consider implementing them as custom functions. Those are compiled python and run at full python speed. You can also avoid extra split/join operations because you know how you will use the information. |
|
![]() |
![]() |
![]() |
#202 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I think I identified the misbehaving template.
![]() New question (likely more regex issue): When using a 'contains' on a taglike, how can I make it match when there's multiple options? e.g. Code:
program: f = field('#field'); strcat ( contains(f, "^foo|bar|foobar|test123$", 'icon.png:', ''), ) |
![]() |
![]() |
![]() |
#203 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
|
|
![]() |
![]() |
![]() |
#204 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
Code:
program: f = field('#field'); strcat ( contains(f, "^(foo|bar|foobar|test123)$", 'icon.png:', ''), ) |
|
![]() |
![]() |
![]() |
#205 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
This expression checks for the existence of any one of the tags, ignoring whether or not other tags also exist. Code:
program: f = field('#mytextmult'); strcat ( if "^(foo|bar|foobar|test123)$" inlist f then 'icon.png:' fi ) Code:
program: f = field('#mytextmult'); strcat ( list_contains(f, ',', "^(foo|bar|foobar|test123)$", 'icon.png:', '') ) |
|
![]() |
![]() |
![]() |
#206 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
For what it matters, the actual template has quite a few individual entries, e.g.:
Code:
program: f = field('#fanficcat'); strcat ( contains(f, "Fallout", 'fallout.png:', ''), contains(f, "Half-Life", 'halflife.png:', ''), contains(f, "Mass Effect Trilogy|Mass Effect: Andromeda", 'masseffect.png:', ''), (at least a dozen more like this)... contains(f, "^(2001: A Space Odyssey|Alien|Short Circuit)$", 'Film.png:', ''), ) Since I want to display all the relevant icons, I'm not sure that an if statement would work too well. But would list_contains be appropriate? Last edited by ownedbycats; 12-11-2021 at 07:39 AM. |
![]() |
![]() |
![]() |
#207 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
In this context the if is the same as a function call. Both are expressions that return a value. You can have as many as you want, and you can intermix them. In other words, this works: Code:
program: f = $tags; strcat( if '^Fallout$' in f then 'fallout.png:' fi, list_contains(f, ',', '^Half-Life$', 'halflife.png:', ''), if "^(Mass Effect Trilogy|Mass Effect: Andromeda)$" in f then 'masseffect.png:' fi ) |
|
![]() |
![]() |
![]() |
#208 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Okay, the ifs are working as expected. However, for some reason I'm having some issue with the exact matching. Did I make a formatting mistake?
Interestingly, it's the $ that seems to make it fail. The ^ alone works. If it matters, the #fanficcat of this book is Crossover, Fallout, Mass Effect Trilogy Last edited by ownedbycats; 12-11-2021 at 05:08 PM. |
![]() |
![]() |
![]() |
#209 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 893
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
|
Hello people could you help me with a template. I want to concatenate the publisher's series with the serial number. What should I put on the note sheet?
Already very grateful |
![]() |
![]() |
![]() |
#210 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 225 | 07-27-2025 02:07 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 |