Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
from collections import defaultdict
import json
""" https://bigquery.cloud.google.com/savedquery/226352634162:ae7566b78dff4e8baf64aae5fdfa33c0
SELECT
libs.name AS library,
INTEGER(FLOOR(pages.rank / 1000) * 1000) AS bucket,
COUNT(0) AS volume
FROM
(SELECT url, lib.name AS name FROM httparchive:scratchspace.2017_04_15_js_libs WHERE lib.name IN ('jQuery', 'Google Maps', 'Bootstrap', 'Modernizr', 'Polymer', 'Angular', 'AngularJS', 'React')) AS libs JOIN
(SELECT url, rank FROM httparchive:runs.latest_pages) AS pages ON pages.url = libs.url
WHERE
pages.rank IS NOT NULL
GROUP BY
library,
bucket
ORDER BY
bucket ASC
"""
f = file('js-lib-ranks.csv')
f.readline()
libs = defaultdict(list)
lines = f.readlines()
for line in lines:
lib, bucket, volume = line.strip('\n').split(',')
libs.setdefault(lib, []).append([int(bucket), int(volume)])
f.close()
f = file('js-lib-ranks.json', 'w')
f.write(json.dumps(libs))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment