Created
December 1, 2021 19:18
-
-
Save rviscomi/330e242514fc73eae907f515b19903b0 to your computer and use it in GitHub Desktop.
Web Almanac 2021 content freshness
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
CREATE TEMP FUNCTION PARSE_LAST_MODIFIED(last_modified STRING) RETURNS DATE DETERMINISTIC AS ( | |
CAST(SAFE.PARSE_DATETIME('%a, %d %h %Y %T GMT', last_modified) AS DATE) | |
); | |
CREATE TEMP FUNCTION encode(comparator DATE, data INT64) RETURNS STRING DETERMINISTIC AS ( | |
CONCAT(CAST(comparator AS STRING), CAST(data AS STRING)) | |
); | |
CREATE TEMP FUNCTION decode(value STRING) RETURNS INT64 DETERMINISTIC AS ( | |
CAST(SUBSTR(value, 11) AS INT64) | |
); | |
SELECT | |
age, | |
COUNT(0) AS n | |
FROM ( | |
SELECT | |
page, | |
DATE_DIFF( | |
DATE(TIMESTAMP_SECONDS(decode(MAX(encode(PARSE_LAST_MODIFIED(resp_last_modified), startedDateTime))))), | |
MAX(PARSE_LAST_MODIFIED(resp_last_modified)), | |
DAY) AS age | |
FROM | |
`httparchive.almanac.requests` | |
WHERE | |
date = '2021-07-01' AND | |
client = 'desktop' AND | |
NET.HOST(page) = NET.HOST(url) | |
GROUP BY | |
page) | |
GROUP BY | |
age | |
ORDER BY | |
age |
Author
rviscomi
commented
Dec 1, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment