Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 01-01-2021, 02:34 PM   #241
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
Quote:
Originally Posted by capink View Post
I don't really want to get into platform specific fixes. Maybe will look at this later to see if simple fixes exist. Problem I cannot test on Windows so difficult to do anything.

This link seems to have some solutions, one of them is changing a registry key. Give it a go and see if it helps.
I already have LongPathsEnabled set. It only affects the actual filepaths though, not the command prompt.
ownedbycats is offline   Reply With Quote
Old 01-01-2021, 08:32 PM   #242
compurandom
Wizard
compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.
 
Posts: 1,013
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
Quote:
Originally Posted by capink View Post
Ahh, I got it. The plugin should probably refresh the gui after running the chain. I will add this to next release, and see if it solves your problems.
Somehow I thought you posted code for this fix, but I can't find it.
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.
compurandom is offline   Reply With Quote
Old 01-01-2021, 08:46 PM   #243
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
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.
capink is offline   Reply With Quote
Old 01-01-2021, 09:25 PM   #244
compurandom
Wizard
compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.
 
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.
compurandom is offline   Reply With Quote
Old 01-04-2021, 01:20 PM   #245
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
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)
This will print the result of the sum in a pop-up final report. We can take this further by defining more than one formula and adding some formatting to the final report:

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>')
You can see how the final report looks in the attached screenshot.

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
  • Only general program mode is supported.
  • In addition to functions defined by the formulas action, calibre template language has arithmetic functions like: add, substract, multiply, divide .... etc, they can be used together.

    Update: As of calibre 5.13, template language supports several operator types including arithmetic operators. So people using calibre version >= 5.13 can replace this:

    Code:
    program:
    add(1,2)
    with:

    Code:
    program:
    1 + 2
    See this post for more details.
  • If you want to have line breaks in the report, you can use the <br> tag. If you want multiple adjacent spaces you can use '&nbsp;' for each space.
  • For performance reasons, whenever in the formula editor, the from_selection and from_search functions return a fixed list ('1,2,3,4,5'). Otherwise, the editor would be very slow while waiting for the full results from these two functions. This will be reflected in the result you see in the editor's preview box.
  • All the numerical functions like sum, mean ... etc will discard non-numerical values in lists. If you want, you can convert these values to a number using the re_non_numerical function (an additional function defined by formulas). For example, the mean function will disregard all columns that does not have values (represented as 'None' in the list). If you want these to be counted, do the following:

    Code:
    program:
        col = '#my_col';
        vals = from_selection(col);
        new_vals = re_non_numerical(vals, 0);
        avg = mean(new_vals)
    This way the mean function should count the undefined columns.

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))
There are some caveats you have to observe:
  • In template functions, all args are of string type. So, you have to unpack (if in an iterable) and convert to whatever datatype you want. When you return the result of your function, convert back to string.
  • Even None values are strings in the form of 'None'. So you have to account of that.

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
Attached Thumbnails
Click image for larger version

Name:	formulas_report.png
Views:	961
Size:	16.4 KB
ID:	184495  

Last edited by capink; 01-16-2022 at 12:01 PM.
capink is offline   Reply With Quote
Old 01-04-2021, 01:22 PM   #246
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
so it's basically a more featured version of the Sum Columns plugin? nice.
ownedbycats is offline   Reply With Quote
Old 01-04-2021, 01:47 PM   #247
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
Yes, I wanted to extend it in way that enables me to easily add more functions whenever I want.
capink is offline   Reply With Quote
Old 01-10-2021, 10:24 AM   #248
compurandom
Wizard
compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.
 
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?
compurandom is offline   Reply With Quote
Old 01-10-2021, 01:48 PM   #249
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 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.
ownedbycats is offline   Reply With Quote
Old 01-10-2021, 03:14 PM   #250
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
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.
capink is offline   Reply With Quote
Old 01-10-2021, 06:12 PM   #251
compurandom
Wizard
compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.
 
Posts: 1,013
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
Quote:
Originally Posted by capink View Post
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.
That's why I suggested having a button for it, in the action options pane.
compurandom is offline   Reply With Quote
Old 01-11-2021, 10:19 AM   #252
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
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.
capink is offline   Reply With Quote
Old 01-16-2021, 01:14 AM   #253
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
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?
ownedbycats is offline   Reply With Quote
Old 01-16-2021, 08:32 AM   #254
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
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().
capink is offline   Reply With Quote
Old 01-16-2021, 08:46 AM   #255
compurandom
Wizard
compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.
 
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.
compurandom is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 03:50 AM.


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