From 3d128b543bb5df6f397e954a572a73e7054eda96 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 29 Sep 2018 19:51:25 +0200 Subject: [PATCH] [Statistics] Add estimated reading finished date (#4241) --- plugins/statistics.koplugin/main.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index c6d2b00fa..28faf2df2 100755 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -963,12 +963,15 @@ function ReaderStatistics:getCurrentStat(id_book) total_time_book = tonumber(total_time_book) total_read_pages = tonumber(total_read_pages) local avg_time_per_page = total_time_book / total_read_pages + local time_to_read = (self.data.pages - self.view.state.page) * avg_time_per_page + local estimate_days_to_read = math.ceil(time_to_read/(total_time_book/tonumber(total_days))) + local estimate_end_of_read_date = os.date("%Y-%m-%d", tonumber(os.time() + estimate_days_to_read * 86400)) return { { _("Current period"), util.secondsToClock(current_period, false) }, { _("Current pages"), tonumber(current_pages) }, { _("Today period"), util.secondsToClock(today_period, false) }, { _("Today pages"), tonumber(today_pages) }, - { _("Time to read"), util.secondsToClock((self.data.pages - self.view.state.page) * avg_time_per_page, false) }, + { _("Time to read"), util.secondsToClock(time_to_read), false}, { _("Total time"), util.secondsToClock(total_time_book, false) }, { _("Total highlights"), tonumber(highlights) }, { _("Total notes"), tonumber(notes) }, @@ -977,6 +980,8 @@ function ReaderStatistics:getCurrentStat(id_book) { _("Read pages/Total pages"), total_read_pages .. "/" .. self.data.pages }, -- adding 0.5 rounds to nearest integer with math.floor { _("Percentage completed"), math.floor(total_read_pages / self.data.pages * 100 + 0.5) .. "%" }, + { _("Average time per day"), util.secondsToClock(total_time_book/tonumber(total_days)), false }, + { _("Estimated reading finished"), string.format("%s (%d day(s))", estimate_end_of_read_date, estimate_days_to_read) }, } end