pub struct AnalyticsService { /* private fields */ }Expand description
Analytics service for dashboard metrics
Implementations§
Source§impl AnalyticsService
impl AnalyticsService
Sourcepub async fn create_materialized_views(&self) -> Result<()>
pub async fn create_materialized_views(&self) -> Result<()>
Create all materialized views
Sourcepub async fn refresh_all_views(&self) -> Result<()>
pub async fn refresh_all_views(&self) -> Result<()>
Refresh all materialized views
Sourcepub async fn get_dashboard_metrics(&self) -> Result<DashboardMetrics>
pub async fn get_dashboard_metrics(&self) -> Result<DashboardMetrics>
Get dashboard metrics (from materialized view if available, otherwise compute)
Sourcepub async fn compute_dashboard_metrics(&self) -> Result<DashboardMetrics>
pub async fn compute_dashboard_metrics(&self) -> Result<DashboardMetrics>
Compute dashboard metrics directly (without materialized view)
Sourcepub async fn get_top_tokens(
&self,
limit: i64,
) -> Result<Vec<TokenMetricsSummary>>
pub async fn get_top_tokens( &self, limit: i64, ) -> Result<Vec<TokenMetricsSummary>>
Get token metrics (top tokens by volume)
Sourcepub async fn get_daily_stats(
&self,
start_date: NaiveDate,
end_date: NaiveDate,
) -> Result<Vec<DailyStats>>
pub async fn get_daily_stats( &self, start_date: NaiveDate, end_date: NaiveDate, ) -> Result<Vec<DailyStats>>
Get daily statistics for a date range
Sourcepub async fn get_top_users(
&self,
limit: i64,
) -> Result<Vec<UserActivitySummary>>
pub async fn get_top_users( &self, limit: i64, ) -> Result<Vec<UserActivitySummary>>
Get top users by trading volume
Sourcepub async fn drop_materialized_views(&self) -> Result<()>
pub async fn drop_materialized_views(&self) -> Result<()>
Drop all materialized views
Sourcepub async fn record_price_history(
&self,
token_id: Uuid,
price_satoshis: i64,
supply: i64,
) -> Result<()>
pub async fn record_price_history( &self, token_id: Uuid, price_satoshis: i64, supply: i64, ) -> Result<()>
Record price history data point
Inserts a price history record into the TimescaleDB hypertable. Safe to call even if TimescaleDB is not installed (uses regular table).
Sourcepub async fn record_volume_history(
&self,
token_id: Uuid,
buy_volume_satoshis: i64,
sell_volume_satoshis: i64,
trade_count: i32,
unique_traders: i32,
) -> Result<()>
pub async fn record_volume_history( &self, token_id: Uuid, buy_volume_satoshis: i64, sell_volume_satoshis: i64, trade_count: i32, unique_traders: i32, ) -> Result<()>
Record volume history data point
Inserts or updates a volume history record for a specific time bucket. Typically called on trade execution to update the current hour’s volume.
Sourcepub async fn record_platform_volume(
&self,
total_volume_satoshis: i64,
trade_count: i32,
active_tokens: i32,
active_traders: i32,
fees_collected_satoshis: i64,
) -> Result<()>
pub async fn record_platform_volume( &self, total_volume_satoshis: i64, trade_count: i32, active_tokens: i32, active_traders: i32, fees_collected_satoshis: i64, ) -> Result<()>
Record platform-wide volume history
Sourcepub async fn get_price_history(
&self,
token_id: Uuid,
start_time: DateTime<Utc>,
end_time: DateTime<Utc>,
) -> Result<Vec<PriceHistory>>
pub async fn get_price_history( &self, token_id: Uuid, start_time: DateTime<Utc>, end_time: DateTime<Utc>, ) -> Result<Vec<PriceHistory>>
Get price history for a token within a time range
Sourcepub async fn get_volume_history(
&self,
token_id: Uuid,
start_time: DateTime<Utc>,
end_time: DateTime<Utc>,
) -> Result<Vec<VolumeHistory>>
pub async fn get_volume_history( &self, token_id: Uuid, start_time: DateTime<Utc>, end_time: DateTime<Utc>, ) -> Result<Vec<VolumeHistory>>
Get volume history for a token within a time range
Sourcepub async fn get_ohlc_data(
&self,
token_id: Uuid,
start_time: DateTime<Utc>,
end_time: DateTime<Utc>,
bucket_interval: &str,
) -> Result<Vec<OhlcData>>
pub async fn get_ohlc_data( &self, token_id: Uuid, start_time: DateTime<Utc>, end_time: DateTime<Utc>, bucket_interval: &str, ) -> Result<Vec<OhlcData>>
Get OHLC (candlestick) data for a token
Returns OHLC data with configurable time buckets (e.g., ‘1 hour’, ‘1 day’, ‘1 week’). Uses TimescaleDB’s continuous aggregate if available, otherwise computes from raw data.
Sourcepub async fn get_aggregated_volume(
&self,
token_id: Option<Uuid>,
start_time: DateTime<Utc>,
end_time: DateTime<Utc>,
bucket_interval: &str,
) -> Result<Vec<VolumeHistory>>
pub async fn get_aggregated_volume( &self, token_id: Option<Uuid>, start_time: DateTime<Utc>, end_time: DateTime<Utc>, bucket_interval: &str, ) -> Result<Vec<VolumeHistory>>
Get aggregated volume data by time bucket
Sourcepub async fn get_platform_volume_history(
&self,
start_time: DateTime<Utc>,
end_time: DateTime<Utc>,
) -> Result<Vec<PlatformVolumeHistory>>
pub async fn get_platform_volume_history( &self, start_time: DateTime<Utc>, end_time: DateTime<Utc>, ) -> Result<Vec<PlatformVolumeHistory>>
Get platform-wide volume history
Sourcepub async fn is_timescaledb_available(&self) -> bool
pub async fn is_timescaledb_available(&self) -> bool
Check if TimescaleDB extension is available
Auto Trait Implementations§
impl Freeze for AnalyticsService
impl !RefUnwindSafe for AnalyticsService
impl Send for AnalyticsService
impl Sync for AnalyticsService
impl Unpin for AnalyticsService
impl !UnwindSafe for AnalyticsService
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more