Created
May 16, 2017 20:01
-
-
Save rviscomi/ae15aa7e441a0d8fc61dc6c24f916ffa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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