Anki/rslib/src/backend/stats.rs
Damien Elmes 786eef6d79 Minor Rust cleanups (#2272)
* Run cargo +nightly fmt

* Latest prost-build includes clippy workaround

* Tweak Rust protobuf imports

- Avoid use of stringify!(), as JetBrains editors get confused by it
- Stop merging all protobuf symbols into a single namespace

* Remove some unnecessary qualifications

Found via IntelliJ lint

* Migrate some asserts to assert_eq/ne

* Remove mention of node_modules exclusion

This no longer seems to be necessary after migrating away from Bazel,
and excluding it means TS/Svelte files can't be edited properly.
2022-12-16 21:40:27 +10:00

43 lines
1.6 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use super::Backend;
pub(super) use crate::pb::stats::stats_service::Service as StatsService;
use crate::{pb, prelude::*, revlog::RevlogReviewKind};
impl StatsService for Backend {
fn card_stats(&self, input: pb::cards::CardId) -> Result<pb::stats::CardStatsResponse> {
self.with_col(|col| col.card_stats(input.into()))
}
fn graphs(&self, input: pb::stats::GraphsRequest) -> Result<pb::stats::GraphsResponse> {
self.with_col(|col| col.graph_data_for_search(&input.search, input.days))
}
fn get_graph_preferences(
&self,
_input: pb::generic::Empty,
) -> Result<pb::stats::GraphPreferences> {
self.with_col(|col| Ok(col.get_graph_preferences()))
}
fn set_graph_preferences(
&self,
input: pb::stats::GraphPreferences,
) -> Result<pb::generic::Empty> {
self.with_col(|col| col.set_graph_preferences(input))
.map(Into::into)
}
}
impl From<RevlogReviewKind> for i32 {
fn from(kind: RevlogReviewKind) -> Self {
(match kind {
RevlogReviewKind::Learning => pb::stats::revlog_entry::ReviewKind::Learning,
RevlogReviewKind::Review => pb::stats::revlog_entry::ReviewKind::Review,
RevlogReviewKind::Relearning => pb::stats::revlog_entry::ReviewKind::Relearning,
RevlogReviewKind::Filtered => pb::stats::revlog_entry::ReviewKind::Filtered,
RevlogReviewKind::Manual => pb::stats::revlog_entry::ReviewKind::Manual,
}) as i32
}
}