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

Compliance score query mixes columns #297

Open
carlosms opened this issue Oct 16, 2019 · 1 comment
Open

Compliance score query mixes columns #297

carlosms opened this issue Oct 16, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@carlosms
Copy link
Contributor

This is the query for the Overview dashboard, Compliance score chart:

SELECT 
    SUM(changelog != 0) / COUNT(changelog)  as changelog, 
    SUM(readme != 0)  / COUNT(changelog) as readme, 
    SUM(notice != 0)  / COUNT(changelog) as notice, 
    SUM(license != 0) / COUNT(changelog) as license,
    SUM(contributing != 0) / COUNT(changelog) as contributing,
    SUM(travis != 0) / COUNT(changelog) as travis, 
    SUM(ci != 0) / COUNT(changelog) as ci, 
    SUM(dockerfile != 0) / COUNT(changelog) as dockerfile 
FROM (
    SELECT 
        SUM(changelog) as changelog, 
        SUM(readme) as readme, 
        SUM(notice) as notice, 
        SUM(license) as license,
        SUM(contributing) as contributing,
        SUM(travis) as travis,
        SUM(ci) as ci,
        SUM(dockerfile) as dockerfile
    FROM (
        SELECT 
            refs.repository_id, 
            CASE WHEN file_path LIKE '(?i)^CHANGELOG(|\.MD)' THEN 1 ELSE 0 END AS changelog,
            CASE WHEN file_path LIKE '(?i)^README(|\.MD)' THEN 1 ELSE 0 END AS readme,
            CASE WHEN file_path LIKE '(?i)^NOTICE(|\.MD)' THEN 1 ELSE 0 END AS notice,
            CASE WHEN file_path LIKE '(?i)^LICENSE(|\.MD)' THEN 1 ELSE 0 END AS license,
            CASE WHEN file_path LIKE '(?i)^CONTRIBUTING(|\.MD)' THEN 1 ELSE 0 END AS contributing,
            CASE WHEN file_path LIKE '(?i)^\.TRAVIS\.YML' THEN 1 ELSE 0 END AS travis,
            CASE WHEN file_path LIKE '(?i)^CI' THEN 1 ELSE 0 END AS ci,
            CASE WHEN file_path LIKE '(?i)^DOCKERFILE$' THEN 1 ELSE 0 END AS dockerfile
        FROM refs
        JOIN commit_files 
        ON refs.commit_hash = commit_files.commit_hash 
        WHERE ref_name = 'refs/heads/master' 
    ) q
    GROUP BY repository_id
) q2

I assume these lines:

    SUM(changelog != 0) / COUNT(changelog)  as changelog, 
    SUM(readme != 0)  / COUNT(changelog) as readme, 
    SUM(notice != 0)  / COUNT(changelog) as notice, 
....

Should be like this instead:

    SUM(changelog != 0) / COUNT(changelog)  as changelog, 
    SUM(readme != 0)  / COUNT(readme) as readme, 
    SUM(notice != 0)  / COUNT(notice) as notice, 
...
@se7entyse7en
Copy link
Contributor

se7entyse7en commented Oct 16, 2019

Since it just COUNTs I don't think it makes any difference in the end, but for sure for clarity, it should be as you said.

@se7entyse7en se7entyse7en added the enhancement New feature or request label Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants