web-platform-dx / web-features

Exploring how to present Web platform features adoptability
https://web-platform-dx.github.io/web-features/
Apache License 2.0
350 stars 68 forks source link

Create a JSON object (or objects) that maps browser versions to Baseline years #578

Open tonypconway opened 8 months ago

tonypconway commented 8 months ago

It would be very helpful for tools and analytics to providers to have an easily parsed mapping of each release version of a given browser to a Baseline year. We could do very deep nesting by year with release dates:

{
  "years": {
    "2023": {
        "chrome": {
          "120": {
            "release": 20231129
          },
          "119": {
            "release": 20231025
          },...
        },
        "safari": {
          "17.2": {
            "release": 20231211
          },
          "17.1": {
            "release": 20231025
          },...
        },
        "firefox": {
          "121.0": {
            "release": 20231219
          },
          "120.0.1": {
            "release": 20231130
          },...
        }
      }
  }
}

Or the other way round, break down by browser, then version, then Baseline year/release:

{
  "browsers": {
    "chrome": {
      "120": {
        "baseline": 2023,
        "release": 20231129
      },
      "119": {
        "baseline": 2023,
        "release": 20231025
      },...
    },...
  }
}

Do we need to differentiate between mobile and desktop? I guess we'd need to regenerate this at a minimum monthly to take new releases into account. I guess it should be too difficult to build this programatically from the MDN Compat data repo's browser files.

foolip commented 8 months ago

In code that @ddbeck and I have written, we always use BCD's browser release data, and I've found that it's already in a form that requires no or very little mangling before use.

Do you have a piece of code you need to write, and did you try using @mdn/browser-compat-data already?

atopal commented 8 months ago

Some thoughts on this:

There is no direct mapping of UAs to Baseline versions. Instead what you’d have to do is look at a Baseline version and say what is the lowest common denominator: Let’s say Baseline 2023 has features that require at least Safari 17.2, Firefox 121 and Chrome 120.

The goal is to produce a table like this: Baseline version % of traffic
2024 0.2
2023 50
2022 80

Code that wants to display a table like this would then have to check for each request whether it's between two releases of a browser.

A minimal mapping might then be: Baseline 2023: Firefox 121, Safari 17.2, etc Baseline 2022: Firefox 110, Safari 16.4

Tony's example structures above would probably make the computation more straight forward though.

Caveat: this is only for tracked browsers, so you can’t use the percentage of those visits relative to all visits for Baseline reach percentage of the overall population.

ddbeck commented 7 months ago

Over in https://github.com/web-platform-dx/web-features/pull/597, we're working on a library for working with the Baseline calculations. In there, I consume BCD's browsers data (in an admittedly complex way) to produce two sets of releases: Baseline "low" releases and Baseline "high" releases. Today, that looks something like this (simplified for display here):

Low:

Set(7) {
  '[Chrome 120]',
  '[Chrome Android 120]',
  '[Edge 120]',
  '[Firefox 121]',
  '[Firefox for Android 121]',
  '[Safari 17.2]',
  '[Safari on iOS 17.2]'
}

High:

Set(188) {
  '[Chrome 93]',
  '[Chrome 94]',
  '[Chrome 95]',
  '[Chrome 96]',
  '[Chrome 97]',
  '[Chrome 98]',
  '[Chrome 99]',
  '[Chrome 100]',
  '[Chrome 101]',
  '[Chrome 102]',
  ... 178 more items
}

I don't think it would be too difficult to allow selecting a date for the set of releases (e.g., getBaselineHighReleases("2023-12-31"), to find out which releases were represented by the Baseline definition on a given date.

tonypconway commented 4 months ago

Coming back to this, as I was discussing it with @just-jeb and @alonkochba . They said it would be really helpful if they could easily get an ingestible summary of BL versions year by year to use in their internally built analytics stack.

Jeb and Alon, is there a format that would make most sense for you? The RUM Archive Baseline page I showed you is open source, and they have some code for parsing a list of browsers/release dates and turning out the table that you see in the page, but I don't know if that's useful or not for your purposes.

foolip commented 4 months ago

Here's some sample code that might be useful:

import bcd from '@mdn/browser-compat-data' with { type: 'json' };

// https://github.com/web-platform-dx/web-features/blob/main/docs/baseline.md#core-browser-set
const browsers = [
    "chrome",
    "chrome_android",
    "edge",
    "firefox",
    "firefox_android",
    "safari",
    "safari_ios",
];

// Map from year (as a string) to a filtered version of the bcd.browsers data.
const releasesByYear = {};

for (let year = 2016; /* no break condition */; year++) {
    let releaseCount = 0;
    const releases = Object.fromEntries(browsers.map((browser) => {
        const filtered = Object.fromEntries(
            Object.entries(bcd.browsers[browser].releases).filter(
                ([version, data]) => {

                    if (!data.release_date.startsWith(`${year}-`)) {
                        return false;
                    }
                    if (!['current', 'esr', 'retired'].includes(data.status)) {
                        return false;
                    }
                    releaseCount++;
                    return true;
                }
            ).map(
                ([version, data]) => [version, data.release_date]
            )
        );
        return [browser, filtered];
    }));
    if (releaseCount == 0) {
        break;
    }
    releasesByYear[String(year)] = releases;
}

console.log(JSON.stringify({ year: releasesByYear}, null, '  '));

The output is in https://gist.github.com/foolip/212740b5d53de0cdd86bbba6859127aa.

My recommendation would be to take a dependency on @mdn/browser-compat-data and adapt this code to do what you want. I suspect that sometimes you actually want all releases after a specific date, more in the style of a browser support matrix.

foolip commented 4 months ago

https://github.com/web-platform-dx/web-features/issues/1047 might also help here. If we publish something simplified, code like the above would be slightly more straightforward.