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

Show package ranking #18

Open
gingerwizard opened this issue Aug 23, 2023 · 2 comments
Open

Show package ranking #18

gingerwizard opened this issue Aug 23, 2023 · 2 comments

Comments

@gingerwizard
Copy link
Collaborator

e.g. top 1% of packages downloaded.

Simple query. Add to downloads bar.

@gingerwizard
Copy link
Collaborator Author

WITH results AS ( SELECT sumIf(count, date > {min_date:String}::Date32 AND date > {max_date:String}::Date32 - toIntervalDay(1) AND date <= {max_date:String}::Date32) AS last_day,
    sumIf(count, date > {min_date:String}::Date32 AND date > {max_date:String}::Date32 - toIntervalWeek(1) AND date <= {max_date:String}::Date32) AS last_week,
    sumIf(count, date > {min_date:String}::Date32 AND date > {max_date:String}::Date32 - toIntervalMonth(1) AND date <= {max_date:String}::Date32) AS last_month,
    sumIf(count, date > {min_date:String}::Date32 AND date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32) AS total
    FROM pypi.pypi_downloads_per_day WHERE (project = {package_name:String}) AND 1=1 AND 1=1 
    AND 1=1 ),
(
    SELECT uniq(project) FROM (
      SELECT project FROM pypi.pypi_downloads_per_day WHERE date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32 GROUP BY project HAVING sum(count) > (SELECT total FROM results)   
    )
) as rank
SELECT rank, * FROM results

solves but alittle slow

@gingerwizard
Copy link
Collaborator Author

better

WITH
(   SELECT
    sum(count) AS total
    FROM pypi.pypi_downloads_per_day WHERE project = {package_name:String} AND 1=1 AND 1=1 AND date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32 AND 1=1
) AS downloads,
(SELECT count() FROM ( SELECT project FROM pypi.pypi_downloads_per_day WHERE date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32 GROUP BY project HAVING sum(count) > downloads )) as rank,
(SELECT uniqExact(project) FROM pypi.pypi_downloads_per_day WHERE date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32 ) as total_packages
SELECT rank, total_packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant