Skip to main content

Analytics

Struct Analytics 

Source
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

Source

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);
Source

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);
}
Source

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);
}
Source

pub fn product_performance( &self, query: AnalyticsQuery, ) -> Result<Vec<ProductPerformance>>

Get product performance with period comparison.

Source

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);
Source

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);
}
Source

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);
Source

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);
}
Source

pub fn inventory_movement( &self, query: AnalyticsQuery, ) -> Result<Vec<InventoryMovement>>

Get inventory movement summary.

Source

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);
Source

pub fn fulfillment_metrics( &self, query: AnalyticsQuery, ) -> Result<FulfillmentMetrics>

Get fulfillment metrics.

Source

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);
Source

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
)?;
Source

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§

Source§

impl Debug for Analytics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more