Skip to content

Compliance score query mixes columns #297

@carlosms

Description

@carlosms

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, 
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions