From f00211df359f8214e9e97688776876a724f59266 Mon Sep 17 00:00:00 2001 From: Jarrett Ye Date: Sat, 12 Oct 2024 12:49:14 +0800 Subject: [PATCH] add get_revlogs API && fix the style of tooltipText of ReviewsGraph (#3490) * add get_revlogs API * fix tooltipText of ReviewsGraph the style of true-retention shouldn't affect the style of tooltipText of ReviewsGraph * More verbose wording (dae) --- proto/anki/stats.proto | 5 +++++ pylib/anki/collection.py | 5 +++++ qt/aqt/mediasrv.py | 1 + rslib/src/stats/card.rs | 7 +++++++ rslib/src/stats/service.rs | 7 +++++++ ts/routes/graphs/true-retention.ts | 4 ++-- 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/proto/anki/stats.proto b/proto/anki/stats.proto index db4a426eb..4ef811df9 100644 --- a/proto/anki/stats.proto +++ b/proto/anki/stats.proto @@ -12,6 +12,7 @@ import "anki/cards.proto"; service StatsService { rpc CardStats(cards.CardId) returns (CardStatsResponse); + rpc GetReviewLogs(cards.CardId) returns (ReviewLogs); rpc Graphs(GraphsRequest) returns (GraphsResponse); rpc GetGraphPreferences(generic.Empty) returns (GraphPreferences); rpc SetGraphPreferences(GraphPreferences) returns (generic.Empty); @@ -21,6 +22,10 @@ service StatsService { // backend service. service BackendStatsService {} +message ReviewLogs { + repeated CardStatsResponse.StatsRevlogEntry entries = 1; +} + message CardStatsResponse { message StatsRevlogEntry { int64 time = 1; diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index ae5caa050..27c01e0e1 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -1004,6 +1004,11 @@ class Collection(DeprecatedNamesMixin): """ return self._backend.card_stats(card_id) + def get_review_logs( + self, card_id: CardId + ) -> Sequence[stats_pb2.CardStatsResponse.StatsRevlogEntry]: + return self._backend.get_review_logs(card_id) + def studied_today(self) -> str: return self._backend.studied_today() diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index c866ae423..26e52f503 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -608,6 +608,7 @@ exposed_backend_list = [ "get_change_notetype_info", # StatsService "card_stats", + "get_review_logs", "graphs", "get_graph_preferences", "set_graph_preferences", diff --git a/rslib/src/stats/card.rs b/rslib/src/stats/card.rs index 3bd6eb3e9..b5da86d2b 100644 --- a/rslib/src/stats/card.rs +++ b/rslib/src/stats/card.rs @@ -83,6 +83,13 @@ impl Collection { }) } + pub fn get_review_logs(&mut self, cid: CardId) -> Result { + let revlogs = self.storage.get_revlog_entries_for_card(cid)?; + Ok(anki_proto::stats::ReviewLogs { + entries: revlogs.iter().rev().map(stats_revlog_entry).collect(), + }) + } + fn due_date(&mut self, card: &Card) -> Result> { Ok(match card.ctype { CardType::New => None, diff --git a/rslib/src/stats/service.rs b/rslib/src/stats/service.rs index e7b208724..2611ae0bf 100644 --- a/rslib/src/stats/service.rs +++ b/rslib/src/stats/service.rs @@ -12,6 +12,13 @@ impl crate::services::StatsService for Collection { self.card_stats(input.cid.into()) } + fn get_review_logs( + &mut self, + input: anki_proto::cards::CardId, + ) -> error::Result { + self.get_review_logs(input.cid.into()) + } + fn graphs( &mut self, input: anki_proto::stats::GraphsRequest, diff --git a/ts/routes/graphs/true-retention.ts b/ts/routes/graphs/true-retention.ts index 91d2e75f0..964a32efc 100644 --- a/ts/routes/graphs/true-retention.ts +++ b/ts/routes/graphs/true-retention.ts @@ -65,10 +65,10 @@ export function renderTrueRetention(data: GraphsResponse, revlogRange: RevlogRan td.trl { border: 1px solid; text-align: left; } td.trr { border: 1px solid; text-align: right; } td.trc { border: 1px solid; text-align: center; } - table { width: 100%; table-layout: fixed; } + table.true-retention { width: 100%; table-layout: fixed; } colgroup col:first-child { width: 40% } - +
${scopeRange(scope)}