diff --git a/warehouse/metrics_mesh/models/metrics_factories.py b/warehouse/metrics_mesh/models/metrics_factories.py index e4c2dd28c..1b7818d10 100644 --- a/warehouse/metrics_mesh/models/metrics_factories.py +++ b/warehouse/metrics_mesh/models/metrics_factories.py @@ -25,10 +25,6 @@ ref="stars.sql", time_aggregations=["daily", "weekly", "monthly"], ), - "active_addresses": MetricQueryDef( - ref="active_addresses.sql", - time_aggregations=["daily", "weekly", "monthly"], - ), "commits": MetricQueryDef( ref="commits.sql", time_aggregations=["daily", "weekly", "monthly"], @@ -45,14 +41,14 @@ ref="forks.sql", time_aggregations=["daily", "weekly", "monthly"], ), - "gas_fees": MetricQueryDef( - ref="gas_fees.sql", - time_aggregations=["daily", "weekly", "monthly"], - ), "repositories": MetricQueryDef( ref="repositories.sql", time_aggregations=["daily", "weekly", "monthly"], ), + "active_contracts": MetricQueryDef( + ref="active_contracts.sql", + time_aggregations=["daily", "weekly", "monthly"], + ), "contributors": MetricQueryDef( ref="contributors.sql", time_aggregations=["daily", "weekly", "monthly"], @@ -100,6 +96,18 @@ cron="@daily", ), ), + "user_retention_classifications": MetricQueryDef( + ref="user_retention_classification.sql", + vars={ + "activity_event_types": ["CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT"], + }, + rolling=RollingConfig( + windows=[30, 90, 180], + unit="day", + cron="@daily", + ), + entity_types=["artifact", "project", "collection"], + ), "change_in_30_day_developer_activity": MetricQueryDef( vars={ "comparison_interval": 30, @@ -187,7 +195,7 @@ ), entity_types=["artifact", "project", "collection"], ), - "avg_time_to_first_response": MetricQueryDef( + "avg_time_to_first_response": MetricQueryDef( ref="prs_time_to_merge.sql", rolling=RollingConfig( windows=[90, 180], @@ -196,6 +204,42 @@ ), entity_types=["artifact", "project", "collection"], ), + "active_addresses_aggregation": MetricQueryDef( + ref="active_addresses.sql", + vars={ + "activity_event_types": ["CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT"], + }, + time_aggregations=["daily", "monthly"], + ), + "active_addresses_rolling": MetricQueryDef( + ref="active_addresses.sql", + vars={ + "activity_event_types": ["CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT"], + }, + rolling=RollingConfig( + windows=[30, 90, 180], + unit="day", + cron="@daily", + ), + ), + "gas_fees": MetricQueryDef( + ref="gas_fees.sql", + rolling=RollingConfig( + windows=[30, 90, 180], + unit="day", + cron="@daily", + ), + entity_types=["artifact", "project", "collection"], + ), + "transactions": MetricQueryDef( + ref="transactions.sql", + rolling=RollingConfig( + windows=[30, 90, 180], + unit="day", + cron="@daily", + ), + entity_types=["artifact", "project", "collection"], + ), }, default_dialect="clickhouse", ) diff --git a/warehouse/metrics_mesh/oso_metrics/active_addresses.sql b/warehouse/metrics_mesh/oso_metrics/active_addresses.sql index 27460383d..7bc721c0e 100644 --- a/warehouse/metrics_mesh/oso_metrics/active_addresses.sql +++ b/warehouse/metrics_mesh/oso_metrics/active_addresses.sql @@ -3,12 +3,12 @@ select @metrics_sample_date(events.bucket_day) as metrics_sample_date, events.to_artifact_id, '' as from_artifact_id, @metric_name() as metric, - COUNT(distinct events.from_artifact_id) as amount + COUNT(DISTINCT events.from_artifact_id) as amount from metrics.events_daily_to_artifact as events -where event_type in ('CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT') +where event_type in @activity_event_types and events.bucket_day BETWEEN @metrics_start('DATE') AND @metrics_end('DATE') group by 1, metric, from_artifact_id, to_artifact_id, - event_source \ No newline at end of file + event_source, diff --git a/warehouse/metrics_mesh/oso_metrics/active_contracts.sql b/warehouse/metrics_mesh/oso_metrics/active_contracts.sql new file mode 100644 index 000000000..6d14f3bdd --- /dev/null +++ b/warehouse/metrics_mesh/oso_metrics/active_contracts.sql @@ -0,0 +1,16 @@ +select @metrics_sample_date(events.bucket_day) as metrics_sample_date, + events.event_source, + events.to_artifact_id as to_artifact_id, + '' as from_artifact_id, + @metric_name() as metric, + COUNT(distinct events.to_artifact_id) as amount +from metrics.events_daily_to_artifact as events +where events.event_type in ( + 'CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT' + ) + and events.bucket_day BETWEEN @metrics_start('DATE') AND @metrics_end('DATE') +group by 1, + metric, + from_artifact_id, + to_artifact_id, + event_source diff --git a/warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql b/warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql new file mode 100644 index 000000000..131be3f9b --- /dev/null +++ b/warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql @@ -0,0 +1,72 @@ +with first_events as ( + select + from_artifact_id, + min(time::date) as first_event_date + from @first_of_event_from_artifact + where event_type in (@activity_event_types) + group by from_artifact_id +), +active_users as ( + select distinct + from_artifact_id, + event_date, + event_source, + @metrics_entity_type_col( + 'to_{entity_type}_id', + include_column_alias := true + ) + from @metrics_source( + event_types := @activity_event_types + ) + where event_date >= @metrics_start('DATE') +) + +select + @metrics_end('DATE') as metrics_sample_date, + active.event_source, + @metrics_entity_type_col( + 'to_{entity_type}_id', + table_alias := active, + include_column_alias := true + ), + '' as from_artifact_id, + @metric_name('new_users') as metric, + COUNT(DISTINCT active.from_artifact_id) as amount +from active_users active +join first_events on first_events.from_artifact_id = active.from_artifact_id +where first_events.first_event_date >= @metrics_start('DATE') +group by + metrics_sample_date, + metric, + from_artifact_id, + @metrics_entity_type_col( + 'to_{entity_type}_id', + table_alias := active + ), + event_source + +union all + +select + @metrics_end('DATE') as metrics_sample_date, + active.event_source, + @metrics_entity_type_col( + 'to_{entity_type}_id', + table_alias := active, + include_column_alias := true + ), + '' as from_artifact_id, + @metric_name('returning_users') as metric, + COUNT(DISTINCT active.from_artifact_id) as amount +from active_users active +join first_events on first_events.from_artifact_id = active.from_artifact_id +where first_events.first_event_date < @metrics_start('DATE') +group by + metrics_sample_date, + metric, + from_artifact_id, + @metrics_entity_type_col( + 'to_{entity_type}_id', + table_alias := active + ), + event_source