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

Page Weight API #10

Open
2 tasks done
rviscomi opened this issue Oct 25, 2023 · 3 comments
Open
2 tasks done

Page Weight API #10

rviscomi opened this issue Oct 25, 2023 · 3 comments
Assignees

Comments

@rviscomi
Copy link
Member

rviscomi commented Oct 25, 2023

@rviscomi rviscomi self-assigned this Oct 25, 2023
@rviscomi
Copy link
Member Author

rviscomi commented Oct 26, 2023

Query

CREATE TEMPORARY FUNCTION GET_PAGE_WEIGHT(
  records ARRAY<STRUCT<
    client STRING,
    total INT64,
    js INT64,
    images INT64
  >>
) RETURNS ARRAY<STRUCT<
  name STRING,
  mobile STRUCT<
    median_bytes INT64
  >,
  desktop STRUCT<
    median_bytes INT64
  >
>> LANGUAGE js AS '''
const METRICS = ['total', 'js', 'images'];

// Initialize the page weight map.
const pageWeight = Object.fromEntries(METRICS.map(metricName => {
  return [metricName, {name: metricName}];
}));

// Populate each client record.
records.forEach(record => {
  METRICS.forEach(metricName => {
    pageWeight[metricName][record.client] = {median_bytes: record[metricName]};
  });
});

return Object.values(pageWeight);
''';

SELECT
  date,
  app AS technology,
  rank,
  geo,
  GET_PAGE_WEIGHT(ARRAY_AGG(STRUCT(
    client,
    median_bytes_total,
    median_bytes_js,
    median_bytes_image
  ))) AS pageWeight
FROM
  `httparchive.core_web_vitals.technologies`
WHERE
  date = '2023-07-01'
GROUP BY
  date,
  app,
  rank,
  geo

Example record

[{
  "date": "2023-07-01",
  "technology": "WordPress",
  "rank": "ALL",
  "geo": "ALL",
  "pageWeight": [{
    "name": "total",
    "mobile": {
      "median_bytes": "2231859"
    },
    "desktop": {
      "median_bytes": "2600099"
    }
  }, {
    "name": "js",
    "mobile": {
      "median_bytes": "563278"
    },
    "desktop": {
      "median_bytes": "652651"
    }
  }, {
    "name": "images",
    "mobile": {
      "median_bytes": "890780"
    },
    "desktop": {
      "median_bytes": "1048110"
    }
  }]
}]

@rviscomi rviscomi assigned maceto and unassigned rviscomi Oct 26, 2023
@maceto
Copy link
Collaborator

maceto commented Nov 13, 2023

The endpoint was added to the API see docs https://github.com/HTTPArchive/tech-report-apis/blob/main/README.md#get-page-weight

Working on the Data script

@sarahfossheim
Copy link

@maceto could you format the data the same as the other endpoints?

Current behavior

Currently it returns the data the same as in the JSON files:

[{
  "date": "2023-07-01",
  "technology": "WordPress",
  "rank": "ALL",
  "geo": "ALL",
  "client": "desktop",
  "median_bytes_total": "2600099",
  "median_bytes_js": "652651",
  "median_bytes_image": "1048110"
}]

Desired behavior

Something similar to the other endpoints, see for example: #4

Example format:

[{
  "date": "2023-07-01",
  "technology": "WordPress",
  "rank": "ALL",
  "geo": "ALL",
  "pageWeight": [{ // Or "page-weight"
    "name": "total", // Total, JS, Image
    "mobile": {
        "median_bytes": 1234
    },
    "desktop": {
        "median_bytes": 567
    },
  }]
}]

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

3 participants