Statistics plugin v2 (SQLite) (#2893)

pull/3147/head
Robert 7 years ago committed by Frans de Jonge
parent efac2721bf
commit 0e2d20353a

@ -208,6 +208,7 @@ function ReaderFooter:init()
if self.settings.auto_refresh_time then
self:setupAutoRefreshTime()
end
self.average_time_per_page = nil
end
function ReaderFooter:setupAutoRefreshTime()
@ -496,12 +497,9 @@ function ReaderFooter:setTocMarkers()
end
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.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)
if self.average_time_per_page then
sec = util.secondsToClock(pages * self.average_time_per_page, true)
end
return title .. sec
end
@ -684,6 +682,11 @@ function ReaderFooter:onSuspend()
end
end
function ReaderFooter:onUpdateStats(avg_time_page)
self.average_time_per_page = avg_time_page
return true
end
function ReaderFooter:onFrontlightStateChanged()
if self.settings.frontlight then
self:updateFooter()

File diff suppressed because it is too large Load Diff

@ -2,8 +2,8 @@ local Blitbuffer = require("ffi/blitbuffer")
local CenterContainer = require("ui/widget/container/centercontainer")
local CloseButton = require("ui/widget/closebutton")
local Font = require("ui/font")
local Geom = require("ui/geometry")
local FrameContainer = require("ui/widget/container/framecontainer")
local Geom = require("ui/geometry")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan")
local InputContainer = require("ui/widget/container/inputcontainer")
@ -36,16 +36,6 @@ local dayOfWeekTranslation = {
["Sunday"] = _("Sunday"),
}
local shortDayOfWeekTranslation = {
["Mon"] = _("Mon"),
["Tue"] = _("Tue"),
["Wed"] = _("Wed"),
["Thu"] = _("Thu"),
["Fri"] = _("Fri"),
["Sat"] = _("Sat"),
["Sun"] = _("Sun"),
}
function ReaderProgress:init()
self.small_font_face = Font:getFace("smallffont")
self.medium_font_face = Font:getFace("ffont")
@ -65,30 +55,16 @@ function ReaderProgress:init()
}
end
function ReaderProgress:getTotalStats(dates)
function ReaderProgress:getTotalStats(stats_day)
local total_time = 0
local total_pages = 0
for _, v in pairs(dates) do
total_pages = total_pages + v. count
total_time = total_time + v.read
for i=1, stats_day do
total_pages = total_pages + self.dates[i][1]
total_time = total_time + self.dates[i][2]
end
return total_time, total_pages
end
function ReaderProgress:getTodayStats(dates)
local today_time = 0
local today_pages = 0
local now_time = os.time()
local today = string.format("%s (%s)",
os.date("%Y-%m-%d", now_time),
shortDayOfWeekTranslation[os.date("%a", now_time)])
if dates[today] ~= nil then
today_time = dates[today].read
today_pages = dates[today].count
end
return today_time, today_pages
end
function ReaderProgress:getStatusContent(width)
return VerticalGroup:new{
align = "left",
@ -188,7 +164,6 @@ end
function ReaderProgress:genWeekStats(stats_day)
local second_in_day = 86400
local date_format
local date_format_show
local select_day_time
local diff_time
@ -199,10 +174,11 @@ function ReaderProgress:genWeekStats(stats_day)
}
local statistics_group = VerticalGroup:new{ align = "left" }
local max_week_time = -1
for _, v in pairs(self.dates) do
if v.read > max_week_time then max_week_time = v.read end
local day_time
for i=1, stats_day do
day_time = self.dates[i][2]
if day_time > max_week_time then max_week_time = day_time end
end
local top_padding_span = HorizontalSpan:new{ width = Screen:scaleBySize(15) }
local top_span_group = HorizontalGroup:new{
align = "center",
@ -222,13 +198,12 @@ function ReaderProgress:genWeekStats(stats_day)
},
}
for i = 1, stats_day , 1 do
local j = 1
for i = 1, stats_day do
diff_time = now_time - second_in_day * (i - 1)
date_format = string.format("%s (%s)",
os.date("%Y-%m-%d", diff_time),
shortDayOfWeekTranslation[os.date("%a", diff_time)])
if self.dates[date_format] ~= nil then
select_day_time = self.dates[date_format].read
if self.dates[j][3] == os.date("%Y-%m-%d", diff_time) then
select_day_time = self.dates[j][2]
j = j + 1
else
select_day_time = 0
end
@ -272,7 +247,6 @@ function ReaderProgress:genWeekStats(stats_day)
end
function ReaderProgress:genSummaryDay(width)
local today_time, today_pages = self:getTodayStats(self.dates)
local height = Screen:scaleBySize(60)
local statistics_container = CenterContainer:new{
dimen = Geom:new{ w = width, h = height },
@ -341,14 +315,14 @@ function ReaderProgress:genSummaryDay(width)
CenterContainer:new{
dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new{
text = today_pages,
text = self.today_pages,
face = self.medium_font_face,
},
},
CenterContainer:new{
dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new{
text = util.secondsToClock(today_time, true),
text = util.secondsToClock(self.today_period, true),
face = self.medium_font_face,
},
},
@ -367,7 +341,7 @@ end
function ReaderProgress:genSummaryWeek(width)
local height = Screen:scaleBySize(60)
local total_time, total_pages = self:getTotalStats(self.dates)
local total_time, total_pages = self:getTotalStats(#self.dates)
local statistics_container = CenterContainer:new{
dimen = Geom:new{ w = width, h = height },
}

Loading…
Cancel
Save