![]() |
#16 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,374
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Thanks. I will look.
Quote:
Code:
program: list_sort( list_difference( list_union(field('#shelf'), field('tags'), ','), list_union('Short, delete', strcat(field('#genre'), ',', field('#mode'), ',', field('#character')), ','), ','), 0, ',') |
|
![]() |
![]() |
![]() |
#17 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
It worked. Thanks.
Now it takes 2 mins and a few seconds to write all the data. I'm thinking of another cheat. Just rename shelves according to the category. If it belongs to genre just add word genre/g or something in the beginning so when viewing the list it would show it alphabetically so all genres would be there. I can do the same with tags. A little work while renaming and after that it should look ok. Not as nice as having separate columns but it would work without any freezes as before. I'm not sure I would like how it looks. Having tags like g-action, g-adventure etc. I guess I will keep it as an option if freezing up makes it too much trouble working with metadata. Would making the list for list_intersection shorter make it easier for calibre? I could remove a lot from category character since there are way too many detail tags. Last edited by Noughty; 10-16-2011 at 08:51 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#18 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,374
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
If you don't mind getting more complicated, we *can* justify the cost of using a python evaluation function. For example, for the template we have been playing with in the last 2 posts, a custom function could easily be 100 times faster to evaluate. That won't change the time needed to build the categories for the tag browser, but it would drastically reduce the amount of time needed to build the columns so the categories can be built. Here is the last template rewritten as a template function. To put this into your library, go to preferences -> advanced -> template functions. You will see some boxes. Fill them in as follows: Code:
Function: myListMerge (you can use any name here you want, as long as it is alphabetic. You might consider using the column name, such as myWhateverItIs.) Arg count: 0 (ignore the warning that will appear later) Documentation: whatever you want to put here Program Code: def evaluate(self, formatter, kwargs, mi, locals): tags = set(mi.get('tags', [])) shelf = set(mi.get('#shelf', [])) genre = set(mi.get('#genre', [])) mode = set(mi.get('#mode', [])) charac = set(mi.get('#character', [])) st = tags | shelf gmc = set(['Short', 'delete']) | genre | mode | charac res = st - gmc return ', '.join(res) You would use this new function in your composite column template as follows, and assuming it is named myListMerge: Code:
{:'myListMerge()'} Do note that this function assumes that the case of all items is identical and uses a case-sensitive compare. For example, it thinks that foo and Foo are different. Fixing this is possible, but it would slow things down somewhat. Last edited by chaley; 10-16-2011 at 10:41 AM. Reason: Fix mistake in composite template to call custom function |
|
![]() |
![]() |
![]() |
#19 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
I created it named as otherts but I don't get any result. I need to write:
{'otherts()'} in custom column made from other tags (behaves like tags)? I get error: EXCEPTION: Value: unknown field 'otherts()' |
![]() |
![]() |
![]() |
#20 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,374
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
For completeness, the :' tells the formatter that what follows is in template program mode, which allows use of functions as arguments and zero-parameter functions. The program goes up to the '}. Writing "{:'foobar()'}" is exactly the same as writing "program:foobar()". You might then ask "why use program:"? That construct allows multiple lines and multiple statements, and is (I think) easier to read. On the other hand, template program mode expressions can be combined together in a single template, such as "{title} {:'foobar()'|- | }" |
|
![]() |
![]() |
Advert | |
|
![]() |
#21 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
It gives wrong result
![]() Nothing gets taken away. It just merges lists (tags, shelf) and deletes 'Short', 'delete', but not other lists Last edited by Noughty; 10-16-2011 at 10:59 AM. |
![]() |
![]() |
![]() |
#22 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,374
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Did I spell the lookup names of the columns correctly?
Are any of #shelf, #mode, #genre, or #character composite columns? I assumed that they were all text, like tags. Do all the words have the same case? If you add 'Short' as a tag, it appears in the output of the custom function? If so, that is odd because it does not for me. Note that if you add 'short' it will appear, but 'Short' should not. |
![]() |
![]() |
![]() |
#23 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
Everything is spelled correctly as far as I can tell.
They are composite columns using code like this: Code:
program: list_union( list_intersection(field('tags'), 'values listed, ','), list_intersection(field('#shelf'), 'values listed', ','), ',') Maybe I could just paste all these values from these into python code like 'short, delete' are? The ones I want to remove. What function I would use in python to write the values I want to keep, not add. Like extract only those values? I'll try to write it myself using your example. I just need a function so I could use it for genre, character,mode columns. It would be more efficient as far as I understand. Last edited by Noughty; 10-16-2011 at 11:17 AM. |
![]() |
![]() |
![]() |
#24 | |||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,374
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
def evaluate(self, formatter, kwargs, mi, locals): # Tags is a multiple text field, so it is already split tags = set(mi.get('tags', [])) # Shelf is a composite column, so we must split it shelf = set([l.strip() for l in mi.get('#shelf', "").split(',')]) # Genre is a composite column, so we must split it genre = set([l.strip() for l in mi.get('#genre', "").split(',')]) # Mode is a composite column, so we must split it mode = set([l.strip() for l in mi.get('#mode', "").split(',')]) # Character is a composite column, so we must split it charac = set([l.strip() for l in mi.get('#character', "").split(',')]) st = tags | shelf gmc = set(['Short', 'delete']) | genre | mode | charac res = st - gmc return ', '.join(res) Quote:
Quote:
Code:
def evaluate(self, formatter, kwargs, mi, locals): # Tags is a multiple text field, so it is already split tags = set(mi.get('tags', [])) # Shelf is a composite column, so we must split it shelf = set([l.strip() for l in mi.get('#shelf', "").split(',')]) # items to remove from the result to_remove = set(['Short', 'delete', 'foo', 'bar', somethingElse', 'andSoOn', 'until I get tired', 'of adding things']) # combine the two fields containing items we might want to keep. st = tags | shelf # now remove the items we don't want in the result res = st - to_remove return ', '.join(res) |
|||
![]() |
![]() |
![]() |
#25 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
I'll try it but shelf isn't composite column. Tags and shelves are simple tag columns.
I edited it and it seems to work It doesn't seem to sort list. Is it possible to use {:'otherts()'} like program? I could use sort function when. Last edited by Noughty; 10-16-2011 at 11:36 AM. |
![]() |
![]() |
![]() |
#26 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,374
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#27 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
Thanks for the comments with them I managed to make edit easily. Now just to figure out how to sort the list
![]() Made it ![]() Just added sort for the result. I might start to get python too... Well, a little ![]() Last edited by Noughty; 10-16-2011 at 11:52 AM. |
![]() |
![]() |
![]() |
#28 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,374
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
![]() Code:
from calibre.utils.icu import sort_key return ', '.join(sorted(res, key=sort_key)) |
|
![]() |
![]() |
![]() |
#29 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
And I just wrote
![]() Code:
return ', '.join(sorted(res)) Where could I read more about functions in python? Seems the speed increased by half a minute. Maybe I could make other columns like this too (genre, character). Since they are basically the same it might not be hard. Code:
def evaluate(self, formatter, kwargs, mi, locals): # Tags is a multiple text field, so it is already split tags = set(mi.get('tags', [])) # Shelf is a composite column, so we must split it shelf = set([l.strip() for l in mi.get('#shelf', "").split(',')]) # items to remove from the result to_remove = set(['Short', 'delete', 'foo', 'bar', somethingElse', 'andSoOn', 'until I get tired', 'of adding things']) # combine the two fields containing items we might want to keep. st = tags | shelf # now remove the items we don't want in the result res = st - to_remove return ', '.join(res) I need to extract specific values Last edited by Noughty; 10-16-2011 at 12:05 PM. |
![]() |
![]() |
![]() |
#30 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,374
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tag browser searching | Stampercam | Calibre | 2 | 06-25-2011 04:42 AM |
Browser freezes loading main forum page | Ripplinger | Feedback | 5 | 04-20-2011 04:24 PM |
Calibre 7.36 Author Fields in Tag Browser is weird | dfad1469 | Library Management | 44 | 01-24-2011 04:47 AM |
Tag Browser partitioning | dasimser | Calibre | 2 | 01-03-2011 12:18 PM |
Empty tag browser | Rachel | Calibre | 18 | 07-26-2010 11:42 AM |