mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add account analytics data normalization to the TUI (#45740)
## What changed Add display models and adapters from typed backend responses for usage, credits, messages, plugins, and skills. Normalize reports into daily histories with grouping labels, units, and freshness timestamps. Preserve missing values, signed credit adjustments, and full daily totals when grouping usage by task start. Account for unassigned message counts as `Other`, merge duplicate dates, and fill unreported days only for credit reports. Group models contributing less than 1% of relative usage into `Other`. This adds the data preparation layer for dashboard integration; it is not yet connected to `/usage`. ## Testing Add unit tests covering missing versus explicit zero values, signed credits, enterprise labels and freshness, usage grouping, duplicate-date message remainders, and unsupported message groupings. GitOrigin-RevId: 931f46a9a6521b4cda2fc26051e7a305cbf6fa6c
This commit is contained in:
1 parent
ab3b40c28b
commit
1fd5399004
9 files changed
+1084
No files matched your search
@@ -0,0 +1,52 @@
|
||||
//! Private analytics display types, independent of the app-server wire protocol.
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum AccountAnalyticsReport {
|
||||
Usage,
|
||||
Credits,
|
||||
Messages,
|
||||
Plugins,
|
||||
Skills,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum AccountAnalyticsGrouping {
|
||||
Feature,
|
||||
Model,
|
||||
Surface,
|
||||
TaskStart,
|
||||
Speed,
|
||||
Reasoning,
|
||||
TokenType,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum AccountAnalyticsUnit {
|
||||
RelativeUsage,
|
||||
Credits,
|
||||
Count,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) struct AccountAnalyticsHistory {
|
||||
pub(crate) unit: AccountAnalyticsUnit,
|
||||
/// Source freshness in Unix seconds, when provided. Not a completeness watermark.
|
||||
pub(crate) updated_at: Option<i64>,
|
||||
pub(crate) data: Vec<AccountAnalyticsDay>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) struct AccountAnalyticsDay {
|
||||
/// Source reporting date; display formatting belongs to the UI.
|
||||
pub(crate) date: chrono::NaiveDate,
|
||||
/// Full daily denominator, including non-task usage when grouped by task start.
|
||||
pub(crate) total: f64,
|
||||
pub(crate) values: Vec<AccountAnalyticsValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) struct AccountAnalyticsValue {
|
||||
pub(crate) key: String,
|
||||
pub(crate) label: String,
|
||||
pub(crate) value: f64,
|
||||
}
|
||||
Reference in new issue
Block a user