datasynth_core/models/management_kpi.rs
1//! Management KPI models for executive dashboards and reporting.
2//!
3//! These models represent key performance indicators tracked by management,
4//! supporting period-over-period comparison and trend analysis.
5
6use chrono::NaiveDate;
7use rust_decimal::Decimal;
8use serde::{Deserialize, Serialize};
9
10/// Category of a management KPI.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
12#[serde(rename_all = "snake_case")]
13pub enum KpiCategory {
14 /// Financial metrics (revenue, margin, EBITDA, etc.)
15 #[default]
16 Financial,
17 /// Operational metrics (throughput, cycle time, utilization, etc.)
18 Operational,
19 /// Customer metrics (NPS, retention, acquisition cost, etc.)
20 Customer,
21 /// Employee metrics (headcount, turnover, engagement, etc.)
22 Employee,
23 /// Quality metrics (defect rate, compliance, SLA adherence, etc.)
24 Quality,
25}
26
27/// Trend direction for a KPI relative to prior periods.
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
29#[serde(rename_all = "snake_case")]
30pub enum KpiTrend {
31 /// KPI is moving in a favorable direction
32 #[default]
33 Improving,
34 /// KPI is holding steady
35 Stable,
36 /// KPI is moving in an unfavorable direction
37 Declining,
38}
39
40/// A management key performance indicator for a given period.
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct ManagementKpi {
43 /// Unique KPI identifier
44 pub kpi_id: String,
45 /// Company code this KPI belongs to
46 pub company_code: String,
47 /// Human-readable name of the KPI (e.g., "Gross Margin")
48 pub name: String,
49 /// Category of the KPI
50 pub category: KpiCategory,
51 /// Start of the measurement period
52 pub period_start: NaiveDate,
53 /// End of the measurement period
54 pub period_end: NaiveDate,
55 /// Actual measured value for the period
56 #[serde(with = "rust_decimal::serde::str")]
57 pub value: Decimal,
58 /// Target value for the period
59 #[serde(with = "rust_decimal::serde::str")]
60 pub target: Decimal,
61 /// Unit of measure (e.g., "%", "days", "USD")
62 pub unit: String,
63 /// Trend direction relative to prior periods
64 pub trend: KpiTrend,
65 /// Year-over-year percentage change (e.g., 0.05 = +5%)
66 pub year_over_year_change: Option<f64>,
67 /// Value from the prior period for comparison
68 #[serde(default, with = "rust_decimal::serde::str_option")]
69 pub prior_period_value: Option<Decimal>,
70}