-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sqlmesh): add onchain rolling window metrics (#2517)
* feat(sqlmesh): add new/returning user model * chore: configure factory query defs * feat(sqlmesh): create daily and monthly active address models * feat(sqlmesh): add active contracts * Update warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql Co-authored-by: Reuven Gonzales <[email protected]> * Update warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql Co-authored-by: Reuven Gonzales <[email protected]> * Update warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql Co-authored-by: Reuven Gonzales <[email protected]> * fix(sqlmesh): metric dates * fix: active_addresses follow developer metric naming conventions * refactor: active addresses models --------- Co-authored-by: Reuven Gonzales <[email protected]>
- Loading branch information
Showing
4 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
72 changes: 72 additions & 0 deletions
72
warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |