![]() |
#16 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 199
Karma: 76476
Join Date: Feb 2012
Location: Poland
Device: none
|
I guess I have to try replacing the 17 rule icon with one advanced rule/template (although I'm waiting for the end of defragmentation to open Calibre and check how it works with that column hidden).
Here are the rules I use: a) if the column '#target' is set: if #target=English, display 'English' icon if #target=German, display 'German' icon (...) if #target=Swedish, display 'Swedish' icon if #target is none of the above, display 'generic' icon b) if the column '#target' is not set: if languages=English, display 'English' icon if languages=German, display 'German' icon (...) if languages=Swedish, display 'Swedish' icon if languages is set and is none of the above, display 'generic' icon Do you think it's too complex, or is there a reasonable way to implement such a mechanism? So far, I've used simple one or two-condition rules for most of the above (which is why there were so many of them). Two rules required more conditions: the 'generic' ones (because the rules went like 'if #target is not German and if #target is not English (...) and if #target is not Swedish') - I guess those two needed most resources. Any tips and ideas? |
![]() |
![]() |
![]() |
#17 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,376
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@Joanna: do you have any programming knowledge? If so then the right way to do something this complicated is to use a custom template function or to use pre-calculated fields.
The first, custom template functions, are written in python and can in one pass (rule) determine which "flag" is to be displayed. The seconds, a pre-calculated field, would be a text-based custom column containing the name of the icon file for the book. You would run a "calibre" python script from time to time to evaluate the books and enter the icon name for each book. Several of us could supply you with such functions/scripts. The problem with these approaches is that if you don't understand what they are doing and how to maintain them then they are magic, and none of us wants to become your dedicated developer. Personally, I would use a custom template function. BTW: you might get significant performance improvements if you reorder your existing rules so that the most common/probable occur first. Rule evaluation is linear, evaluating one by one until one succeeds or there are no more rules. |
![]() |
![]() |
![]() |
#18 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 199
Karma: 76476
Join Date: Feb 2012
Location: Poland
Device: none
|
You were all right, the 17 rule custom column was the biggest culprit. Without that, Calibre runs pretty smoothly (gotta test it more, though, with more categories shown in the Tag Browser etc.).
@chaley, thanks for your tips and explanations. Unfortunately, my programming knowledge is pretty much non-existing. I do like challenges, though ![]() I've tried to write a custom template function and it seems that it does work! ![]() program: a =field ('#target'); b = field ('languages'); test (a, switch (a, 'English', 'united_kingdom_flag.png', 'Polish', 'poland.png', 'German', 'germany_flag.png', 'French', 'france_flag.png', 'Swedish', 'sweden.png', 'Dutch', 'netherlands_flag.png', 'Spanish', 'spain.png', 'generic_flag.png'), switch (b, 'eng', 'united_kingdom_flag.png', 'pol', 'poland.png', 'deu', 'germany_flag.png', 'fra', 'france_flag.png', 'swe', 'sweden.png', 'nld', 'netherlands_flag.png', 'spa', 'spain.png', 'generic_flag.png')) One thing I haven't figured out: there are (rare) cases where one book has more than one language (in 'languages' or in '#target'). What functions/structures should I use to display more than one flag then? |
![]() |
![]() |
![]() |
#19 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Looks good to me! GPM is pretty simple logic for the most part.
![]() Can you show multiple icons? (My inexperience shows. ![]() I don't believe there is a builtin way to iterate over anything in GPM, though a custom function could do it. |
![]() |
![]() |
![]() |
#20 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 199
Karma: 76476
Join Date: Feb 2012
Location: Poland
Device: none
|
@eschwartz, thanks! Yes, you can show multiple icons (provided that the option 'composed icons' has been chosen).
I'll check the list_item() function (but now I have to get some sleep ![]() Here an enhanced version of the template function (so that no flag is shown if no language has been set). (Am I right that you just leave '' if nothing should happen? Seems to work.) program: a =field ('#target'); b = field ('languages'); test (a, switch (a, 'English', 'united_kingdom_flag.png', 'Polish', 'poland.png', 'German', 'germany_flag.png', 'French', 'france_flag.png', 'Swedish', 'sweden.png', 'Dutch', 'netherlands_flag.png', 'Spanish', 'spain.png', 'generic_flag.png'), test(b, switch (b, 'eng', 'united_kingdom_flag.png', 'pol', 'poland.png', 'deu', 'germany_flag.png', 'fra', 'france_flag.png', 'swe', 'sweden.png', 'nld', 'netherlands_flag.png', 'spa', 'spain.png', 'generic_flag.png'), '') ) |
![]() |
![]() |
![]() |
#21 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
The switch function accepts a final fallback value -- should be empty.
Use ifempty() to skip the first switch statement if it is empty -- or first_non_empty() for more than two switches. No need for recursive test()'s. The final '' is redundant logic -- you should be relying on the spot reserved by generic_flag.png Speaking of which those are mutually conflicting goals. Last edited by eschwartz; 12-30-2015 at 11:19 PM. |
![]() |
![]() |
![]() |
#22 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 199
Karma: 76476
Join Date: Feb 2012
Location: Poland
Device: none
|
I think the final '' is not redundant (but I may be totally wrong). If I don't use here the second test(), I get 'generic_flag.png' displayed if there is no information about the language.
I'll read about ifempty() and first_non_empty(), thank you! |
![]() |
![]() |
![]() |
#23 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,376
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
As you say, you can iterate in a custom template function (CF). My guess is that in this case a CF would have between 1 and 2 orders of magnitude better performance than a GPM template because the CF would evaluate only what it needs, while a GPM template evaluates all arguments then applies the logic. |
||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calibre Running Really Slowly | polly | Devices | 21 | 10-28-2013 08:18 PM |
Calibre for Mac running slowly | scubasaida | Calibre | 3 | 08-12-2011 06:37 PM |
Slowly running forum | JSWolf | Feedback | 5 | 07-19-2011 07:15 PM |
calibre running slowly OS X?? | tm3 | Calibre | 3 | 01-14-2011 10:31 AM |
BooksOnBoard is running really slowly | JSWolf | Reading Recommendations | 3 | 02-22-2009 08:00 PM |