pub struct Analytics { /* private fields */ }Expand description
Analytics operations interface.
Provides sales analytics, inventory forecasting, and business intelligence.
§Example
use stateset_embedded::{Commerce, AnalyticsQuery, TimePeriod};
let commerce = Commerce::new("./store.db")?;
// Get sales summary for last 30 days
let summary = commerce.analytics().sales_summary(
AnalyticsQuery::new().period(TimePeriod::Last30Days)
)?;
println!("Revenue: ${}", summary.total_revenue);
// Get top selling products
let top_products = commerce.analytics().top_products(
AnalyticsQuery::new().period(TimePeriod::ThisMonth).limit(10)
)?;
// Get demand forecast
let forecasts = commerce.analytics().demand_forecast(None, 30)?;Implementations§
Source§impl Analytics
impl Analytics
Sourcepub fn sales_summary(&self, query: AnalyticsQuery) -> Result<SalesSummary>
pub fn sales_summary(&self, query: AnalyticsQuery) -> Result<SalesSummary>
Get sales summary for a time period.
Returns total revenue, order count, average order value, and more.
§Example
let summary = commerce.analytics().sales_summary(
AnalyticsQuery::new().period(TimePeriod::Last30Days)
)?;
println!("Revenue: ${}", summary.total_revenue);
println!("Orders: {}", summary.order_count);
println!("AOV: ${}", summary.average_order_value);Sourcepub fn revenue_by_period(
&self,
query: AnalyticsQuery,
) -> Result<Vec<RevenueByPeriod>>
pub fn revenue_by_period( &self, query: AnalyticsQuery, ) -> Result<Vec<RevenueByPeriod>>
Get revenue broken down by time periods.
§Example
let revenue = commerce.analytics().revenue_by_period(
AnalyticsQuery::new()
.period(TimePeriod::Last30Days)
.granularity(TimeGranularity::Day)
)?;
for day in revenue {
println!("{}: ${}", day.period, day.revenue);
}Sourcepub fn top_products(&self, query: AnalyticsQuery) -> Result<Vec<TopProduct>>
pub fn top_products(&self, query: AnalyticsQuery) -> Result<Vec<TopProduct>>
Get top selling products.
§Example
let top = commerce.analytics().top_products(
AnalyticsQuery::new()
.period(TimePeriod::ThisMonth)
.limit(10)
)?;
for product in top {
println!("{}: {} units, ${}", product.name, product.units_sold, product.revenue);
}Sourcepub fn product_performance(
&self,
query: AnalyticsQuery,
) -> Result<Vec<ProductPerformance>>
pub fn product_performance( &self, query: AnalyticsQuery, ) -> Result<Vec<ProductPerformance>>
Get product performance with period comparison.
Sourcepub fn customer_metrics(&self, query: AnalyticsQuery) -> Result<CustomerMetrics>
pub fn customer_metrics(&self, query: AnalyticsQuery) -> Result<CustomerMetrics>
Get customer metrics.
§Example
let metrics = commerce.analytics().customer_metrics(
AnalyticsQuery::new().period(TimePeriod::ThisMonth)
)?;
println!("Total customers: {}", metrics.total_customers);
println!("New this month: {}", metrics.new_customers);
println!("Avg LTV: ${}", metrics.average_lifetime_value);Sourcepub fn top_customers(&self, query: AnalyticsQuery) -> Result<Vec<TopCustomer>>
pub fn top_customers(&self, query: AnalyticsQuery) -> Result<Vec<TopCustomer>>
Get top customers by spend.
§Example
let top = commerce.analytics().top_customers(
AnalyticsQuery::new().period(TimePeriod::AllTime).limit(10)
)?;
for customer in top {
println!("{}: {} orders, ${}", customer.name, customer.order_count, customer.total_spent);
}Sourcepub fn inventory_health(&self) -> Result<InventoryHealth>
pub fn inventory_health(&self) -> Result<InventoryHealth>
Get inventory health summary.
§Example
let health = commerce.analytics().inventory_health()?;
println!("Total SKUs: {}", health.total_skus);
println!("Low stock: {}", health.low_stock_skus);
println!("Out of stock: {}", health.out_of_stock_skus);Sourcepub fn low_stock_items(
&self,
threshold: Option<Decimal>,
) -> Result<Vec<LowStockItem>>
pub fn low_stock_items( &self, threshold: Option<Decimal>, ) -> Result<Vec<LowStockItem>>
Get low stock items.
§Example
let low_stock = commerce.analytics().low_stock_items(Some(dec!(20)))?;
for item in low_stock {
println!("{}: {} available", item.sku, item.available);
}Sourcepub fn inventory_movement(
&self,
query: AnalyticsQuery,
) -> Result<Vec<InventoryMovement>>
pub fn inventory_movement( &self, query: AnalyticsQuery, ) -> Result<Vec<InventoryMovement>>
Get inventory movement summary.
Sourcepub fn order_status_breakdown(
&self,
query: AnalyticsQuery,
) -> Result<OrderStatusBreakdown>
pub fn order_status_breakdown( &self, query: AnalyticsQuery, ) -> Result<OrderStatusBreakdown>
Get order status breakdown.
§Example
let breakdown = commerce.analytics().order_status_breakdown(
AnalyticsQuery::new().period(TimePeriod::Last30Days)
)?;
println!("Pending: {}", breakdown.pending);
println!("Shipped: {}", breakdown.shipped);
println!("Delivered: {}", breakdown.delivered);Sourcepub fn fulfillment_metrics(
&self,
query: AnalyticsQuery,
) -> Result<FulfillmentMetrics>
pub fn fulfillment_metrics( &self, query: AnalyticsQuery, ) -> Result<FulfillmentMetrics>
Get fulfillment metrics.
Sourcepub fn return_metrics(&self, query: AnalyticsQuery) -> Result<ReturnMetrics>
pub fn return_metrics(&self, query: AnalyticsQuery) -> Result<ReturnMetrics>
Get return metrics.
§Example
let metrics = commerce.analytics().return_metrics(
AnalyticsQuery::new().period(TimePeriod::ThisMonth)
)?;
println!("Returns: {}", metrics.total_returns);
println!("Return rate: {}%", metrics.return_rate_percent);Sourcepub fn demand_forecast(
&self,
skus: Option<Vec<String>>,
days_ahead: u32,
) -> Result<Vec<DemandForecast>>
pub fn demand_forecast( &self, skus: Option<Vec<String>>, days_ahead: u32, ) -> Result<Vec<DemandForecast>>
Get demand forecast for inventory items.
Predicts future demand based on historical sales data.
§Arguments
skus- Optional list of SKUs to forecast. If None, forecasts all items.days_ahead- Number of days to forecast ahead.
§Example
// Forecast for all items
let forecasts = commerce.analytics().demand_forecast(None, 30)?;
for f in forecasts {
println!("{}: {} units/day, {} days until stockout",
f.sku,
f.average_daily_demand,
f.days_until_stockout.unwrap_or(999)
);
}
// Forecast for specific SKUs
let forecasts = commerce.analytics().demand_forecast(
Some(vec!["SKU-001".to_string(), "SKU-002".to_string()]),
14
)?;Sourcepub fn revenue_forecast(
&self,
periods_ahead: u32,
granularity: TimeGranularity,
) -> Result<Vec<RevenueForecast>>
pub fn revenue_forecast( &self, periods_ahead: u32, granularity: TimeGranularity, ) -> Result<Vec<RevenueForecast>>
Get revenue forecast.
Predicts future revenue based on historical trends.
§Arguments
periods_ahead- Number of periods to forecast.granularity- Time granularity (Day, Week, Month).
§Example
let forecasts = commerce.analytics().revenue_forecast(3, TimeGranularity::Month)?;
for f in forecasts {
println!("{}: ${} (${} - ${})",
f.period,
f.forecasted_revenue,
f.lower_bound,
f.upper_bound
);
}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Analytics
impl !UnwindSafe for Analytics
impl Freeze for Analytics
impl Send for Analytics
impl Sync for Analytics
impl Unpin for Analytics
impl UnsafeUnpin for Analytics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more