mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat: realtime user analytics (#5098)
Co-authored-by: Sampras Lopes <Sampras.lopes@juspay.in>
This commit is contained in:
		| @ -4,6 +4,7 @@ use common_utils::pii::EmailStrategy; | ||||
| use masking::Secret; | ||||
|  | ||||
| use self::{ | ||||
|     active_payments::ActivePaymentsMetrics, | ||||
|     api_event::{ApiEventDimensions, ApiEventMetrics}, | ||||
|     auth_events::AuthEventMetrics, | ||||
|     disputes::{DisputeDimensions, DisputeMetrics}, | ||||
| @ -13,6 +14,7 @@ use self::{ | ||||
| }; | ||||
| pub use crate::payments::TimeRange; | ||||
|  | ||||
| pub mod active_payments; | ||||
| pub mod api_event; | ||||
| pub mod auth_events; | ||||
| pub mod connector_events; | ||||
| @ -151,6 +153,14 @@ pub struct GetAuthEventMetricRequest { | ||||
|     pub delta: bool, | ||||
| } | ||||
|  | ||||
| #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] | ||||
| #[serde(rename_all = "camelCase")] | ||||
| pub struct GetActivePaymentsMetricRequest { | ||||
|     #[serde(default)] | ||||
|     pub metrics: HashSet<ActivePaymentsMetrics>, | ||||
|     pub time_range: TimeRange, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, serde::Serialize)] | ||||
| pub struct AnalyticsMetadata { | ||||
|     pub current_time_range: TimeRange, | ||||
|  | ||||
							
								
								
									
										77
									
								
								crates/api_models/src/analytics/active_payments.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								crates/api_models/src/analytics/active_payments.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,77 @@ | ||||
| use std::{ | ||||
|     collections::hash_map::DefaultHasher, | ||||
|     hash::{Hash, Hasher}, | ||||
| }; | ||||
|  | ||||
| use super::NameDescription; | ||||
|  | ||||
| #[derive( | ||||
|     Clone, | ||||
|     Debug, | ||||
|     Hash, | ||||
|     PartialEq, | ||||
|     Eq, | ||||
|     serde::Serialize, | ||||
|     serde::Deserialize, | ||||
|     strum::Display, | ||||
|     strum::EnumIter, | ||||
|     strum::AsRefStr, | ||||
| )] | ||||
| #[strum(serialize_all = "snake_case")] | ||||
| #[serde(rename_all = "snake_case")] | ||||
| pub enum ActivePaymentsMetrics { | ||||
|     ActivePayments, | ||||
| } | ||||
|  | ||||
| pub mod metric_behaviour { | ||||
|     pub struct ActivePayments; | ||||
| } | ||||
|  | ||||
| impl From<ActivePaymentsMetrics> for NameDescription { | ||||
|     fn from(value: ActivePaymentsMetrics) -> Self { | ||||
|         Self { | ||||
|             name: value.to_string(), | ||||
|             desc: String::new(), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Debug, serde::Serialize, Eq)] | ||||
| pub struct ActivePaymentsMetricsBucketIdentifier { | ||||
|     pub time_bucket: Option<String>, | ||||
| } | ||||
|  | ||||
| impl ActivePaymentsMetricsBucketIdentifier { | ||||
|     pub fn new(time_bucket: Option<String>) -> Self { | ||||
|         Self { time_bucket } | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Hash for ActivePaymentsMetricsBucketIdentifier { | ||||
|     fn hash<H: Hasher>(&self, state: &mut H) { | ||||
|         self.time_bucket.hash(state); | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl PartialEq for ActivePaymentsMetricsBucketIdentifier { | ||||
|     fn eq(&self, other: &Self) -> bool { | ||||
|         let mut left = DefaultHasher::new(); | ||||
|         self.hash(&mut left); | ||||
|         let mut right = DefaultHasher::new(); | ||||
|         other.hash(&mut right); | ||||
|         left.finish() == right.finish() | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Debug, serde::Serialize)] | ||||
| pub struct ActivePaymentsMetricsBucketValue { | ||||
|     pub active_payments: Option<u64>, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, serde::Serialize)] | ||||
| pub struct MetricsBucketResponse { | ||||
|     #[serde(flatten)] | ||||
|     pub values: ActivePaymentsMetricsBucketValue, | ||||
|     #[serde(flatten)] | ||||
|     pub dimensions: ActivePaymentsMetricsBucketIdentifier, | ||||
| } | ||||
| @ -86,6 +86,7 @@ impl_misc_api_event_type!( | ||||
|     GetInfoResponse, | ||||
|     GetPaymentMetricRequest, | ||||
|     GetRefundMetricRequest, | ||||
|     GetActivePaymentsMetricRequest, | ||||
|     GetSdkEventMetricRequest, | ||||
|     GetAuthEventMetricRequest, | ||||
|     GetPaymentFiltersRequest, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Vrishab Srivatsa
					Vrishab Srivatsa