mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
feat: 扩展 Rust gateway 全功能模块,新增 billing/crypto/wallet crate 及完整数据层
- 新增 aether-billing、aether-crypto、aether-wallet 独立 crate - aether-data 扩展 repository 层:announcements、auth_modules、billing、 candidate_selection、gemini_file_mappings、global_models、management_tokens、 oauth_providers、proxy_nodes、quota、users、wallet 等模块 - aether-gateway 新增 api/auth/billing/control/middleware/scheduler/usage/ video_tasks/hooks/maintenance/model_fetch/provider_transport 等功能模块 - 重构 executor decision 和 gateway state 为模块目录结构 - 新增 gateway router、frontdoor 路由层及对应测试 - Python 侧 API 路由重构,新增 compat/support 模块 - 前端 Logo 组件更新及 Provider 管理页面调整
This commit is contained in:
33
crates/aether-billing/src/precision.rs
Normal file
33
crates/aether-billing/src/precision.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
pub const BILLING_STORAGE_PRECISION: u32 = 8;
|
||||
pub const BILLING_DISPLAY_PRECISION: u32 = 6;
|
||||
|
||||
pub fn quantize_value(value: f64, precision: u32) -> f64 {
|
||||
if !value.is_finite() {
|
||||
return value;
|
||||
}
|
||||
let factor = 10_f64.powi(precision as i32);
|
||||
(value * factor).round() / factor
|
||||
}
|
||||
|
||||
pub fn quantize_cost(value: f64) -> f64 {
|
||||
quantize_value(value, BILLING_STORAGE_PRECISION)
|
||||
}
|
||||
|
||||
pub fn quantize_display(value: f64) -> f64 {
|
||||
quantize_value(value, BILLING_DISPLAY_PRECISION)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{quantize_cost, quantize_display};
|
||||
|
||||
#[test]
|
||||
fn quantizes_cost_to_storage_precision() {
|
||||
assert_eq!(quantize_cost(1.234567891), 1.23456789);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quantizes_display_to_display_precision() {
|
||||
assert_eq!(quantize_display(1.23456789), 1.234568);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user