Skip to content

Instantly share code, notes, and snippets.

@rviscomi
Created December 1, 2021 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rviscomi/330e242514fc73eae907f515b19903b0 to your computer and use it in GitHub Desktop.
Save rviscomi/330e242514fc73eae907f515b19903b0 to your computer and use it in GitHub Desktop.
Web Almanac 2021 content freshness
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
@rviscomi
Copy link
Author

rviscomi commented Dec 1, 2021

Screen Shot 2021-12-01 at 2 17 46 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment