Skip to content

Commit

Permalink
fmt & check
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspb committed Feb 22, 2024
1 parent ac13fd5 commit 7bc6e56
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ FROM
LEFT JOIN
bi_customer_ytd_summary bi ON bi.customer_id = c.id
WHERE c.tenant_id = :tenant_id
AND (bi.revenue_year IS NULL OR bi.currency = :currency)
AND (bi.revenue_year IS NULL OR bi.revenue_year >= DATE_PART('year', CURRENT_DATE))
ORDER BY
total_revenue_cents DESC
Expand Down
31 changes: 15 additions & 16 deletions modules/meteroid/crates/meteroid-repository/src/cornucopia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9490,9 +9490,10 @@ GROUP BY
pub currency: T2,
pub tenant_id: uuid::Uuid,
}
#[derive(Clone, Copy, Debug)]
pub struct TopRevenuePerCustomerParams {
#[derive(Debug)]
pub struct TopRevenuePerCustomerParams<T1: cornucopia_async::StringSql> {
pub tenant_id: uuid::Uuid,
pub currency: T1,
pub limit: i64,
}
#[derive(Debug)]
Expand Down Expand Up @@ -10852,23 +10853,25 @@ FROM
LEFT JOIN
bi_customer_ytd_summary bi ON bi.customer_id = c.id
WHERE c.tenant_id = $1
AND (bi.revenue_year IS NULL OR bi.currency = $2)
AND (bi.revenue_year IS NULL OR bi.revenue_year >= DATE_PART('year', CURRENT_DATE))
ORDER BY
total_revenue_cents DESC
LIMIT $2",
LIMIT $3",
))
}
pub struct TopRevenuePerCustomerStmt(cornucopia_async::private::Stmt);
impl TopRevenuePerCustomerStmt {
pub fn bind<'a, C: GenericClient>(
pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>(
&'a mut self,
client: &'a C,
tenant_id: &'a uuid::Uuid,
currency: &'a T1,
limit: &'a i64,
) -> TopRevenuePerCustomerQuery<'a, C, TopRevenuePerCustomer, 2> {
) -> TopRevenuePerCustomerQuery<'a, C, TopRevenuePerCustomer, 3> {
TopRevenuePerCustomerQuery {
client,
params: [tenant_id, limit],
params: [tenant_id, currency, limit],
stmt: &mut self.0,
extractor: |row| TopRevenuePerCustomerBorrowed {
id: row.get(0),
Expand All @@ -10879,20 +10882,20 @@ LIMIT $2",
}
}
}
impl<'a, C: GenericClient>
impl<'a, C: GenericClient, T1: cornucopia_async::StringSql>
cornucopia_async::Params<
'a,
TopRevenuePerCustomerParams,
TopRevenuePerCustomerQuery<'a, C, TopRevenuePerCustomer, 2>,
TopRevenuePerCustomerParams<T1>,
TopRevenuePerCustomerQuery<'a, C, TopRevenuePerCustomer, 3>,
C,
> for TopRevenuePerCustomerStmt
{
fn params(
&'a mut self,
client: &'a C,
params: &'a TopRevenuePerCustomerParams,
) -> TopRevenuePerCustomerQuery<'a, C, TopRevenuePerCustomer, 2> {
self.bind(client, &params.tenant_id, &params.limit)
params: &'a TopRevenuePerCustomerParams<T1>,
) -> TopRevenuePerCustomerQuery<'a, C, TopRevenuePerCustomer, 3> {
self.bind(client, &params.tenant_id, &params.currency, &params.limit)
}
}
pub fn insert_mrr_movement_log() -> InsertMrrMovementLogStmt {
Expand Down Expand Up @@ -11033,8 +11036,6 @@ WHERE date <= $1
COUNT(*) FILTER (WHERE movement_type = 'CHURN') AS churn_count,
COALESCE(SUM(net_mrr_change) FILTER (WHERE movement_type = 'REACTIVATION'), 0)::bigint AS reactivation_mrr,
COUNT(*) FILTER (WHERE movement_type = 'REACTIVATION') AS reactivation_count
-- SUM(net_mrr_change) FILTER (WHERE movement_type = 'INCREMENTAL_USAGE') AS incremental_usage_mrr,
-- COUNT(*) FILTER (WHERE movement_type = 'INCREMENTAL_USAGE') AS incremental_usage_count
FROM bi_mrr_movement_log bi
WHERE applies_to BETWEEN $2 AND $3
AND bi.currency = $4
Expand Down Expand Up @@ -11124,8 +11125,6 @@ ORDER BY period"))
COUNT(*) FILTER (WHERE movement_type = 'REACTIVATION') AS reactivation_count,
p.id,
p.name
-- SUM(net_mrr_change) FILTER (WHERE movement_type = 'INCREMENTAL_USAGE') AS incremental_usage_mrr,
-- COUNT(*) FILTER (WHERE movement_type = 'INCREMENTAL_USAGE') AS incremental_usage_count
FROM bi_mrr_movement_log bi
JOIN plan_version pv on bi.plan_version_id = pv.id
JOIN plan p on pv.plan_id = p.id
Expand Down
8 changes: 5 additions & 3 deletions modules/meteroid/src/api/services/stats/mapping.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::services::stats::stats_service::{CountAndValue, MRRBreakdown, MRRBreakdownScope, MrrMovementType, Trend, TrendScope};
use crate::services::stats::stats_service::{
CountAndValue, MRRBreakdown, MRRBreakdownScope, MrrMovementType, Trend, TrendScope,
};
use meteroid_grpc::meteroid::api::stats::v1 as proto;
use meteroid_grpc::meteroid::api::stats::v1::{BreakdownStat, MrrBreakdownScope, MrrBreakdown};
use meteroid_grpc::meteroid::api::stats::v1::{BreakdownStat, MrrBreakdown, MrrBreakdownScope};

pub fn trend_to_server(trend: &Trend) -> proto::Trend {
proto::Trend {
Expand Down Expand Up @@ -61,4 +63,4 @@ pub fn map_mrr_type(m: MrrMovementType) -> proto::MrrMovementType {
MrrMovementType::NewBusiness => proto::MrrMovementType::NewBusiness,
MrrMovementType::Reactivation => proto::MrrMovementType::Reactivation,
}
}
}
5 changes: 1 addition & 4 deletions modules/meteroid/src/api/services/stats/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



use crate::services::stats::stats_service::{PgStatsService, StatsService};
use meteroid_grpc::meteroid::api::stats::v1::stats_service_server::StatsServiceServer;
use meteroid_repository::Pool;
Expand All @@ -9,7 +6,7 @@ use std::sync::Arc;
mod mapping;
mod service;

pub struct StatsServiceComponents {
pub struct StatsServiceComponents {
pub pool: Pool,
pub stats_service: Arc<dyn StatsService + Send + Sync>,
}
Expand Down
46 changes: 23 additions & 23 deletions modules/meteroid/src/api/services/stats/service.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@


use tonic::{Request, Response, Status};

use crate::{
api::services::utils::{parse_uuid},
parse_uuid,
};
use crate::{api::services::utils::parse_uuid, parse_uuid};

use super::{mapping, StatsServiceComponents};
use meteroid_grpc::meteroid::api::stats::v1 as grpc;
use meteroid_grpc::meteroid::api::stats::v1::{general_stats_response, signup_series, stats_service_server::StatsService, GeneralStatsRequest, GeneralStatsResponse, MrrBreakdownRequest, MrrBreakdownResponse, MrrChartRequest, MrrChartResponse, MrrChartSeries, MrrLogRequest, MrrLogResponse, SignupSeries, SignupSparklineRequest, SignupSparklineRequestResponse, TopRevenueByCustomerRequest, TopRevenueByCustomerResponse, TrialConversionRateSparklineRequest, TrialConversionRateSparklineResponse, TrialConversionSeries, TrialConversionMetaDataPoint, MrrBreakdownScope};


use meteroid_grpc::meteroid::api::stats::v1::{
general_stats_response, signup_series, stats_service_server::StatsService, GeneralStatsRequest,
GeneralStatsResponse, MrrBreakdownRequest, MrrBreakdownResponse, MrrBreakdownScope,
MrrChartRequest, MrrChartResponse, MrrChartSeries, MrrLogRequest, MrrLogResponse, SignupSeries,
SignupSparklineRequest, SignupSparklineRequestResponse, TopRevenueByCustomerRequest,
TopRevenueByCustomerResponse, TrialConversionMetaDataPoint,
TrialConversionRateSparklineRequest, TrialConversionRateSparklineResponse,
TrialConversionSeries,
};

use crate::api::services::shared;
use crate::api::services::stats::mapping::trend_to_server;

use crate::services::stats::stats_service;
use crate::services::stats::stats_service::{
RevenueByCustomerRequest,
};
use crate::services::stats::stats_service::RevenueByCustomerRequest;

use uuid::Uuid;
use common_grpc::middleware::server::auth::RequestExt;
use uuid::Uuid;

use meteroid_grpc::meteroid::api::stats::v1::mrr_chart_series;
use meteroid_grpc::meteroid::api::stats::v1::trial_conversion_series;


#[tonic::async_trait]
impl StatsService for StatsServiceComponents {
async fn general_stats(
Expand All @@ -36,7 +34,6 @@ impl StatsService for StatsServiceComponents {
) -> Result<Response<GeneralStatsResponse>, Status> {
let tenant_id = request.tenant()?;


let (
net_revenue_res,
active_subscriptions,
Expand Down Expand Up @@ -102,10 +99,11 @@ impl StatsService for StatsServiceComponents {
let plans_id = if req.plans_id.is_empty() {
None
} else {
let parsed: Vec<Uuid> = req.plans_id.into_iter()
.map(|plan_id|
parse_uuid!(&plan_id)
).collect::<Result<Vec<Uuid>, Status>>()?;
let parsed: Vec<Uuid> = req
.plans_id
.into_iter()
.map(|plan_id| parse_uuid!(&plan_id))
.collect::<Result<Vec<Uuid>, Status>>()?;
Some(parsed)
};

Expand Down Expand Up @@ -151,14 +149,14 @@ impl StatsService for StatsServiceComponents {
let tenant_id = request.tenant()?;
let req = request.into_inner();


let mrr_breakdown = self
.stats_service
.mrr_breakdown(stats_service::MRRBreakdownRequest {
tenant_id,
scope: mapping::mrr_breakdown_scope_from_server(
MrrBreakdownScope::try_from(req.scope)
.map_err(|e| Status::invalid_argument(format!("Failed to parse scope: {}", e)))?
MrrBreakdownScope::try_from(req.scope).map_err(|e| {
Status::invalid_argument(format!("Failed to parse scope: {}", e))
})?,
),
})
.await
Expand Down Expand Up @@ -195,7 +193,9 @@ impl StatsService for StatsServiceComponents {
customer_id: entry.customer_id,
customer_name: entry.customer_name,
applies_to: Some(shared::mapping::date::to_proto(entry.applies_to)),
created_at: Some(shared::mapping::datetime::offset_datetime_to_timestamp(entry.created_at)),
created_at: Some(shared::mapping::datetime::offset_datetime_to_timestamp(
entry.created_at,
)),
description: entry.description,
plan_name: entry.plan_name,
subscription_id: entry.subscription_id,
Expand Down
2 changes: 1 addition & 1 deletion modules/meteroid/src/services/stats/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod stats_service;
mod utils;
mod utils;
Loading

0 comments on commit 7bc6e56

Please sign in to comment.