![]() |
#241 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
|
|
![]() |
![]() |
![]() |
#242 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,013
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
|
Quote:
My wikidata-gui plugin has the same glitch, when it updates metadata, the display doesn't update. I'd like to fix that without having to reapply a sort or something. That's the last bug fix I want to put in before posting the new version. |
|
![]() |
![]() |
![]() |
#243 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
It is already in the plugin, with an option to turn it off for chains that do not change data like copy to clipboard, as it takes nearly a second on an 5000 books library (more on larger libraries).
Look for a method called refresh_gui in chain_tools.py. Another way to do it is mentioned by Kovid here and here. Edit: The time my method takes is not in refreshing the gui, but in calculating modified book_ids. Last edited by capink; 01-01-2021 at 08:48 PM. |
![]() |
![]() |
![]() |
#244 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,013
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
|
Ok, found it, thanks. Change added to my code and tested!
I shouldn't have a performance issue there, as I already had a calculated a list of changed books at the end of the code path. Kovid's response I probably need to take into account too, as I add books in another place, but I don't think that code path had a problem with the view not updating. I'll have to test it later to make sure. |
![]() |
![]() |
![]() |
#245 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Formulas Action
The formulas action is a template based solution for doing calculations based on values from multiple books (somewhat similar to excel formulas). Since it is template based, you can also control the formatting of the final report. Similar to the single field action, you can define the formulas at runtime, or have them predefined.
The formulas action comes with the following functions: sum, min, max, median, mean, mode, multiply_by. These functions work on a list of values e.g sum('1,2,3,4'). In addition to the supplied functions, you can define your own using the plugin's module editor, or using calibre's template function editor. More on this below. Two additional functions are included which make it possible to fetch values from different books: from_selection, from_search. Here is an example of how use formulas: Code:
program: col = '#my_col'; vals = from_selection(col); s = sum(vals) Code:
program: col = '#my_col'; vals = from_selection(col); s = sum(vals); avg = mean(vals); strcat('<b><u>Calculations for column ', col, ':</u></b><ul><li>', 'Sum: ', s, '</li><li>', 'Average: ', avg, '</li></ul>') In the above examples we got the value of #my_col for all selected books. We can replace it with values from a search instead of selections, using from_search function: Code:
vals = from_search(col, 'tags:true'); Notes
Defining your own functions You can define your own function using the plugin's module editor. Here is an example of how the mean function is defined: Code:
from calibre_plugins.action_chains.actions.formulas import FormulasFunction import statistics class MeanFormula(FormulasFunction): name = 'mean' arg_count = 1 def run(self, iterable): iterable = self.to_numerical_iterable(iterable) return str(statistics.mean(iterable))
You can also use calibre's template function editor to define the function. If it makes sense to use your function outside this plugin, it might be more suitable to define it in calibre's template function editor Last edited by capink; 01-16-2022 at 12:01 PM. |
![]() |
![]() |
![]() |
#246 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
so it's basically a more featured version of the Sum Columns plugin? nice.
|
![]() |
![]() |
![]() |
#247 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Yes, I wanted to extend it in way that enables me to easily add more functions whenever I want.
|
![]() |
![]() |
![]() |
#248 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,013
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
|
Minor visual feature request...
When adding a new action, set the comment to a default value. For instance, if a selection modifier is created, and the comment field is empty, copy the search or the search name to the comment field. Would this make sense? Or maybe make a button in the action editor to update the comment rather than setting it if empty? |
![]() |
![]() |
![]() |
#249 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I was thinking that would make sense, for example if you set a Calibre action, it autopopulates the comment field with the name of the action. Hopefully in a way that won't overwrite any user comments.
|
![]() |
![]() |
![]() |
#250 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
There is no clean way to do this, as you have to do it for every action separately. Also you have to check every time the user changes the action if the comment is auto-generated, before you replace it.
|
![]() |
![]() |
![]() |
#251 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,013
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
|
That's why I suggested having a button for it, in the action options pane.
|
![]() |
![]() |
![]() |
#252 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
This is not a clean way of doing it. The options pane is for settings that are passed to the action when the chain runs. And more importantly it does not have access to the any filed in the chain tables including the comments, so you still have have to put code elsewhere to read from each action options pane, do all the checks, and then insert the comment.
I am not going to over-complicate the code to that degree, when the user can already type whatever comments he wants. |
![]() |
![]() |
![]() |
#253 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,007
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Unsure if I'm dumb or...
The button says "Chain(s) Conditions." But as far as I can tell, the user can only add one condition? |
![]() |
![]() |
![]() |
#254 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
It refers to the ability to set it for more than one chain simultaneously. Maybe this is not grammatically right, I am not sure. If so, I will modify it in the next release.
Note that you can set multiple conditions using one template. As an example, this template tests for two conditions (selection_count + book format). The following boolean template functions can be useful for setting multiple conditions: and(), or(), not(). |
![]() |
![]() |
![]() |
#255 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,013
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
|
I must have missed something. Is there a button to create named templates for the chain/action condition? I see the templates in the documentation, but not where to put them.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Editor Plugin] Editor Chains | capink | Plugins | 106 | 06-17-2025 05:36 PM |
Action Chains Resources | capink | Plugins | 77 | 06-16-2025 12:45 PM |
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB | lrpirlet | Plugins | 2 | 08-18-2022 03:15 PM |
[GUI Plugin] Save Virtual Libraries To Column (GUI) | chaley | Plugins | 14 | 04-04-2021 05:25 AM |