From e19f73bdba4d0b5199e60ea05e73c5a92f978e5c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 28 Jan 2016 22:37:46 -0800 Subject: [PATCH] style(util): rename tablelength to tableSize --- frontend/apps/reader/modules/readerfooter.lua | 2 +- frontend/util.lua | 5 +++-- plugins/statistics.koplugin/main.lua | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index d01bd5e53..74072622c 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -249,7 +249,7 @@ function ReaderFooter:getDataFromStatistics(title, pages) local statistics_data = self.ui.doc_settings:readSetting("stats") local sec = 'na' if statistics_data and statistics_data.performance_in_pages then - local read_pages = util.tablelength(statistics_data.performance_in_pages) + local read_pages = util.tableSize(statistics_data.performance_in_pages) local average_time_per_page = statistics_data.total_time_in_sec / read_pages sec = util.secondsToClock(pages * average_time_per_page, true) end diff --git a/frontend/util.lua b/frontend/util.lua index 3dfebe88e..89d65975d 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -46,7 +46,7 @@ function util.gsplit(str, pattern, capture) end) end ---https://gist.github.com/jesseadams/791673 +-- https://gist.github.com/jesseadams/791673 function util.secondsToClock(seconds, withoutSeconds) seconds = tonumber(seconds) if seconds == 0 or seconds ~= seconds then @@ -66,7 +66,8 @@ function util.secondsToClock(seconds, withoutSeconds) end end -function util.tablelength(T) +-- returns number of keys in a table +function util.tableSize(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 9fc726934..733668a6b 100755 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -235,7 +235,7 @@ function ReaderStatistics:updateCurrentStat() dates[os.date("%Y-%m-%d", k)] = "" end - local read_pages = util.tablelength(self.data.performance_in_pages) + local read_pages = util.tableSize(self.data.performance_in_pages) local current_page = self.ui.document:getCurrentPage() local average_time_per_page = self.data.total_time_in_sec / read_pages @@ -244,7 +244,7 @@ function ReaderStatistics:updateCurrentStat() table.insert(stats, { text = _("Total time"), mandatory = util.secondsToClock(self.data.total_time_in_sec, false) }) table.insert(stats, { text = _("Total highlights"), mandatory = self.data.highlights }) table.insert(stats, { text = _("Total notes"), mandatory = self.data.notes }) - table.insert(stats, { text = _("Total days"), mandatory = util.tablelength(dates) }) + table.insert(stats, { text = _("Total days"), mandatory = util.tableSize(dates) }) table.insert(stats, { text = _("Average time per page"), mandatory = util.secondsToClock(average_time_per_page, false) }) table.insert(stats, { text = _("Read pages/Total pages"), mandatory = read_pages .. "/" .. self.data.pages }) return stats