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 11-23-2021, 02:47 PM   #196
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,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?
ownedbycats is online now   Reply With Quote
Old 11-23-2021, 05:20 PM   #197
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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?
I am not sure what question you are asking. Guessing ...

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
I don't know if the performance is acceptable.
chaley is offline   Reply With Quote
Advert
Old 12-09-2021, 07:42 PM   #198
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,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.
ownedbycats is online now   Reply With Quote
Old 12-10-2021, 02:38 AM   #199
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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.
No, there isn't any profiling for templates. And I am not sure it would be useful in the face of templates that refer to other templates.

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.
chaley is offline   Reply With Quote
Old 12-10-2021, 05:54 AM   #200
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
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
Edit: A custom function called (time_it) can do the same

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.
capink is offline   Reply With Quote
Advert
Old 12-10-2021, 07:27 AM   #201
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
Wouldn't measuring the time elapsed (in template tester) provide some kind of rough measure, by which you can compare different templates?
One problem is that the work to compute the time could easily exceed the time to compute the template. I think that I would need to add profiling to the formatter itself to avoid this.

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.
chaley is offline   Reply With Quote
Old 12-11-2021, 04:33 AM   #202
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,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:', ''),
   )
it sometimes breaks if "test123" is in the taglike. It works again if I remove the exact-match modifiers but then it's not exact matching.
ownedbycats is online now   Reply With Quote
Old 12-11-2021, 06:12 AM   #203
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
One problem is that the work to compute the time could easily exceed the time to compute the template. I think that I would need to add profiling to the formatter itself to avoid this.

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.
Thanks for the informative and comprehensive reply.
capink is offline   Reply With Quote
Old 12-11-2021, 06:17 AM   #204
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
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:', ''),
   )
it sometimes breaks if "test123" is in the taglike. It works again if I remove the exact-match modifiers but then it's not exact matching.
I think you need to change the regex:

Code:
program:
   f = field('#field');
   strcat
   (
    contains(f, "^(foo|bar|foobar|test123)$", 'icon.png:', ''),
   )
capink is offline   Reply With Quote
Old 12-11-2021, 07:21 AM   #205
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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:', ''),
   )
it sometimes breaks if "test123" is in the taglike. It works again if I remove the exact-match modifiers but then it's not exact matching.
Are you sure that you want contains() on a tags-like column? The contains() function looks at the string of tags as a single element, not as a list. As such, if the column value is 'foo, zorro' then your expression can never match. It will succeed only if the column contains a single value, which raises the questions "why is it tags-like?".

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
		)
Alternatively, this, which is closer in spirit to what you did.
Code:
program:
	f = field('#mytextmult');
	strcat
		(
			list_contains(f, ',', "^(foo|bar|foobar|test123)$", 'icon.png:', '')
		)
chaley is offline   Reply With Quote
Old 12-11-2021, 07:37 AM   #206
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,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:', ''),
   )
I just combine the miscellaneous one into generic film/book/videogame icons. Since it's a stored template both the column icons and emblems get updated.

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.
ownedbycats is online now   Reply With Quote
Old 12-11-2021, 08:22 AM   #207
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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:', ''),
   )
I just combine the miscellaneous one into generic film/book/videogame icons. Since it's a stored template both the column icons and emblems get updated.

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?
Yes, given the above you want list_contains(), not contains().

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
	)
The 'if' is slightly faster because it is directly executed by the formatter. list_contains() is a template function call that is not inlined.
chaley is offline   Reply With Quote
Old 12-11-2021, 05:05 PM   #208
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,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
Attached Thumbnails
Click image for larger version

Name:	2021-12-11 18_06_38-Template tester.png
Views:	907
Size:	30.7 KB
ID:	190769   Click image for larger version

Name:	2021-12-11 18_06_58-Template tester.png
Views:	913
Size:	30.5 KB
ID:	190770  

Last edited by ownedbycats; 12-11-2021 at 05:08 PM.
ownedbycats is online now   Reply With Quote
Old 12-11-2021, 05:17 PM   #209
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
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
Attached Thumbnails
Click image for larger version

Name:	1.jpg
Views:	932
Size:	13.9 KB
ID:	190771  
dunhill is offline   Reply With Quote
Old 12-11-2021, 05:24 PM   #210
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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
Sorry, I led you astray. You should use 'inlist', not 'in'.
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 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


All times are GMT -4. The time now is 06:25 AM.


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