Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 10-30-2021, 06:01 AM   #1
Vianney
Junior Member
Vianney began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Oct 2021
Device: KOBO Aura H20
How to divide a custom column value?

Hello everyone,

I'm new to this forum so I hope I'm in the good place for this question.

I use the Countpage plugin which displays the number of words of a epub in a custom column called "mots".

What I want to do is to display a fraction of this number in another custom column called "durée" (so I can have the reading time of the book, based on my reading speed)

I read some documentation about the calibre templates and functions and I try a lot, but I can't manage to perform this simple operation. I get an error each time i try.

Can anyone explain to me which syntax to use for this operation?

Thanks you very much

Vianney
Vianney is offline   Reply With Quote
Old 10-30-2021, 07:41 AM   #2
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,725
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
I searched this sub-forum for 'calculate' and found:

How many hours for a book

Calculate reading time.

Moderator Notice

And, I moved your thread here because you must have missed this sticky

PLEASE READ BEFORE POSTING - Purpose of Development subforum


BR
BetterRed is online now   Reply With Quote
Advert
Old 10-30-2021, 11:39 AM   #3
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,211
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by Vianney View Post
Hello everyone,

I'm new to this forum so I hope I'm in the good place for this question.

I use the Countpage plugin which displays the number of words of a epub in a custom column called "mots".

What I want to do is to display a fraction of this number in another custom column called "durée" (so I can have the reading time of the book, based on my reading speed)

I read some documentation about the calibre templates and functions and I try a lot, but I can't manage to perform this simple operation. I get an error each time i try.

Can anyone explain to me which syntax to use for this operation?

Thanks you very much

Vianney

I believe this is what you are asking for:

Code:
program:
	reading_time = divide(raw_field('#mots'), 50);
	h = format_number(subtract(reading_time, fractional_part(reading_time)),  '{0:0>2.0f}');
	m = format_number(multiply(fractional_part(reading_time), 60), '{0:0>2.0f}');
	reading_time = strcat(h, 'h ', m, 'm')
Use the template above on your 'durée' column. The value in red on the first line represents your reading speed in pages/hour. Just change it accordingly.

P.S.: I formatted the result to be more human readable. Ex.: '12.8' becomes '12h 48m'.

Edit: You acctually mentioned words, not pages. But it works just the same. Just use your speed in words/hour.

Last edited by thiago.eec; 10-30-2021 at 12:53 PM. Reason: Clarification
thiago.eec is offline   Reply With Quote
Old 10-30-2021, 02:18 PM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by thiago.eec View Post
Code:
program:
	reading_time = divide(raw_field('#mots'), 50);
	h = format_number(subtract(reading_time, fractional_part(reading_time)),  '{0:0>2.0f}');
	m = format_number(multiply(fractional_part(reading_time), 60), '{0:0>2.0f}');
	reading_time = strcat(h, 'h ', m, 'm')
And just for fun, using the recent changes to the template language:
Code:
program:
	reading_time = (if $$#mots == 'none' then 0 else $$#myfloat fi) / 50;
	h = format_number(floor(reading_time), '{0:0>2.0f}');
	m = format_number(fractional_part(reading_time) * 60, '{0:0>2.0f}');
	reading_time = strcat(h, 'h ', m, 'm')
The strange 'if' on line 2 is there because I found a bug in calculating binary operators like '/'. Undefined raw fields don't work. I will fix that. After I fix it the line would be
Code:
	reading_time = $$#mots / 50;
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using RE to extract pattern from custom column into another custom column activedirectory Library Management 1 12-15-2019 08:07 PM
Adding custom column with any lookup-name gives me empty column as a result? Ahu Lee Library Management 16 06-09-2019 12:14 PM
Move selected data from series column to a new custom column fvdham Library Management 3 06-02-2017 03:49 PM
Custom column returns value based on value of another custom column? calvin-c Calibre 3 09-14-2013 02:24 PM
how to move value(s) of tag column to a custom made column zoorakhan Library Management 0 12-08-2012 03:53 AM


All times are GMT -4. The time now is 02:28 AM.


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