From 483b62a91308ce2af2cec329f684f3b0bee12d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20R=C3=ADos?= Date: Tue, 3 Dec 2024 17:56:48 +0100 Subject: [PATCH] add: timeseries `funding_received` sqlmesh model (#2563) --- warehouse/metrics_mesh/models/metrics_factories.py | 9 +++++++++ .../metrics_mesh/oso_metrics/funding_received.sql | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 warehouse/metrics_mesh/oso_metrics/funding_received.sql diff --git a/warehouse/metrics_mesh/models/metrics_factories.py b/warehouse/metrics_mesh/models/metrics_factories.py index fc7326cfd..24ac8ec05 100644 --- a/warehouse/metrics_mesh/models/metrics_factories.py +++ b/warehouse/metrics_mesh/models/metrics_factories.py @@ -278,6 +278,15 @@ # ), # entity_types=["artifact"], # ), + "funding_received": MetricQueryDef( + ref="funding_received.sql", + rolling=RollingConfig( + windows=[180], + unit="day", + cron="@daily", + ), + entity_types=["artifact", "project", "collection"], + ), }, default_dialect="clickhouse", ) diff --git a/warehouse/metrics_mesh/oso_metrics/funding_received.sql b/warehouse/metrics_mesh/oso_metrics/funding_received.sql new file mode 100644 index 000000000..fdc4933f4 --- /dev/null +++ b/warehouse/metrics_mesh/oso_metrics/funding_received.sql @@ -0,0 +1,14 @@ +select @metrics_sample_date(events.bucket_day) as metrics_sample_date, + events.event_source, + events.to_artifact_id, + '' as from_artifact_id, + @metric_name() as metric, + SUM(events.amount) as amount +from metrics.events_daily_to_artifact as events +where event_type = 'CREDIT' + and events.bucket_day BETWEEN @metrics_start('DATE') AND @metrics_end('DATE') +group by 1, + metric, + from_artifact_id, + to_artifact_id, + event_source