mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
Statistics in bookstatuswidget (#3218)
This commit is contained in:
parent
e566a7ffc6
commit
e5eb015f1b
@ -27,6 +27,8 @@ local template = require("ffi/util").template
|
|||||||
local util = require("util")
|
local util = require("util")
|
||||||
local _ = require("gettext")
|
local _ = require("gettext")
|
||||||
|
|
||||||
|
local stats_book = {}
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
--Save into sdr folder addtional section
|
--Save into sdr folder addtional section
|
||||||
["summary"] = {
|
["summary"] = {
|
||||||
@ -47,16 +49,9 @@ local BookStatusWidget = InputContainer:new{
|
|||||||
status = "",
|
status = "",
|
||||||
modified = "",
|
modified = "",
|
||||||
},
|
},
|
||||||
stats = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function BookStatusWidget:init()
|
function BookStatusWidget:init()
|
||||||
self.stats = {
|
|
||||||
total_time_in_sec = 0,
|
|
||||||
performance_in_pages = {},
|
|
||||||
total_pages = self.document:getPageCount(),
|
|
||||||
}
|
|
||||||
self:getStatisticsSettings()
|
|
||||||
if self.settings then
|
if self.settings then
|
||||||
self.summary = self.settings:readSetting("summary") or {
|
self.summary = self.settings:readSetting("summary") or {
|
||||||
rating = nil,
|
rating = nil,
|
||||||
@ -65,6 +60,8 @@ function BookStatusWidget:init()
|
|||||||
modified = "",
|
modified = "",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
self.total_pages = self.view.document:getPageCount()
|
||||||
|
stats_book = self:getStats()
|
||||||
|
|
||||||
self.small_font_face = Font:getFace("smallffont")
|
self.small_font_face = Font:getFace("smallffont")
|
||||||
self.medium_font_face = Font:getFace("ffont")
|
self.medium_font_face = Font:getFace("ffont")
|
||||||
@ -89,6 +86,34 @@ function BookStatusWidget:init()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BookStatusWidget:getStats()
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function BookStatusWidget:getStatDays()
|
||||||
|
if stats_book.days then
|
||||||
|
return stats_book.days
|
||||||
|
else
|
||||||
|
return _("N/A")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BookStatusWidget:getStatHours()
|
||||||
|
if stats_book.time then
|
||||||
|
return util.secondsToClock(stats_book.time, false)
|
||||||
|
else
|
||||||
|
return _("N/A")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BookStatusWidget:getStatReadPages()
|
||||||
|
if stats_book.pages then
|
||||||
|
return string.format("%s/%s",stats_book.pages, self.total_pages)
|
||||||
|
else
|
||||||
|
return _("N/A")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function BookStatusWidget:getStatusContent(width)
|
function BookStatusWidget:getStatusContent(width)
|
||||||
return VerticalGroup:new{
|
return VerticalGroup:new{
|
||||||
align = "left",
|
align = "left",
|
||||||
@ -106,31 +131,6 @@ function BookStatusWidget:getStatusContent(width)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function BookStatusWidget:getStatDays(stats)
|
|
||||||
if stats and stats.performance_in_pages then
|
|
||||||
local dates = {}
|
|
||||||
for k, v in pairs(stats.performance_in_pages) do
|
|
||||||
dates[os.date("%Y-%m-%d", k)] = ""
|
|
||||||
end
|
|
||||||
return util.tableSize(dates)
|
|
||||||
end
|
|
||||||
return "none"
|
|
||||||
end
|
|
||||||
|
|
||||||
function BookStatusWidget:getStatHours(stats)
|
|
||||||
if stats and stats.total_time_in_sec then
|
|
||||||
return util.secondsToClock(stats.total_time_in_sec, false)
|
|
||||||
end
|
|
||||||
return "none"
|
|
||||||
end
|
|
||||||
|
|
||||||
function BookStatusWidget:getReadPages(stats)
|
|
||||||
if stats and stats.performance_in_pages and stats.total_pages then
|
|
||||||
return util.tableSize(stats.performance_in_pages) .. "/" .. stats.total_pages
|
|
||||||
end
|
|
||||||
return "none"
|
|
||||||
end
|
|
||||||
|
|
||||||
function BookStatusWidget:genHeader(title)
|
function BookStatusWidget:genHeader(title)
|
||||||
local width, height = Screen:getWidth(), Screen:scaleBySize(35)
|
local width, height = Screen:getWidth(), Screen:scaleBySize(35)
|
||||||
|
|
||||||
@ -255,8 +255,7 @@ function BookStatusWidget:genBookInfoGroup()
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
-- progress bar
|
-- progress bar
|
||||||
local total_pages = self.stats.total_pages
|
local read_percentage = self.view.state.page / self.total_pages
|
||||||
local read_percentage = self.view.state.page / total_pages
|
|
||||||
local progress_bar = ProgressWidget:new{
|
local progress_bar = ProgressWidget:new{
|
||||||
width = width * 0.7,
|
width = width * 0.7,
|
||||||
height = Screen:scaleBySize(10),
|
height = Screen:scaleBySize(10),
|
||||||
@ -357,21 +356,21 @@ function BookStatusWidget:genStatisticsGroup(width)
|
|||||||
CenterContainer:new{
|
CenterContainer:new{
|
||||||
dimen = Geom:new{ w = tile_width, h = tile_height },
|
dimen = Geom:new{ w = tile_width, h = tile_height },
|
||||||
TextWidget:new{
|
TextWidget:new{
|
||||||
text = self:getStatDays(self.stats),
|
text = self:getStatDays(),
|
||||||
face = self.medium_font_face,
|
face = self.medium_font_face,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CenterContainer:new{
|
CenterContainer:new{
|
||||||
dimen = Geom:new{ w = tile_width, h = tile_height },
|
dimen = Geom:new{ w = tile_width, h = tile_height },
|
||||||
TextWidget:new{
|
TextWidget:new{
|
||||||
text = self:getStatHours(self.stats),
|
text = self:getStatHours(),
|
||||||
face = self.medium_font_face,
|
face = self.medium_font_face,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CenterContainer:new{
|
CenterContainer:new{
|
||||||
dimen = Geom:new{ w = tile_width, h = tile_height },
|
dimen = Geom:new{ w = tile_width, h = tile_height },
|
||||||
TextWidget:new{
|
TextWidget:new{
|
||||||
text = self:getReadPages(self.stats),
|
text = self:getStatReadPages(),
|
||||||
face = self.medium_font_face,
|
face = self.medium_font_face,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -507,18 +506,6 @@ function BookStatusWidget:onClose()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function BookStatusWidget:getStatisticsSettings()
|
|
||||||
if self.settings then
|
|
||||||
local stats = self.settings:readSetting("stats")
|
|
||||||
if stats then
|
|
||||||
self.stats.total_time_in_sec = self.stats.total_time_in_sec + stats.total_time_in_sec
|
|
||||||
for k, v in pairs(stats.performance_in_pages) do
|
|
||||||
self.stats.performance_in_pages[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function BookStatusWidget:onSwitchFocus(inputbox)
|
function BookStatusWidget:onSwitchFocus(inputbox)
|
||||||
self.note_dialog = InputDialog:new{
|
self.note_dialog = InputDialog:new{
|
||||||
title = "Note",
|
title = "Note",
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
local BookStatusWidget = require("ui/widget/bookstatuswidget")
|
||||||
local ConfirmBox = require("ui/widget/confirmbox")
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
local DataStorage = require("datastorage")
|
local DataStorage = require("datastorage")
|
||||||
local DocSettings = require("docsettings")
|
local DocSettings = require("docsettings")
|
||||||
@ -95,6 +96,9 @@ function ReaderStatistics:init()
|
|||||||
self.convert_to_db = settings.convert_to_db
|
self.convert_to_db = settings.convert_to_db
|
||||||
self.ui.menu:registerToMainMenu(self)
|
self.ui.menu:registerToMainMenu(self)
|
||||||
self:checkInitDatabase()
|
self:checkInitDatabase()
|
||||||
|
BookStatusWidget.getStats = function()
|
||||||
|
return self:getStatsBookStatus(self.id_curr_book, self.is_enabled)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderStatistics:initData()
|
function ReaderStatistics:initData()
|
||||||
@ -128,6 +132,45 @@ function ReaderStatistics:initData()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderStatistics:getStatsBookStatus(id_curr_book, stat_enable)
|
||||||
|
if not stat_enable or id_curr_book == nil then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
self:insertDB(self.id_curr_book)
|
||||||
|
local conn = SQ3.open(db_location)
|
||||||
|
local sql_stmt = [[
|
||||||
|
SELECT count(*)
|
||||||
|
FROM (
|
||||||
|
SELECT strftime('%%Y-%%m-%%d', start_time, 'unixepoch', 'localtime') AS dates
|
||||||
|
FROM page_stat
|
||||||
|
WHERE id_book = '%s'
|
||||||
|
GROUP BY dates
|
||||||
|
)
|
||||||
|
]]
|
||||||
|
local total_days = conn:rowexec(string.format(sql_stmt, id_curr_book))
|
||||||
|
sql_stmt = [[
|
||||||
|
SELECT sum(period),
|
||||||
|
count(DISTINCT page)
|
||||||
|
FROM page_stat
|
||||||
|
WHERE id_book = '%s'
|
||||||
|
]]
|
||||||
|
local total_time_book, total_read_pages = conn:rowexec(string.format(sql_stmt, id_curr_book))
|
||||||
|
conn:close()
|
||||||
|
|
||||||
|
if total_time_book == nil then
|
||||||
|
total_time_book = 0
|
||||||
|
end
|
||||||
|
if total_read_pages == nil then
|
||||||
|
total_read_pages = 0
|
||||||
|
end
|
||||||
|
return {
|
||||||
|
days = tonumber(total_days),
|
||||||
|
time = tonumber(total_time_book),
|
||||||
|
pages = tonumber(total_read_pages),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderStatistics:checkInitDatabase()
|
function ReaderStatistics:checkInitDatabase()
|
||||||
local conn = SQ3.open(db_location)
|
local conn = SQ3.open(db_location)
|
||||||
if self.convert_to_db then -- if conversion to sqlite was doing earlier
|
if self.convert_to_db then -- if conversion to sqlite was doing earlier
|
||||||
|
Loading…
Reference in New Issue
Block a user