Skip to content

Commit

Permalink
dbt: event models by source (#1118)
Browse files Browse the repository at this point in the history
* dbt: update project models

* add: events to project by source models

* add: additional models

* fix: white space

* fix: linting
  • Loading branch information
ccerv1 authored Mar 22, 2024
1 parent 69a27b7 commit d078f4b
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 1 deletion.
2 changes: 2 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
in-project = true
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ WITH project_commit_dates AS (
project_repos_summary AS (
SELECT
p.project_id,
p.project_slug,
p.project_name,
r.repository_source,
COUNT(DISTINCT r.id) AS repositories,
Expand All @@ -48,7 +49,7 @@ project_repos_summary AS (
INNER JOIN {{ ref('projects') }} AS p
ON r.project_id = p.project_id
WHERE r.is_fork = false
GROUP BY p.project_id, p.project_name, r.repository_source
GROUP BY p.project_id, p.project_slug, p.project_name, r.repository_source
),

-- CTE for calculating contributor counts and new contributors in the last 6
Expand Down Expand Up @@ -128,6 +129,7 @@ activity_cte AS (
-- Final query to join all the metrics together
SELECT
p.project_id,
p.project_slug,
p.project_name,
p.repository_source AS `source`,
pcd.first_commit_date,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events daily to an artifact by source
#}

SELECT
e.to_id AS artifact_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.time, DAY) AS bucket_day,
SUM(e.amount) AS amount
FROM {{ ref('int_events_to_project') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events daily to a collection by source
#}

SELECT
e.collection_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.time, DAY) AS bucket_day,
SUM(e.amount) AS amount
FROM {{ ref('int_events_to_collection') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events daily to a project by source
#}

SELECT
e.project_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.time, DAY) AS bucket_day,
SUM(e.amount) AS amount
FROM {{ ref('int_events_to_project') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events monthly to an artifact by source
#}

SELECT
e.artifact_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.bucket_day, MONTH) AS bucket_month,
SUM(e.amount) AS amount
FROM {{ ref('events_daily_to_artifact_by_source') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events monthly to a collection by source
#}

SELECT
e.collection_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.bucket_day, MONTH) AS bucket_month,
SUM(e.amount) AS amount
FROM {{ ref('events_daily_to_collection_by_source') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events monthly to a project by source
#}

SELECT
e.project_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.bucket_day, MONTH) AS bucket_month,
SUM(e.amount) AS amount
FROM {{ ref('events_daily_to_project_by_source') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events weekly to an artifact by source
#}

SELECT
e.artifact_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.bucket_day, WEEK) AS bucket_week,
SUM(e.amount) AS amount
FROM {{ ref('events_daily_to_artifact_by_source') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events weekly to a collection by source
#}

SELECT
e.collection_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.bucket_day, WEEK) AS bucket_week,
SUM(e.amount) AS amount
FROM {{ ref('events_daily_to_collection_by_source') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
All events weekly to a project by source
#}

SELECT
e.project_id,
e.from_id,
e.event_type,
TIMESTAMP_TRUNC(e.bucket_day, WEEK) AS bucket_week,
SUM(e.amount) AS amount
FROM {{ ref('events_daily_to_project_by_source') }} AS e
GROUP BY 1, 2, 3, 4
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ contracts AS (
project_by_network AS (
SELECT
p.project_id,
p.project_slug,
ctx.onchain_network,
p.project_name
FROM {{ ref('projects') }} AS p
Expand All @@ -159,6 +160,7 @@ project_by_network AS (
-- Final query to join all the metrics together
SELECT
p.project_id,
p.project_slug,
p.onchain_network AS network,
p.project_name,
-- TODO: add deployers owned by project
Expand Down

0 comments on commit d078f4b

Please sign in to comment.