App is building
This commit is contained in:
1 parent
7e1bb4bc22
commit
f9c4bf9c03
5 files changed
+108
-94
No files matched your search
+28
-2
@@ -1,6 +1,6 @@
|
||||
use crate::core::srs::{FADE_PER_DAY, MAX_SCORE, WordOpenMode};
|
||||
use crate::data::{INVALID_ID, Id};
|
||||
use chrono::{DateTime, NaiveDate, Utc};
|
||||
use chrono::{DateTime, Local, NaiveDate, Utc};
|
||||
use fsrs::MemoryState;
|
||||
use litemap::LiteMap;
|
||||
use log::info;
|
||||
@@ -8,7 +8,9 @@ use rhai::Engine;
|
||||
use std::cmp::Ordering;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use crate::data_provider::history::{HistoryRepository, HistoryRepositoryInner};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WordData {
|
||||
@@ -63,7 +65,7 @@ impl WordData {
|
||||
pub struct HistoryNote {
|
||||
pub id: Id,
|
||||
pub timestamp: DateTime<Utc>,
|
||||
pub set_id: Id,
|
||||
pub deck_id: Id,
|
||||
pub word_id: Id,
|
||||
pub answer: WordOpenMode,
|
||||
pub before: u8,
|
||||
@@ -81,6 +83,30 @@ impl EntityData for HistoryNote {
|
||||
}
|
||||
}
|
||||
|
||||
impl HistoryRepositoryInner {
|
||||
pub fn activity_of_deck(&self, id: Id) -> Vec<(NaiveDate, u32)> {
|
||||
let mut query = self.query(Arc::new(move |note| note.deck_id == id));
|
||||
let values = query.iter(&self).collect::<Vec<_>>();
|
||||
let mut counts = vec![];
|
||||
if !values.is_empty() {
|
||||
let mut date = values[0].timestamp.with_timezone(&Local).date_naive();
|
||||
let mut count = 0;
|
||||
for note in values {
|
||||
let current_date = note.timestamp.with_timezone(&Local).date_naive();
|
||||
if date == current_date{
|
||||
count += 1;
|
||||
}
|
||||
else {
|
||||
counts.push((date, count));
|
||||
date = current_date;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
counts
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DeckSettings {
|
||||
pub id: Id,
|
||||
|
||||
Reference in new issue
Block a user