AnalyticsService

Struct AnalyticsService 

Source
pub struct AnalyticsService { /* private fields */ }
Expand description

Analytics service for dashboard metrics

Implementations§

Source§

impl AnalyticsService

Source

pub fn new(pool: PgPool) -> Self

Create a new analytics service

Source

pub async fn create_materialized_views(&self) -> Result<()>

Create all materialized views

Source

pub async fn refresh_all_views(&self) -> Result<()>

Refresh all materialized views

Source

pub async fn get_dashboard_metrics(&self) -> Result<DashboardMetrics>

Get dashboard metrics (from materialized view if available, otherwise compute)

Source

pub async fn compute_dashboard_metrics(&self) -> Result<DashboardMetrics>

Compute dashboard metrics directly (without materialized view)

Source

pub async fn get_top_tokens( &self, limit: i64, ) -> Result<Vec<TokenMetricsSummary>>

Get token metrics (top tokens by volume)

Source

pub async fn get_daily_stats( &self, start_date: NaiveDate, end_date: NaiveDate, ) -> Result<Vec<DailyStats>>

Get daily statistics for a date range

Source

pub async fn get_top_users( &self, limit: i64, ) -> Result<Vec<UserActivitySummary>>

Get top users by trading volume

Source

pub async fn drop_materialized_views(&self) -> Result<()>

Drop all materialized views

Source

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).

Source

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.

Source

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

Source

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

Source

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

Source

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.

Source

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

Source

pub async fn get_platform_volume_history( &self, start_time: DateTime<Utc>, end_time: DateTime<Utc>, ) -> Result<Vec<PlatformVolumeHistory>>

Get platform-wide volume history

Source

pub async fn is_timescaledb_available(&self) -> bool

Check if TimescaleDB extension is available

Source

pub async fn get_hypertable_info( &self, table_name: &str, ) -> Result<Option<String>>

Get hypertable information (only works with TimescaleDB)

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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