Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics) : Ajout d'une sous-application analytics #144

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
8 changes: 6 additions & 2 deletions analytics/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ clean-targets:

models:
dora:
legacy:
+schema: analytics
staging:
+schema: staging
+materialized: view
intermediate:
+schema: intermediate
+materialized: table
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ sources:
- name: structures_structure_national_labels
- name: structures_structureputativemember
- name: structures_structuretypology
- name: upload_stats_insertion
description: "Table insérée manuellement par DORA ? Faire un seed ?"
- name: users_user


17 changes: 17 additions & 0 deletions analytics/models/intermediate/int_mobilisationevent_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH users AS (
SELECT * FROM {{ ref('stg_user') }}
),

events AS (
SELECT * FROM {{ ref('stg_mobilisationevent') }}
),

final AS (
SELECT
{{ dbt_utils.star(relation_alias='events', from=ref('stg_mobilisationevent'), prefix='event_') }},
{{ dbt_utils.star(relation_alias='users', from=ref('stg_user'), prefix='user_') }}
FROM events
INNER JOIN users ON events.user_id = users.id
)

SELECT * FROM final
23 changes: 23 additions & 0 deletions analytics/models/intermediate/int_orientation_user_service.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
WITH orientations AS (
SELECT * FROM {{ ref('stg_orientation') }}
),

users AS (
SELECT * FROM {{ ref('stg_user') }}
),

services AS (
SELECT * FROM {{ ref('int_service_structure') }}
),

final AS (
SELECT
{{ dbt_utils.star(relation_alias='orientations', from=ref('stg_orientation'), prefix='orientation_') }},
{{ dbt_utils.star(relation_alias='users', from=ref('stg_user'), prefix='user_') }},
{{ dbt_utils.star(relation_alias='services', from=ref('int_service_structure')) }}
FROM orientations
INNER JOIN users ON orientations.prescriber_id = users.id
INNER JOIN services ON orientations.service_id = services.service_id
)

SELECT * FROM final
17 changes: 17 additions & 0 deletions analytics/models/intermediate/int_pageview_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH events AS (
SELECT * FROM {{ ref('stg_pageview') }}
),

users AS (
SELECT * FROM {{ ref('stg_user') }}
),

final AS (
SELECT
{{ dbt_utils.star(relation_alias='events', from=ref('stg_pageview'), prefix='event_') }},
{{ dbt_utils.star(relation_alias='users', from=ref('stg_user'), prefix='user_') }}
FROM events
INNER JOIN users ON events.user_id = users.id
)

SELECT * FROM final
17 changes: 17 additions & 0 deletions analytics/models/intermediate/int_searchview_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH events AS (
SELECT * FROM {{ ref('stg_searchview') }}
),

users AS (
SELECT * FROM {{ ref('stg_user') }}
),

final AS (
SELECT
{{ dbt_utils.star(relation_alias='events', from=ref('stg_searchview'), prefix='event_') }},
{{ dbt_utils.star(relation_alias='users', from=ref('stg_user'), prefix='user_') }}
FROM events
INNER JOIN users ON events.user_id = users.id
)

SELECT * FROM final
23 changes: 23 additions & 0 deletions analytics/models/intermediate/int_service_categories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
WITH services AS (
SELECT * FROM {{ ref("int_service_structure") }}
),

categorie_pairs AS (
SELECT * FROM {{ source('dora', 'services_service_categories') }}
),

categories AS (
SELECT * FROM {{ source('dora', 'services_servicecategory') }}
),

final AS (
SELECT
services.*,
categories.label AS category_name,
categories.value AS category_label
FROM services
LEFT JOIN categorie_pairs ON services.service_id = categorie_pairs.service_id
LEFT JOIN categories ON categorie_pairs.servicecategory_id = categories.id
)

SELECT * FROM final
23 changes: 23 additions & 0 deletions analytics/models/intermediate/int_service_fundinglabels.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
WITH services AS (
SELECT * FROM {{ ref("int_service_structure") }}
),

fundinglabel_pairs AS (
SELECT * FROM {{ source('dora', 'services_service_funding_labels') }}
),

fundinglabels AS (
SELECT * FROM {{ source('dora', 'services_fundinglabel') }}
),

final AS (
SELECT
services.*,
fundinglabels.label AS fundinglabel_name,
fundinglabels.value AS fundinglabel_label
FROM services
LEFT JOIN fundinglabel_pairs ON services.service_id = fundinglabel_pairs.service_id
LEFT JOIN fundinglabels ON fundinglabel_pairs.fundinglabel_id = fundinglabels.id
)

SELECT * FROM final
17 changes: 17 additions & 0 deletions analytics/models/intermediate/int_service_structure.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH services AS (
SELECT * FROM {{ ref("stg_service") }}
),

structure AS (
SELECT * FROM {{ ref("stg_structure") }}
),

final AS (
SELECT
{{ dbt_utils.star(relation_alias='services', from=ref("stg_service"), prefix='service_') }},
{{ dbt_utils.star(relation_alias='structure', from=ref("stg_structure"), prefix='structure_') }}
FROM services
INNER JOIN structure ON services.structure_id = structure.id
)

SELECT * FROM final
17 changes: 17 additions & 0 deletions analytics/models/intermediate/int_service_structure_labels.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH services AS (
SELECT * FROM {{ ref("stg_service") }}
),

structure AS (
SELECT * FROM {{ ref("int_structure_labels") }}
),

final AS (
SELECT
{{ dbt_utils.star(relation_alias='services', from=ref("stg_service"), prefix='service_', except=['id']) }},
{{ dbt_utils.star(relation_alias='structure', from=ref("int_structure_labels"), prefix='structure_', except=['id']) }}
FROM services
INNER JOIN structure ON services.structure_id = structure.id
)

SELECT * FROM final
23 changes: 23 additions & 0 deletions analytics/models/intermediate/int_serviceview_user_service.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
WITH events AS (
SELECT * FROM {{ ref('stg_serviceview') }}
),

services AS (
SELECT * FROM {{ ref('int_service_structure') }}
),

users AS (
SELECT * FROM {{ ref('stg_user') }}
),

final AS (
SELECT
{{ dbt_utils.star(relation_alias='events', from=ref('stg_serviceview'), prefix='event_') }},
{{ dbt_utils.star(relation_alias='services', from=ref('int_service_structure')) }},
{{ dbt_utils.star(relation_alias='users', from=ref('stg_user'), prefix='user_') }}
FROM events
INNER JOIN services ON CAST(services.service_id AS TEXT) = events.service_id
LEFT JOIN users ON events.user_id = users.id
)

SELECT * FROM final
23 changes: 23 additions & 0 deletions analytics/models/intermediate/int_structure_labels.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
WITH structures AS (
SELECT * FROM {{ ref("stg_structure") }}
),

national_label_pairs AS (
SELECT * FROM {{ source('dora', 'structures_structure_national_labels') }}
),

national_labels AS (
SELECT * FROM {{ source('dora', 'structures_structurenationallabel') }}
),

final AS (
SELECT
structures.*,
national_labels.label AS national_label_name,
national_labels.value AS national_label_code
FROM structures
LEFT JOIN national_label_pairs ON structures.id = national_label_pairs.structure_id
LEFT JOIN national_labels ON national_label_pairs.structurenationallabel_id = national_labels.id
)

SELECT * FROM final
22 changes: 22 additions & 0 deletions analytics/models/intermediate/int_structure_member.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
WITH users AS (
SELECT * FROM {{ ref('stg_user') }}
),

structure AS (
SELECT * FROM {{ ref('stg_structure') }}
),

member AS (
SELECT * FROM {{ source('dora', 'structures_structuremember') }}
),

final AS (
SELECT
{{ dbt_utils.star(relation_alias='users', from=ref('stg_user'), prefix='user_') }},
{{ dbt_utils.star(relation_alias='structure', from=ref('stg_structure'), prefix='structure_') }}
FROM member
INNER JOIN structure ON member.structure_id = structure.id
INNER JOIN users ON member.user_id = users.id
)

SELECT * FROM final

This file was deleted.

75 changes: 0 additions & 75 deletions analytics/models/legacy/metabase/01-base/mb_service.sql

This file was deleted.

This file was deleted.

Loading
Loading