-
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.
Merge branch 'main' into jabolol/defillama-tvl
- Loading branch information
Showing
31 changed files
with
732 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Funding in a Social Network | ||
sidebar_position: 5 | ||
--- | ||
|
||
Analyze Gitcoin grants funding in a social network. New to OSO? Check out our [Getting Started guide](../get-started/index.md) to set up your BigQuery or API access. | ||
|
||
This tutorial combines Farcaster and Gitcoin data to to identify popular projects within a social network. | ||
|
||
## BigQuery | ||
|
||
If you haven't already, then the first step is to subscribe to OSO public datasets in BigQuery. You can do this by clicking the "Subscribe" button on our [Datasets page](../integrate/datasets/#oso-production-data-pipeline). For this tutorial, you'll need to subscribe to the Gitcoin and Karma3/OpenRank datasets. (You can also use the Farcaster dataset in place of OpenRank.) | ||
|
||
The following queries should work if you copy-paste them into your [BigQuery console](https://console.cloud.google.com/bigquery). | ||
|
||
### Identify popular projects within your social network | ||
|
||
```sql | ||
select distinct | ||
donations.donor_address, | ||
users.user_source_id as fid, | ||
users.user_name as username, | ||
donations.project_name, | ||
amount_in_usd, | ||
timestamp | ||
from `gitcoin.all_donations` as donations | ||
join `oso_production.artifacts_by_user_v1` as users | ||
on lower(donations.donor_address) = users.artifact_name | ||
where | ||
user_source = 'FARCASTER' | ||
and users.user_source_id in ( | ||
with max_date as ( | ||
select max(date) as last_date | ||
from `karma3.localtrust` | ||
) | ||
select cast(j as string) as fid | ||
from `karma3.localtrust` | ||
where i = 5650 | ||
order by v desc | ||
limit 150 | ||
) | ||
``` |
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
59 changes: 59 additions & 0 deletions
59
warehouse/dbt/models/intermediate/directory/int_open_collective_projects.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,59 @@ | ||
with url_registry as ( | ||
select | ||
LOWER(JSON_EXTRACT_SCALAR(to_account, '$.slug')) as project_slug, | ||
LOWER(JSON_EXTRACT_SCALAR(link, '$.url')) as github_url, | ||
REGEXP_EXTRACT(LOWER(JSON_EXTRACT_SCALAR(link, '$.url')), r'github\.com/([a-z0-9-]+)') | ||
as artifact_namespace, | ||
REGEXP_EXTRACT( | ||
LOWER(JSON_EXTRACT_SCALAR(link, '$.url')), r'github\.com/[a-z0-9-]+/([a-z0-9-._]+)' | ||
) as artifact_name | ||
from | ||
{{ ref('stg_open_collective__deposits') }}, | ||
UNNEST(JSON_EXTRACT_ARRAY(to_account, '$.socialLinks')) as link | ||
where | ||
JSON_EXTRACT_SCALAR(link, '$.url') like '%github.com%' | ||
), | ||
|
||
oso_projects as ( | ||
select | ||
project_id, | ||
artifact_namespace, | ||
artifact_name | ||
from {{ ref('repositories_v0') }} | ||
where artifact_source = 'GITHUB' | ||
), | ||
|
||
namespace_counts as ( | ||
select | ||
artifact_namespace, | ||
COUNT(distinct project_id) as project_count, | ||
MIN(project_id) as project_id | ||
from oso_projects | ||
group by artifact_namespace | ||
), | ||
|
||
matched_projects as ( | ||
select | ||
ur.*, | ||
case | ||
when op.project_id is not null then op.project_id | ||
when nc.project_count = 1 then nc.project_id | ||
end as project_id | ||
from url_registry as ur | ||
left join oso_projects as op | ||
on | ||
ur.artifact_namespace = op.artifact_namespace | ||
and ur.artifact_name = op.artifact_name | ||
left join namespace_counts as nc | ||
on ur.artifact_namespace = nc.artifact_namespace | ||
) | ||
|
||
select distinct | ||
project_id as project_id, | ||
{{ oso_id("'OPEN_COLLECTIVE'", 'project_slug') }} as artifact_id, | ||
project_slug as artifact_source_id, | ||
'OPEN_COLLECTIVE' as artifact_source, | ||
'' as artifact_namespace, | ||
project_slug as artifact_name, | ||
'https://opencollective.com/' || project_slug as artifact_url | ||
from matched_projects |
24 changes: 24 additions & 0 deletions
24
warehouse/dbt/models/intermediate/funding/int_open_collective_deposits.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,24 @@ | ||
with open_collective_deposits as ( | ||
select | ||
id as event_source_id, | ||
created_at as `time`, | ||
JSON_EXTRACT_SCALAR(to_account, '$.name') as project_name, | ||
LOWER(JSON_EXTRACT_SCALAR(to_account, '$.slug')) as project_slug, | ||
UPPER(JSON_EXTRACT_SCALAR(to_account, '$.type')) as project_type, | ||
UPPER(JSON_EXTRACT_SCALAR(amount, '$.currency')) as currency, | ||
CAST(JSON_EXTRACT_SCALAR(amount, '$.value') as NUMERIC) as amount | ||
from {{ ref('stg_open_collective__deposits') }} | ||
) | ||
|
||
select | ||
open_collective_deposits.event_source_id, | ||
open_collective_deposits.`time`, | ||
projects.project_id, | ||
open_collective_deposits.project_name, | ||
open_collective_deposits.project_slug, | ||
open_collective_deposits.project_type, | ||
open_collective_deposits.currency, | ||
open_collective_deposits.amount | ||
from open_collective_deposits | ||
left join {{ ref('int_open_collective_projects') }} as projects | ||
on open_collective_deposits.project_slug = projects.artifact_source_id |
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
File renamed without changes.
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,8 @@ | ||
MODEL ( | ||
name metrics.metric_names_from_artifact, | ||
kind FULL | ||
); | ||
|
||
SELECT DISTINCT | ||
metric | ||
FROM metrics.timeseries_metrics_to_artifact |
8 changes: 8 additions & 0 deletions
8
warehouse/metrics_mesh/models/metric_names_from_collection.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,8 @@ | ||
MODEL ( | ||
name metrics.metric_names_from_collection, | ||
kind FULL | ||
); | ||
|
||
SELECT DISTINCT | ||
metric | ||
FROM metrics.timeseries_metrics_to_collection |
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,8 @@ | ||
MODEL ( | ||
name metrics.metric_names_from_project, | ||
kind FULL | ||
); | ||
|
||
SELECT DISTINCT | ||
metric | ||
FROM metrics.timeseries_metrics_to_project |
Oops, something went wrong.