-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josquin Cornec
committed
Sep 16, 2024
1 parent
10eacd6
commit 5b97cf3
Showing
2 changed files
with
54 additions
and
3 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,44 @@ | ||
drop materialized view v_stats; | ||
create materialized view if not exists v_stats as | ||
WITH stat_users AS (SELECT count(DISTINCT v_log.tokencontent ->> 'email'::text) AS users, | ||
date_trunc('month'::text, v_log.date_add) AS mois | ||
FROM v_log | ||
GROUP BY (date_trunc('month'::text, v_log.date_add))), | ||
stat_recherches AS (SELECT count(DISTINCT | ||
CASE | ||
WHEN v_log.method = 'GET'::text THEN v_log.path | ||
ELSE v_log.body::json ->> 'search'::text | ||
END || ((v_log.tokencontent ->> 'email'::text) || | ||
date_trunc('day'::text, v_log.date_add)::text)) AS recherches, | ||
date_trunc('month'::text, v_log.date_add) AS mois | ||
FROM v_log | ||
WHERE v_log.path ~~ '%/search%'::text | ||
GROUP BY (date_trunc('month'::text, v_log.date_add))), | ||
stat_fiches AS (SELECT count(v_log.path) AS fiches, | ||
date_trunc('month'::text, v_log.date_add) AS mois | ||
FROM v_log | ||
WHERE v_log.path ~~ '/etablissement/get/%'::text | ||
OR v_log.path ~~ '/entreprise/%'::text | ||
GROUP BY (date_trunc('month'::text, v_log.date_add))), | ||
stat_visites AS (SELECT count(DISTINCT date_trunc('hour'::text, v_log.date_add)::text || | ||
(v_log.tokencontent ->> 'email'::text)) AS visites, | ||
date_trunc('month'::text, v_log.date_add) AS mois | ||
FROM v_log | ||
GROUP BY (date_trunc('month'::text, v_log.date_add)) | ||
LIMIT 100), | ||
stat_export AS (SELECT count(v_log.path) AS export, | ||
date_trunc('month'::text, v_log.date_add) AS mois | ||
FROM v_log | ||
WHERE v_log.path ~~ '/scores/xls/%'::text | ||
GROUP BY (date_trunc('month'::text, v_log.date_add))) | ||
SELECT u.mois, | ||
u.users, | ||
r.recherches, | ||
f.fiches, | ||
v.visites, | ||
e.export | ||
FROM stat_users u | ||
JOIN stat_recherches r ON r.mois = u.mois | ||
JOIN stat_fiches f ON f.mois = u.mois | ||
JOIN stat_visites v ON v.mois = u.mois | ||
JOIN stat_export e ON e.mois = u.mois; |
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