-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Finished books: freeze history timestamp and statistics #10968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Dunno if it is just me and my bad English, but "Preserve" sounds ambiguous to me. Also, "Preserve (or whatever) finished book timestamp" may feel too technical and a bit vague about what this does. If we don't find a better wording, it needs some |
How about “Freeze timestamp” and “Stop statistics”? |
Freeze sounds good to me. |
plugins/statistics.koplugin/main.lua
Outdated
function ReaderStatistics:isDocless(preserve_finished_books) | ||
return self.ui == nil or self.ui.document == nil or self.ui.document.is_pic == true | ||
or (preserve_finished_books and self.settings.preserve_finished_books | ||
and self.ui.doc_settings:readSetting("summary").status == "complete") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a bit like a quick hack :)
(and ugly in the last chunk of this PR:
if self:isDocless() or not self.settings.is_enabled then return end
if not self:isDocless(true) then...
)
May be the isDocLess() stuff should be remade so it's just a flag, set in :init() or onReadSettings(), and not this whole bunch of checks each time we onPageUpdate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Book status can be changed at any moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so, either:
- you don't care about a change of that status while the book is opened, and keep using its state when it was opened (I'm totally fine with that)
- you send a new Event("BookStatusChanged") and an handler in statistics (is it really worth the work? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what is the profit?
readSetting
costs nothing.
All isDocless(true)
calls will remain in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
costs nothing, but still, a few checks that could be avoided.
return self.ui == nil or self.ui.document == nil or self.ui.document.is_pic == true
ended up like that as we added these checks, and were lazy.
Now it gets added: or (preserve_finished_books and self.settings.preserve_finished_books and self.ui.doc_settings:readSetting("summary").status == "complete")
And It's not any longer true to its name: isDocLess() :)
So, either we keep adding unmeaningful stuff to sometihng related to "Document Less usage", or we rename it to isReallyEnabled() or shouldDoAccounting(), and if we do that, we can as well make it cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid reading all 3 thousands lines, but it is funny from the beginning
koreader/plugins/statistics.koplugin/main.lua
Lines 104 to 108 in 5b5b4d9
function ReaderStatistics:init() | |
-- Disable in PIC documents (but not the FM, as we want to be registered to the FM's menu). | |
if self.ui and self.ui.document and self.ui.document.is_pic then | |
return | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, not necessarily a massive fan of the approach, but agree that the current situation isn't great either.
I was thinking of something like what KOSync (or... something, a few things do that) does, where the handler methods are not enabled by default (i.e., they're declared as Module:_onStuffHappening
), and we have a pair of register/unregisterEventHandlers
methods that either set self.onStuffHappening
to nil
(unregister) or self._onStuffHappening
(register).
This would allow dropping a bit of cruft from that crappy check, and avoid running the handlers at all when disabled.
BTW, about "preserve" koreader/plugins/statistics.koplugin/main.lua Lines 262 to 263 in 5b5b4d9
I'm okay with "Freeze". |
Have no issue with preserve myself, but freeze works for me, too ;). |
It's me who did name that function that way, and I meant it my naive way: "save and keep reusing it" (and not prevent/freeze). Anyway, it's some internal name, not exposed to users.
With that "Freeze" too. |
Fixate timestamp? |
For context on the reaction, that sounds extremely clunky ;). |
Understood 😅 |
Changing status of the currently opened book will not freeze the statistics. Do we need a marker in the Current statistics table indicating the book is frozen? |
Dunno, doesn't feel really needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks better to me this way.
plugins/statistics.koplugin/main.lua
Outdated
self.is_doc_not_freezed = self.is_doc | ||
and (self.is_doc_not_finished or self.settings.freeze_finished_books) | ||
self.settings.freeze_finished_books = not self.settings.freeze_finished_books |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would read easier if you swap the order of these 2 lines (currently, the first line use the previous value of self.settings.freeze_finished_books - I was going to review and say "... or not self.settings.freeze_finished_books")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the first attempt, then swapped to save one not
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarity/readability/obviousness is better than convoluted optimisation :)
Viewing the above screenshot, I would expect to see the date that the book was marked as finished (which, if frozen, might be date of the last inserted statistics) on the right of "Book marked as finished" :/ |
Just "statistics frozen" or "statistics are frozen" btw (not is!) ^_^ |
plugins/statistics.koplugin/main.lua
Outdated
return self.settings.is_enabled and self.is_doc | ||
end | ||
|
||
function ReaderStatistics:isEnabledNotFreezed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Frozen
;). (ditto for the variable)
(I'd possibly add an And
in the middle there, too).
plugins/statistics.koplugin/main.lua
Outdated
@@ -1123,6 +1126,15 @@ The max value ensures a page you stay on for a long time (because you fell aslee | |||
UIManager:show(durations_widget) | |||
end, | |||
keep_menu_open = true, | |||
}, | |||
{ | |||
text = _("Freeze finished books statistics"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze statistics of finished books
sounds ever so slightly better to me, RFC?
plugins/statistics.koplugin/main.lua
Outdated
end | ||
|
||
function ReaderStatistics:onReadSettings(config) | ||
self.data = config:readSetting("stats", {}) | ||
self.data = config:readSetting("stats", { performance_in_pages= {} }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: weird spacing around the =
there ;)
frontend/datetime.lua
Outdated
datetime_string = datetime_string .. " 00:00:00" | ||
end | ||
local year, month, day, hour, min, sec = datetime_string:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)") | ||
local dateTimeTable = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our coding style advises thie kind of casing for methods/functions.
So, best to use underscore for these kind of variable name, ie. datetime_table
or datetime_t
or d
or t
(it is used just after, no real need to have an explicite name - you could even inline it inside os.time(...).
plugins/statistics.koplugin/main.lua
Outdated
estimated_time_left = { _("Book marked as finished"), _("statistics frozen") } | ||
local mark_date = self.ui.doc_settings:readSetting("summary").modified | ||
estimated_finish_date = { _("Book marked as finished"), datetime.secondsToDate(datetime.stringToSeconds(mark_date), true) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to have a different wording for the first one that replaces "Estimated reading time left" and indicates that statistics are frozen.
(Having twice the same key, and additionally each having different values, feels quite odd.)
Not sure about what to write. May be Reading finished statistics frozen
(or Reading marked as finished statistics frozen
but the short one feels more different and better) .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a mild preference over the ever so slightly more explicit Book marked as finished
he went with, Reading finished
doesn't necessarily imply that the book was actually marked as finished, it could be construed as "oh, that happened on its own because I reached the last page" or something ;).
(I mean, you can have books auto-flag as finished on EoB, but that's non-default ;p).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what about the other one I suggested Reading marked as finished statistics frozen
?
(My wish is just to not have twice the same key, and additionally each having different values.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I'd... possibly approach this another way: don't change the key, just the value? The whole thing is opt-in, so I don't think we need to re-explain why statistics are frozen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, I may be confused; lemme check the full context, as I don't rightly recall how this thing even looks like to begin with ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, yeah, I would keep estimated_time_left
's description as-is (i.e., Estimated reading time left
), and just change the "value" to mention something like N/A
and/or stats are frozen
.
I do like the change from Estimated finish date
to Book marked as finished
date, but this one is technically semantically different for both its description and the value, so it makes sense ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screenshots, wording and code looks good to me.
Dispatcher:registerAction("book_statistics", {category="none", event="ShowBookStats", title=_("Book statistics"), reader=true, separator=false}) | ||
Dispatcher:registerAction("stats_sync", {category="none", event="SyncBookStats", title=_("Synchronize book statistics"), reader=true, separator=true}) | ||
Dispatcher:registerAction("stats_calendar_view", {category="none", event="ShowCalendarView", title=_("Statistics calendar view"), general=true}) | ||
Dispatcher:registerAction("stats_calendar_day_view", {category="none", event="ShowCalendarDayView", title=_("Statistics today's timeline"), general=true}) | ||
Dispatcher:registerAction("stats_sync", {category="none", event="SyncBookStats", title=_("Synchronize book statistics"), general=true, separator=true}) | ||
Dispatcher:registerAction("book_statistics", {category="none", event="ShowBookStats", title=_("Book statistics"), reader=true}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the order of registerAction matter ?
Does it impact the order in which they appear in gestures action?
Feels like I'd want all "view stats" item first, and "sync stats" last.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"View stats" is in the Reader section, others - in General.
Too late to avoid the whitespace diff churn, unfortunately ;).
Too late to avoid the whitespace diff churn, unfortunately ;).
Separate settings for History and Statistics.
If enabled in History settings: after opening the finished book will not pop up in History, will not be saved as Last document, will not pop up in the file browser with Sort by last read date.
Doesn't depend on the way of opening (from FM, History, Collections, random book etc.).
Closes #10962.
EDIT: closes #10984.
This change is