View Single Post
Old 06-04-2016, 06:54 PM   #1
Joanna
Groupie
Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.Joanna understands the mechanisms of the catecholamine pathways.
 
Posts: 199
Karma: 76476
Join Date: Feb 2012
Location: Poland
Device: none
A custom column built from other columns: simple math operations

In my library, I have a custom column #pages (the number of pages as estimated by the Count Pages plugin) and a custom column #progress (which is a number, entered manually based on the information from my Kindle: if the Kindle shows 54%, I enter 54 etc.).

I would like to have:
a) a column that shows the number of pages read,
b) a column that shows the number of pages left.

The rough formulas would be:
a) #progress/100 x #pages
b) (100-#progress)/100 x #pages

which, translated into the Calibre template language, look as follows:

a) {#calc:'multiply(divide(field('#progress'), 100), field('#pages'))'}
b) {#calc:'multiply(divide(subtract(100, field('#progress')), 100), field('#pages'))'}

This seems to render correct results. Still, I have some doubts and questions:

1) I don't quite get the very beginning: do I have to put the name of field (#calc: )? It doesn't seem to matter which field I put there (still not quite getting the syntax ).

2) What function should I use so that the calculations are made only if #progress is not empty, and otherwise the target column is left blank?

3) Is it possible to sort such a calculated column in an ascending/descending order like a regular numerical column, and if so, how to achieve that? At the moment, sorting is kind of alphabetical, based on the first digit, then the second digit etc. while ignoring the order of magnitude, i.e. 40 and 400 would be between 4 and 5.
Joanna is offline   Reply With Quote