tempo_cli/models/
insight.rs

1use chrono::{DateTime, NaiveDate, Utc};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct ProductivityInsight {
6    pub id: Option<i64>,
7    pub project_id: Option<i64>,
8    pub insight_type: InsightType,
9    pub period_start: NaiveDate,
10    pub period_end: NaiveDate,
11    pub data: InsightData,
12    pub calculated_at: DateTime<Utc>,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
16pub enum InsightType {
17    Daily,
18    Weekly,
19    Monthly,
20    ProjectSummary,
21}
22
23impl std::fmt::Display for InsightType {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            InsightType::Daily => write!(f, "daily"),
27            InsightType::Weekly => write!(f, "weekly"),
28            InsightType::Monthly => write!(f, "monthly"),
29            InsightType::ProjectSummary => write!(f, "project_summary"),
30        }
31    }
32}
33
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35pub struct InsightData {
36    pub total_hours: f64,
37    pub sessions_count: i64,
38    pub avg_session_duration: f64,
39    pub most_active_day: Option<String>,
40    pub most_active_time: Option<String>,
41    pub productivity_score: Option<f64>,
42    pub project_breakdown: Vec<ProjectBreakdown>,
43    pub trends: Vec<TrendPoint>,
44}
45
46#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47pub struct ProjectBreakdown {
48    pub project_id: i64,
49    pub project_name: String,
50    pub hours: f64,
51    pub percentage: f64,
52}
53
54#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
55pub struct TrendPoint {
56    pub date: NaiveDate,
57    pub hours: f64,
58    pub sessions: i64,
59}
60
61#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
62pub struct TeamInsight {
63    pub id: Option<i64>,
64    pub workspace_id: Option<i64>,
65    pub team_member: String,
66    pub period_start: NaiveDate,
67    pub period_end: NaiveDate,
68    pub total_hours: f64,
69    pub project_breakdown: Vec<ProjectBreakdown>,
70    pub productivity_score: Option<f64>,
71    pub calculated_at: DateTime<Utc>,
72}
73
74impl ProductivityInsight {
75    pub fn new(
76        insight_type: InsightType,
77        period_start: NaiveDate,
78        period_end: NaiveDate,
79        data: InsightData,
80    ) -> Self {
81        Self {
82            id: None,
83            project_id: None,
84            insight_type,
85            period_start,
86            period_end,
87            data,
88            calculated_at: Utc::now(),
89        }
90    }
91}