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)
This commit is contained in:
Jarrett Ye 2024-10-12 12:49:14 +08:00 committed by GitHub
parent aaf4994e6f
commit f00211df35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 27 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import "anki/cards.proto";
service StatsService { service StatsService {
rpc CardStats(cards.CardId) returns (CardStatsResponse); rpc CardStats(cards.CardId) returns (CardStatsResponse);
rpc GetReviewLogs(cards.CardId) returns (ReviewLogs);
rpc Graphs(GraphsRequest) returns (GraphsResponse); rpc Graphs(GraphsRequest) returns (GraphsResponse);
rpc GetGraphPreferences(generic.Empty) returns (GraphPreferences); rpc GetGraphPreferences(generic.Empty) returns (GraphPreferences);
rpc SetGraphPreferences(GraphPreferences) returns (generic.Empty); rpc SetGraphPreferences(GraphPreferences) returns (generic.Empty);
@ -21,6 +22,10 @@ service StatsService {
// backend service. // backend service.
service BackendStatsService {} service BackendStatsService {}
message ReviewLogs {
repeated CardStatsResponse.StatsRevlogEntry entries = 1;
}
message CardStatsResponse { message CardStatsResponse {
message StatsRevlogEntry { message StatsRevlogEntry {
int64 time = 1; int64 time = 1;

View file

@ -1004,6 +1004,11 @@ class Collection(DeprecatedNamesMixin):
""" """
return self._backend.card_stats(card_id) 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: def studied_today(self) -> str:
return self._backend.studied_today() return self._backend.studied_today()

View file

@ -608,6 +608,7 @@ exposed_backend_list = [
"get_change_notetype_info", "get_change_notetype_info",
# StatsService # StatsService
"card_stats", "card_stats",
"get_review_logs",
"graphs", "graphs",
"get_graph_preferences", "get_graph_preferences",
"set_graph_preferences", "set_graph_preferences",

View file

@ -83,6 +83,13 @@ impl Collection {
}) })
} }
pub fn get_review_logs(&mut self, cid: CardId) -> Result<anki_proto::stats::ReviewLogs> {
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<Option<i64>> { fn due_date(&mut self, card: &Card) -> Result<Option<i64>> {
Ok(match card.ctype { Ok(match card.ctype {
CardType::New => None, CardType::New => None,

View file

@ -12,6 +12,13 @@ impl crate::services::StatsService for Collection {
self.card_stats(input.cid.into()) self.card_stats(input.cid.into())
} }
fn get_review_logs(
&mut self,
input: anki_proto::cards::CardId,
) -> error::Result<anki_proto::stats::ReviewLogs> {
self.get_review_logs(input.cid.into())
}
fn graphs( fn graphs(
&mut self, &mut self,
input: anki_proto::stats::GraphsRequest, input: anki_proto::stats::GraphsRequest,

View file

@ -65,10 +65,10 @@ export function renderTrueRetention(data: GraphsResponse, revlogRange: RevlogRan
td.trl { border: 1px solid; text-align: left; } td.trl { border: 1px solid; text-align: left; }
td.trr { border: 1px solid; text-align: right; } td.trr { border: 1px solid; text-align: right; }
td.trc { border: 1px solid; text-align: center; } 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% } colgroup col:first-child { width: 40% }
</style> </style>
<table cellspacing="0" cellpadding="2"> <table class="true-retention" cellspacing="0" cellpadding="2">
<colgroup><col><col><col></colgroup> <colgroup><col><col><col></colgroup>
<tr> <tr>
<td class="trl"><b>${scopeRange(scope)}</b></td> <td class="trl"><b>${scopeRange(scope)}</b></td>