This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1326 from open-apparel-registry/tw/add-new-reports
Add new admin reports
- Loading branch information
Showing
6 changed files
with
147 additions
and
0 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
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,29 @@ | ||
SELECT | ||
month, | ||
ROUND(AVG(match_count), 2) as average_matches | ||
FROM ( | ||
SELECT f.id, COUNT(*) as match_count, zmonth as month | ||
FROM api_facility f | ||
JOIN ( | ||
SELECT DISTINCT | ||
c.id, | ||
fm.facility_id, | ||
to_char(fm.created_at, 'YYYY-MM') as created_month, | ||
z.month as zmonth | ||
FROM api_facilitymatch fm | ||
JOIN api_facilitylistitem i | ||
ON fm.facility_list_item_id = i.id | ||
JOIN api_source s | ||
ON i.source_id = s.id | ||
JOIN api_contributor c | ||
ON s.contributor_id = c.id | ||
JOIN ( | ||
SELECT to_char(m.created_at, 'YYYY-MM') as month | ||
FROM api_facilitymatch m group by month | ||
) z ON to_char(fm.created_at, 'YYYY-MM') <= z.month | ||
WHERE fm.status NOT IN ('PENDING', 'REJECTED') | ||
) as fm ON f.id = fm.facility_id | ||
GROUP BY zmonth, f.id | ||
) as c | ||
GROUP BY month | ||
ORDER BY month; |
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,22 @@ | ||
SELECT | ||
fm.month, | ||
ROUND(CAST( | ||
(COUNT(CASE WHEN fm.is_public_list THEN 1 ELSE NULL END)*100) | ||
as decimal)/COUNT(*), 2) AS oar_data, | ||
ROUND(CAST( | ||
(COUNT(CASE WHEN NOT fm.is_public_list THEN 1 ELSE NULL END)*100) | ||
as decimal)/COUNT(*), 2) AS industry_data | ||
FROM ( | ||
SELECT | ||
MIN(to_char(m.created_at, 'YYYY-MM')) AS month, | ||
u.email LIKE '%openapparel.org%' AS is_public_list | ||
FROM api_facilitymatch m | ||
JOIN api_facilitylistitem i on m.facility_list_item_id = i.id | ||
JOIN api_source s on i.source_id = s.id | ||
JOIN api_contributor c ON s.contributor_id = c.id | ||
JOIN api_user u ON u.id = c.admin_id | ||
WHERE m.status NOT IN ('REJECTED', 'PENDING') | ||
GROUP BY m.facility_id, u.email | ||
) as fm | ||
GROUP BY fm.month | ||
ORDER BY fm.month |
35 changes: 35 additions & 0 deletions
35
src/django/api/reports/percent_data_by_contributor_type.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,35 @@ | ||
SELECT | ||
match.month, | ||
contrib_type, | ||
ROUND(CAST((COUNT(*)*100) as decimal)/total, 2) as percent_of_data | ||
FROM ( | ||
SELECT | ||
MIN(to_char(m.created_at, 'YYYY-MM')) AS month, | ||
contrib_type | ||
FROM api_facilitymatch m | ||
JOIN api_facilitylistitem i on m.facility_list_item_id = i.id | ||
JOIN api_source s on i.source_id = s.id | ||
JOIN api_contributor c ON s.contributor_id = c.id | ||
JOIN api_user u ON u.id = c.admin_id | ||
WHERE m.status NOT IN ('REJECTED', 'PENDING') | ||
AND u.email NOT LIKE '%openapparel.org%' | ||
GROUP BY m.facility_id, u.email, c.contrib_type | ||
) as match | ||
JOIN ( | ||
SELECT month, count(*) as total | ||
FROM ( | ||
SELECT | ||
MIN(to_char(m.created_at, 'YYYY-MM')) AS month | ||
FROM api_facilitymatch m | ||
JOIN api_facilitylistitem i on m.facility_list_item_id = i.id | ||
JOIN api_source s on i.source_id = s.id | ||
JOIN api_contributor c ON s.contributor_id = c.id | ||
JOIN api_user u ON u.id = c.admin_id | ||
WHERE m.status NOT IN ('REJECTED', 'PENDING') | ||
AND u.email NOT LIKE '%openapparel.org%' | ||
GROUP BY m.facility_id, u.email | ||
) as fm | ||
GROUP BY month | ||
ORDER BY month | ||
) t ON t.month = match.month | ||
GROUP BY match.month, contrib_type, total; |
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,31 @@ | ||
SELECT | ||
match.month, | ||
source_type, | ||
ROUND(CAST((COUNT(*)*100) as decimal)/total, 2) as percent_of_data | ||
FROM ( | ||
SELECT | ||
MIN(to_char(m.created_at, 'YYYY-MM')) AS month, | ||
source_type | ||
FROM api_facilitymatch m | ||
JOIN api_facilitylistitem i on m.facility_list_item_id = i.id | ||
JOIN api_source s on i.source_id = s.id | ||
JOIN api_contributor c ON s.contributor_id = c.id | ||
WHERE m.status NOT IN ('REJECTED', 'PENDING') | ||
GROUP BY m.facility_id, c.id, s.source_type | ||
) as match | ||
JOIN ( | ||
SELECT month, count(*) as total | ||
FROM ( | ||
SELECT | ||
MIN(to_char(m.created_at, 'YYYY-MM')) AS month | ||
FROM api_facilitymatch m | ||
JOIN api_facilitylistitem i on m.facility_list_item_id = i.id | ||
JOIN api_source s on i.source_id = s.id | ||
JOIN api_contributor c ON s.contributor_id = c.id | ||
WHERE m.status NOT IN ('REJECTED', 'PENDING') | ||
GROUP BY m.facility_id, c.id | ||
) as fm | ||
GROUP BY month | ||
ORDER BY month | ||
) t ON t.month = match.month | ||
GROUP BY match.month, source_type, total; |
29 changes: 29 additions & 0 deletions
29
src/django/api/reports/percent_facilities_with_multiple_matches.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,29 @@ | ||
SELECT zmonth as month, | ||
ROUND(CAST((facilities_with_multiple_matches*100) as decimal)/total_facilities, 2) as percent_of_data_with_multiple_matches, | ||
facilities_with_multiple_matches, | ||
total_facilities | ||
FROM ( | ||
SELECT | ||
zmonth, | ||
COUNT(CASE WHEN match_count > 1 THEN 1 ELSE NULL END) as facilities_with_multiple_matches, | ||
COUNT(*) AS total_facilities | ||
FROM ( | ||
SELECT facility_id, COUNT(*) as match_count, zmonth | ||
FROM | ||
( | ||
SELECT | ||
fm.facility_id, | ||
z.month as zmonth | ||
FROM api_facilitymatch fm | ||
JOIN ( | ||
SELECT to_char(m.created_at, 'YYYY-MM') as month | ||
FROM api_facilitymatch m group by month | ||
) z ON to_char(fm.created_at, 'YYYY-MM') <= z.month | ||
JOIN api_facilitylistitem i ON i.id = fm.facility_list_item_id | ||
JOIN api_source s on i.source_id = s.id | ||
GROUP BY s.contributor_id, zmonth, fm.facility_id | ||
) as f | ||
GROUP BY f.facility_id, zmonth | ||
) as y | ||
GROUP BY zmonth | ||
) as z |