diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-06-18 17:11:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-18 17:11:24 +0100 |
| commit | b8be23ee99f47c89d9c9f4ce508b940efc88b1ca (patch) | |
| tree | ad5ba50590f0cdb11b2ea4540795ced931ee7c30 /ui/backend/src/db.rs | |
| parent | feat(tui): configurable prefix character (#2157) (diff) | |
| download | atuin-b8be23ee99f47c89d9c9f4ce508b940efc88b1ca.zip | |
feat(gui): add activity calendar to the homepage (#2160)
* feat(gui): add activity calendar to the homepage
* localise week start
Diffstat (limited to 'ui/backend/src/db.rs')
| -rw-r--r-- | ui/backend/src/db.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ui/backend/src/db.rs b/ui/backend/src/db.rs index 7e29302a..1015ebf1 100644 --- a/ui/backend/src/db.rs +++ b/ui/backend/src/db.rs @@ -174,6 +174,24 @@ impl HistoryDB { Ok(history) } + pub async fn calendar(&self) -> Result<Vec<(String, u64)>, String> { + let query = "select count(1) as count, strftime('%F', datetime(timestamp / 1000000000, 'unixepoch')) as day from history where timestamp > ((unixepoch() - 31536000) * 1000000000) group by day;"; + + let calendar: Vec<(String, u64)> = sqlx::query(query) + // safe to cast, count(x) is never < 0 + .map(|row: SqliteRow| { + ( + row.get::<String, _>("day"), + row.get::<i64, _>("count") as u64, + ) + }) + .fetch_all(&self.0.pool) + .await + .map_err(|e| e.to_string())?; + + Ok(calendar) + } + pub async fn global_stats(&self) -> Result<GlobalStats, String> { let day_ago = time::OffsetDateTime::now_utc() - time::Duration::days(1); let day_ago = day_ago.unix_timestamp_nanos(); |
