Skip to content

Commit

Permalink
feat: move starts stats to DailyStats
Browse files Browse the repository at this point in the history
  • Loading branch information
jooooscha committed Nov 29, 2022
1 parent ba81b70 commit 43e4718
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/backend/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,15 @@ pub fn draw(app: AppState) {


let stats = app.history.stats();
let starts = match stats.today() {
Some(stats) => stats.starts,
None => 0,
};
let videos = match stats.today() {
Some(stats) => stats.watched,
None => 0
};
let info = Paragraph::new(Span::from(format!("{} - Videos Today: {} - Starts: {}", INFO_LINE, videos, stats.starts)))
let info = Paragraph::new(Span::from(format!("{} - Videos Today: {} - Starts: {}", INFO_LINE, videos, starts)))
.style(Style::default())
.alignment(Alignment::Left);

Expand Down
2 changes: 1 addition & 1 deletion src/backend/io/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl History {
}

pub(crate) fn add_start(&mut self) {
self.stats.starts += 1;
self.stats.add_start();
self.save();
}

Expand Down
6 changes: 2 additions & 4 deletions src/backend/io/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use crate::backend::data::video::Video;
/// Statistics collected in total
#[derive(Clone, Deserialize, Serialize, Default)]
pub(crate) struct Stats {
pub starts: usize,
pub per_day: HashMap<NaiveDate, DailyStats>,
}

/// Statistics collected per day
#[derive(Clone, Deserialize, Serialize, Default)]
pub(crate) struct DailyStats {
pub starts: usize,
pub watched: usize,
pub channels: HashMap<String, usize>,
}
Expand Down Expand Up @@ -41,11 +41,9 @@ impl Stats {
}

pub fn add_start(&mut self) {
self.starts += 1;
self.today_mut().starts += 1;
}



// pub(crate) fn stat_today(&self) -> Option<&Stats> {
// let now: NaiveDate = Local::now().date_naive();
// self.stats.get(&now)
Expand Down

0 comments on commit 43e4718

Please sign in to comment.