Quote:
Originally Posted by red_dragon
Beware, this is kind of ugly because Calibre doesn't provide math functions (especially modulo) that would make life so much easier.
|
Thank you! I couldn't get it to work...
I just changed 0.49 with 0.499 because I had two books that gave me reading times of X hours and -1 minutes (the reading time in hours was something like 3.9917).
Edit: and after having looked at it a little more, I hadn't though to use regex, but we could also simply do rt1_hour=re(time1, '\.\d*', ''); to truncate the hour... This way no rounding occurs
So here is what I got:
Spoiler:
Code:
program:
# This program calculate a reading time per hour for an ebook
# Adjustments:
# w_min -> minimum words per minute
# w_max -> maximum words per minute
w_min=250;
w_max=300;
# readingtime per hour=60
p_time=60;
# Needs a custom column for word count (#words)
# change it to your field name
words=raw_field('#words');
time1=format_number(divide(words,multiply(w_max, p_time)), '{0:.2f}');
time2=format_number(divide(words,multiply(w_min, p_time)), '{0:.2f}');
# Unfortunately Calibre doesn't provide a simple way to convert a float
# into a time string -> I used a regex
# The minutes can be set to use 2 numbers using python number formatting,
# otherwise times are displayed as 4:4h instead of 4:04h.
rt1_hour=re(time1, '\.\d*', '');
rt1_minute=format_number(multiply(subtract(time1,rt1_hour),60), '{0:02.0f}');
rt2_hour=re(time2, '\.\d*', '');
rt2_minute=format_number(multiply(subtract(time2,rt2_hour),60), '{0:02.0f}');
readingtime=strcat(rt1_hour,':', rt1_minute, 'h - ', rt2_hour, ':', rt2_minute, 'h');
Thanks again for sharing